Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
#include <TriBase.h> #include "Resource.h" // ****************************************************************** // Struktur für einen Vertex der Wasseroberfläche struct SVertex { tbVector3 vPosition; // Position tbVector3 vNormal; // Normalenvektor tbVector2 vTexture; // 2D-Texturkoordinaten static const DWORD dwFVF; // Vertexformat }; const DWORD SVertex::dwFVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1; // ****************************************************************** // Globale Variablen tbConfig g_Config; // Konfigurationsstruktur tbVertexBuffer* g_pVB = NULL; // Wasser-Vertex-Buffer tbIndexBuffer* g_pIB = NULL; // Wasser-Index-Buffer float g_fTime = 0.0f; // Globaler Zeitzähler // ****************************************************************** // Die Init-Funktion tbResult AppInit(void) { SVertex Vertex; tbVector3 vPosition; WORD wIndex; g_pVB = new tbVertexBuffer; if(g_pVB->Init(8 * sizeof(SVertex), sizeof(SVertex), SVertex::dwFVF)) { // Fehler! return TB_ERROR; } Vertex.vPosition = tbVector3(-1.0f, 1.0f, -1.0f); Vertex.vNormal = tbVector3(-0.5f, 0.5f, -0.5f); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3(-1.0f, 1.0f, 1.0f); Vertex.vNormal = tbVector3(-0.5f, 0.5f, 0.5f); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3( 1.0f, 1.0f, 1.0f); Vertex.vNormal = tbVector3( 0.5f, 0.5f, 0.5f); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3( 1.0f, 1.0f, -1.0f); Vertex.vNormal = tbVector3( 0.5f, 0.5f, -0.5f); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3(-1.0f, -1.0f, -1.0f); Vertex.vNormal = tbVector3(-0.5f, 0.5f, -0.5f); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3(-1.0f, -1.0f, 1.0f); Vertex.vNormal = tbVector3(-0.5f, -0.5f, 0.5f); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3( 1.0f, -1.0f, 1.0f); Vertex.vNormal = tbVector3( 0.5f, -0.5f, 0.5f); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3( 1.0f, -1.0f, -1.0f); Vertex.vNormal = tbVector3( 0.5f, -0.5f, -0.5f); g_pVB->AddVertex(&Vertex); g_pVB->Update(); g_pIB = new tbIndexBuffer; if(g_pIB->Init(36 * sizeof(WORD), sizeof(WORD), D3DFMT_INDEX16)) { // Fehler! return TB_ERROR; } int aiIndex[36] = {0, 3, 7, 0, 7, 4, // Vorderseite 2, 1, 5, 2, 5, 6, // Hinterseite 1, 0, 4, 1, 4, 5, // Linke Seite 3, 2, 6, 3, 6, 7, // Rechte Seite 0, 1, 2, 0, 2, 3, // Oberseite 6, 5, 4, 6, 4, 7}; // Unterseite g_pIB->AddIndices(36, &aiIndex); if(g_pIB->Update()) return TB_ERROR; return TB_OK; } // ****************************************************************** // Die Move-Funktion tbResult MoveProc(float fNumSecsPassed) { g_fTime += fNumSecsPassed; return TB_OK; } // ****************************************************************** // Die Render-Funktion tbResult RenderProc(float fNumSecsPassed) { tbMatrix mCamera; tbMatrix mProjection; tbMatrix mRotation; tbMatrix mWorld; D3DLIGHT9 Light; D3DMATERIAL9 Material; tbDirect3D &D3D = tbDirect3D::Instance(); D3D->BeginScene(); D3D.SetRS(D3DRS_DITHERENABLE, TRUE); D3D.SetRS(D3DRS_LIGHTING, TRUE); D3D.SetRS(D3DRS_SPECULARENABLE, TRUE); D3D.SetRS(D3DRS_ZENABLE, TRUE); D3D.SetRS(D3DRS_COLORVERTEX, FALSE); D3D.SetRS(D3DRS_AMBIENT, tbColor(0.25f, 0.25f, 0.25f)); mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f), D3D.GetAspect(), 0.1f, 100.0f); D3D.SetTransform(D3DTS_PROJECTION, mProjection); mCamera = tbMatrixCamera(tbVector3(0.0f, 0.0f, -5.0f), tbVector3(0.0f, 0.0f, 1.0f)); D3D.SetTransform(D3DTS_VIEW, mCamera); Light.Type = D3DLIGHT_POINT; Light.Diffuse = tbColor(0.75f, 0.75f, 0.75f); Light.Ambient = tbColor(0.25f, 0.25f, 0.25f); Light.Position = tbVector3(0.0f, 0.0f, -10.0f); Light.Direction = tbVector3(0.0f, 0.0f, 1.0f); Light.Range = 1000.0f; Light.Attenuation0 = 0.0f; Light.Attenuation1 = 0.025f; Light.Attenuation2 = 0.0f; Light.Specular = tbColor(0.75f, 0.75f, 0.75f); Material.Diffuse = tbColor(0.75f, 0.75f, 0.75f); Material.Ambient = tbColor(0.25f, 0.25f, 0.25f); Material.Emissive = tbColor(0.0f, 0.0f, 0.0f); Material.Power = 50.0f; Material.Specular = tbColor(0.75f, 0.75f, 0.75f); D3D->SetLight(0, &Light); D3D->LightEnable(0, TRUE); D3D->SetMaterial(&Material); mRotation = tbMatrixRotationY(TB_DEG_TO_RAD(g_fTime * 90.0f)); mWorld = mRotation; D3D.SetTransform(D3DTS_WORLD, mWorld); D3D->SetStreamSource(0, g_pVB->GetVB(), NULL, sizeof(SVertex)); D3D->SetIndices(g_pIB->GetIB()); D3D->SetFVF(SVertex::dwFVF); // Zeichnen! D3D->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, // Dreiecksliste 0, // Basisvertexindex 0, // Der kleinste Index 8, // Diff. zw. größtem u. kleinstem Index 0, // Von Anfang an zeichnen 12); // 12 Dreiecke pro Würfel D3D->EndScene(); return TB_OK; } // ****************************************************************** // Aufräumen tbResult CleanUp() { // Alles löschen tbDirect3D::Instance().Exit(); tbTextureManager::Instance().Exit(); // Die TriBase-Engine herunterfahren tbExit(); return TB_OK; } // ****************************************************************** // Windows-Hauptfunktion int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* pcCommandLine, int iShowCommand) { // TriBase-Engine initialisieren tbInit(); // Konfiguration abfragen tbResult r; if(r = tbDoConfigDialog(&g_Config)) { if(r == TB_CANCELED) return 0; else { // Fehler! MessageBox(NULL, "Fehler im Konfigurationsdialog!", "Fehler", MB_OK | MB_ICONEXCLAMATION); return 1; } } // Direct3D initialisieren if(tbDirect3D::Instance().Init(&g_Config, "Rahmen-Anwendung", NULL, LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)))) { // Fehler! MessageBox(NULL, "Fehler bei der Direct3D-Initialisierung!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } // Den Texturmanager initialisieren if(tbTextureManager::Instance().Init()) { MessageBox(tbDirect3D::Instance().GetWindow(), "Fehler beim Initialisieren des Texturmanagers!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } if(AppInit()) { MessageBox(tbDirect3D::Instance().GetWindow(), "Fehler in AppInit()!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } if(tbDoMessageLoop(MoveProc, RenderProc)) { MessageBox(tbDirect3D::Instance().GetWindow(), "Fehler beim Zeichnen!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } // Aufräumen CleanUp(); return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
g_pVB = new tbVertexBuffer; if(g_pVB->Init(8 * sizeof(SVertex), sizeof(SVertex), SVertex::dwFVF)) { // Fehler! return TB_ERROR; } Vertex.vPosition = tbVector3(-1.0f, 1.0f, -1.0f); Vertex.vNormal = tbVector3Normalize(tbVector3(-0.5f, 0.5f, -0.5f)); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3(-1.0f, 1.0f, 1.0f); Vertex.vNormal = tbVector3Normalize(tbVector3(-0.5f, 0.5f, 0.5f)); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3( 1.0f, 1.0f, 1.0f); Vertex.vNormal = tbVector3Normalize(tbVector3( 0.5f, 0.5f, 0.5f)); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3( 1.0f, 1.0f, -1.0f); Vertex.vNormal = tbVector3Normalize(tbVector3( 0.5f, 0.5f, -0.5f)); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3(-1.0f, -1.0f, -1.0f); Vertex.vNormal = tbVector3Normalize(tbVector3(-0.5f, 0.5f, -0.5f)); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3(-1.0f, -1.0f, 1.0f); Vertex.vNormal = tbVector3Normalize(tbVector3(-0.5f, -0.5f, 0.5f)); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3( 1.0f, -1.0f, 1.0f); Vertex.vNormal = tbVector3Normalize(tbVector3( 0.5f, -0.5f, 0.5f)); g_pVB->AddVertex(&Vertex); Vertex.vPosition = tbVector3( 1.0f, -1.0f, -1.0f); Vertex.vNormal = tbVector3Normalize(tbVector3( 0.5f, -0.5f, -0.5f)); g_pVB->AddVertex(&Vertex); g_pVB->Update(); |
Zitat von »"CroBenji"«
normaler weise braucht jede ecke ja drei vektoren (für harte kanten). aber ich arbeite ja mit indexbuffer somit habe ich alle ecken nur einmal. deshalb der mittelvektor....
Sheddex
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
#include <TriBase.h> #include "Resource.h" // ****************************************************************** // Struktur für einen Vertex der Wasseroberfläche struct SVertex { tbVector3 vPosition; // Position tbVector3 vNormal; // Normalenvektor tbVector2 vTexture; // 2D-Texturkoordinaten static const DWORD dwFVF; // Vertexformat }; const DWORD SVertex::dwFVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1; // ****************************************************************** // Globale Variablen tbConfig g_Config; // Konfigurationsstruktur tbVertexBuffer* g_pVB = NULL; // Wasser-Vertex-Buffer tbIndexBuffer* g_pIB = NULL; // Wasser-Index-Buffer float g_fTime = 0.0f; // Globaler Zeitzähler // ****************************************************************** // Die Init-Funktion tbResult AppInit(void) { SVertex Vertex[7]; tbVector3 vPosition; WORD wIndex; g_pVB = new tbVertexBuffer; if(g_pVB->Init(8 * sizeof(SVertex), sizeof(SVertex), SVertex::dwFVF)) { // Fehler! return TB_ERROR; } Vertex[0].vPosition = tbVector3(-1.0f, 1.0f, -1.0f); Vertex[1].vPosition = tbVector3(-1.0f, 1.0f, 1.0f); Vertex[2].vPosition = tbVector3( 1.0f, 1.0f, 1.0f); Vertex[3].vPosition = tbVector3( 1.0f, 1.0f, -1.0f); Vertex[4].vPosition = tbVector3(-1.0f, -1.0f, -1.0f); Vertex[5].vPosition = tbVector3(-1.0f, -1.0f, 1.0f); Vertex[6].vPosition = tbVector3( 1.0f, -1.0f, 1.0f); Vertex[7].vPosition = tbVector3( 1.0f, -1.0f, -1.0f); Vertex[0].vNormal = tbVector3Normalize(tbVector3(-0.5f, 0.5f, -0.5f)); Vertex[1].vNormal = tbVector3Normalize(tbVector3(-0.5f, 0.5f, 0.5f)); Vertex[2].vNormal = tbVector3Normalize(tbVector3( 0.5f, 0.5f, 0.5f)); Vertex[3].vNormal = tbVector3Normalize(tbVector3( 0.5f, 0.5f, -0.5f)); Vertex[4].vNormal = tbVector3Normalize(tbVector3(-0.5f, 0.5f, -0.5f)); Vertex[5].vNormal = tbVector3Normalize(tbVector3(-0.5f, -0.5f, 0.5f)); Vertex[6].vNormal = tbVector3Normalize(tbVector3( 0.5f, -0.5f, 0.5f)); Vertex[7].vNormal = tbVector3Normalize(tbVector3( 0.5f, -0.5f, -0.5f)); g_pVB->AddVertices(8, &Vertex); g_pVB->Update(); g_pIB = new tbIndexBuffer; if(g_pIB->Init(36 * sizeof(WORD), sizeof(WORD), D3DFMT_INDEX16)) { // Fehler! return TB_ERROR; } int aiIndex[36] = {0, 3, 7, 0, 7, 4, // Vorderseite 2, 1, 5, 2, 5, 6, // Hinterseite 1, 0, 4, 1, 4, 5, // Linke Seite 3, 2, 6, 3, 6, 7, // Rechte Seite 0, 1, 2, 0, 2, 3, // Oberseite 6, 5, 4, 6, 4, 7}; // Unterseite g_pIB->AddIndices(36, &aiIndex); if(g_pIB->Update()) return TB_ERROR; return TB_OK; } // ****************************************************************** // Die Move-Funktion tbResult MoveProc(float fNumSecsPassed) { g_fTime += fNumSecsPassed; return TB_OK; } // ****************************************************************** // Die Render-Funktion tbResult RenderProc(float fNumSecsPassed) { tbMatrix mCamera; tbMatrix mProjection; tbMatrix mRotation; tbMatrix mWorld; D3DLIGHT9 Light; D3DMATERIAL9 Material; tbDirect3D &D3D = tbDirect3D::Instance(); D3D->BeginScene(); D3D.SetRS(D3DRS_DITHERENABLE, TRUE); D3D.SetRS(D3DRS_LIGHTING, TRUE); D3D.SetRS(D3DRS_SPECULARENABLE, TRUE); D3D.SetRS(D3DRS_ZENABLE, TRUE); D3D.SetRS(D3DRS_COLORVERTEX, FALSE); D3D.SetRS(D3DRS_CULLMODE, D3DCULL_NONE); D3D.SetRS(D3DRS_AMBIENT, tbColor(0.25f, 0.25f, 0.25f)); D3D->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 0); mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f), D3D.GetAspect(), 0.1f, 100.0f); D3D.SetTransform(D3DTS_PROJECTION, mProjection); mCamera = tbMatrixCamera(tbVector3(0.0f, 0.0f, -5.0f), tbVector3(0.0f, 0.0f, 1.0f)); D3D.SetTransform(D3DTS_VIEW, mCamera); Light.Type = D3DLIGHT_POINT; Light.Diffuse = tbColor(0.75f, 0.75f, 0.75f); Light.Ambient = tbColor(0.25f, 0.25f, 0.25f); Light.Position = tbVector3(0.0f, 0.0f, -10.0f); Light.Direction = tbVector3(0.0f, 0.0f, 1.0f); Light.Range = 1000.0f; Light.Attenuation0 = 0.0f; Light.Attenuation1 = 0.025f; Light.Attenuation2 = 0.0f; Light.Specular = tbColor(0.75f, 0.75f, 0.75f); Material.Diffuse = tbColor(0.75f, 0.75f, 0.75f); Material.Ambient = tbColor(0.25f, 0.25f, 0.25f); Material.Emissive = tbColor(0.0f, 0.0f, 0.0f); Material.Power = 50.0f; Material.Specular = tbColor(0.75f, 0.75f, 0.75f); D3D->SetLight(0, &Light); D3D->LightEnable(0, TRUE); D3D->SetMaterial(&Material); mRotation = tbMatrixRotationY(TB_DEG_TO_RAD(g_fTime * 90.0f)); mWorld = mRotation; D3D.SetTransform(D3DTS_WORLD, mWorld); D3D->SetStreamSource(0, g_pVB->GetVB(), NULL, sizeof(SVertex)); D3D->SetIndices(g_pIB->GetIB()); D3D->SetFVF(SVertex::dwFVF); // Zeichnen! D3D->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, // Dreiecksliste 0, // Basisvertexindex 0, // Der kleinste Index 8, // Diff. zw. größtem u. kleinstem Index 0, // Von Anfang an zeichnen 12); // 12 Dreiecke pro Würfel D3D->EndScene(); return TB_OK; } // ****************************************************************** // Aufräumen tbResult CleanUp() { // Alles löschen tbDirect3D::Instance().Exit(); tbTextureManager::Instance().Exit(); // Die TriBase-Engine herunterfahren tbExit(); return TB_OK; } // ****************************************************************** // Windows-Hauptfunktion int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* pcCommandLine, int iShowCommand) { // TriBase-Engine initialisieren tbInit(); // Konfiguration abfragen tbResult r; if(r = tbDoConfigDialog(&g_Config)) { if(r == TB_CANCELED) return 0; else { // Fehler! MessageBox(NULL, "Fehler im Konfigurationsdialog!", "Fehler", MB_OK | MB_ICONEXCLAMATION); return 1; } } // Direct3D initialisieren if(tbDirect3D::Instance().Init(&g_Config, "Rahmen-Anwendung", NULL, LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)))) { // Fehler! MessageBox(NULL, "Fehler bei der Direct3D-Initialisierung!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } // Den Texturmanager initialisieren if(tbTextureManager::Instance().Init()) { MessageBox(tbDirect3D::Instance().GetWindow(), "Fehler beim Initialisieren des Texturmanagers!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } if(AppInit()) { MessageBox(tbDirect3D::Instance().GetWindow(), "Fehler in AppInit()!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } if(tbDoMessageLoop(MoveProc, RenderProc)) { MessageBox(tbDirect3D::Instance().GetWindow(), "Fehler beim Zeichnen!", "Fehler", MB_OK | MB_ICONEXCLAMATION); CleanUp(); return 1; } // Aufräumen CleanUp(); return 0; } |
Werbeanzeige