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
Anonymous
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
#include <Windows.h> #include <TriBase.h> #include "InitWindow.h" #include "Direct3DEnum.h" #include "InitDirect3D.h" #include "Resource.h" // Strukturen oder Globale Variable PDIRECT3DTEXTURE9 g_pTexture; SVertex g_aTriangle; float g_fTime = 0.0f; // Struktur für einen Vertex: Position, Farbe und Texturkoordinaten struct SVertex { tbVector3 vPosition; DWORD dwColor; tbVector2 vTexture; static const DWORD dwFVF; }; const g_aTriangle SVertex::dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; // Struktur für ein Dreieck struct STriangle { tbVector3 vPosition; tbVector3 vVelocity; tbVector3 vRotation; tbVector3 vRotVelocity; float fSize; SVertex aVertex[3]; }; SDirect3DParameters g_Direct3DParameters; // Render-Funktion tbResult Render(float fNumSecsPassed) { if((int)(g_fTime / 3.0f) % 3 == 0) { // Bilineare Filter mit linearem MIP-Mapping g_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); SetWindowText(g_hWindow, "Beispielprogramm Nr.4: Texturen (MIN: Linear, MAG: Linear, MIP: Linear)"); } else if((int)(g_fTime / 3.0f) % 3 == 2) { // Keine Filter ("Playstation-Effekt"), auch kein MIP-Mapping g_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); SetWindowText(g_hWindow, "Beispielprogramm Nr.4: Texturen (MIN: Point, MAG: Point, MIP: None)"); } else { // Maximaler anisotropischer Filter ohne MIP-Mapping g_pD3DDevice->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, g_Direct3DParameters.DeviceCaps.MaxAnisotropy); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); SetWindowText(g_hWindow, "Beispielprogramm Nr. 4: Texturen: (MIN: Anisotropic, MAG: Linear, MIP: None)"); } return TB_OK; } // Move-Funktion float fDistance; tbResult Move(float fNumSecsPassed) { // Zeitzähler erhöhen g_fTime += fNumSecsPassed; // Wenn der Benutzer die Leertaste drückt, wird das // Programm angehalten. if(GetAsyncKeyState(VK_SPACE)) fNumSecsPassed = 0.0f; // Jedes Dreieck bewegen float fDistance; tbVector3 tbVector3Lenght; for(int iTriangle = 0; iTriangle < g_iNumTriangles; iTriangle++) { // Position und Rotation aktualisieren g_aTriangle[iTriangle].vPosition += g_aTriangle[iTriangle].vVelocity * fNumSecsPassed; g_aTriangle[iTriangle].vRotation += g_aTriangle[iTriangle].vRotVelocity * fNumSecsPassed; // Distance des Dreicks zum Beobachter (zum Nullpunkt) berechnen fDistance = tbVector3Lenght(g_aTriangle[iTriangle].vPosition); // Wenn die Distanz größer als 100 ist, soll das Dreieck umkehren if(fDistance > 100.0f) g_aTriangle[iTriangle].vVelocity *= -1.0f; } return TB_OK; } // Herunterfahren der Szene // Herunterfahren der Anwendung tbResult ExitApplication() { // Szene herunterfahren // Direct3D und Fenster herunterfahren ExitDirect3D(); ExitWindow(); // Engine herunterfahren tbExit(); return TB_OK; } // Initialisieren der Szene tbResult InitScene() { float fSpeed; // Initialisierung der Dreiecke for(int iTri = 0; iTri < g_iNumTriangles; iTri++) { // Alle Dreiecke starten am Punkt (0, 0, 50.0f). g_aTriangle[iTri].vPosition = tbVector3(0.0f, 0.0f, 50.0f); // Die Bewegung ist zufällig float fSpeed = tbFloatRandom(0.1f, 5.0f); g_aTriangle[iTri].vVelocity = tbVector3Random() * fSpeed; // Rotation zurückstellen g_aTriangle[iTri].vRotation = tbVector3(0.0f, 0.0f, 0.0f); // Rotationsgeschwindigkeit ist zufällig auf allen drei Achsen g_aTriangle[iTri]vRotVelocity.x = tbFloatRandom(-1.0f, 1.0f); g_aTriangle[iTri]vRotVelocity.y = tbFloatRandom(-1.0f, 1.0f); g_aTriangle[iTri]vRotVelocity.z = tbFloatRandom(-1.0f, 1.0f); // Grösse zufällig zwischen 1 und 5 festlegen g_aTriangle[iTri].fSize = tbFloatRandom(1.0f, 5.0f); // Nun die einzelnen Vertizes generieren for(int iVertex = 0; iVertex < 3; iVertex++) { // Position g_aTriangle[iTri].aVertex[iVertex].vPosition = tbVector3Random(); // Farbe tbColor VertexColor(tbFloatRandom(0.0f, 1.0f), tbFloatRandom(0.0f, 1.0f), tbFloatRandom(0.0f, 1.0f)); g_aTriangle[iTri].aVertex[iVertex].dwColor = (DWORD)(VertexColor); // Texturkoordinaten zufällig zwischen -1 únd 2 erzeugen g_aTriangle[iTri].aVertex[iVertex].vTexture.u = tbFloatRandom(-1.0f, 2.0f); g_aTriangle[iTri].aVertex[iVertex].vTexture.v = tbFloatRandom(-1.0f, 2.0f); } } // Die Textur Laden HRESULT hResult; if(FAILED(hResult = D3DXCreateTextureFromFileEx(g_pD3DDevice, "Texture.bmp", D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 0, NULL, NULL, &g_pTexture))) { // Fehler TB_ERROR_DIRECTX("D3DXCreateTextureFromFileEx", hResult, TB_ERROR); } // Textur einsetzen g_pD3DDevice->SetTexture(0, g_pTexture); return TB_OK; } // Initialisierungsfunktion tbResult InitApplication() { tbResult Result; // TriBase-Engine initialisieren tbInit(); // Direct3D-Optionen abfragen (vom Benutzer gewählt) Result = GetDirect3DParameters(&g_Direct3DParameters); if(Result == TB_ERROR) { // Es trat ein Fehler auf! MessageBox(NULL, "Fehler beim Abzählen!", "Fehler", MB_OK | MB_ICONEXCLAMATION); return TB_ERROR; } else if(Result == TB_CANCELED) { // Der Dialog wurde abgebrochen! return TB_CANCELED; } // Fenster initialisieren. Die Größe hängt vom gewählten // Videomodus ab, der in der Parameterstruktur gespeichert ist. if(InitWindow(g_Direct3DParameters.VideoMode.Width, g_Direct3DParameters.VideoMode.Height, "Beispielprogramm Nr. 3: Das erste Dreieck", LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)))) { // Fehler beim Erstellen des Fensters! MessageBox(NULL, "Fehler beim Erstellen des Fensters!", "Fehler", MB_OK | MB_ICONEXCLAMATION); return TB_ERROR; } // Direct3D mit den abgefragten Einstellungen initialisieren if(InitDirect3D(&g_Direct3DParameters, g_hWindow)) { // Fehler! MessageBox(g_hWindow, "Fehler beim Initialisieren von Direct3D!", "Fehler", MB_OK | MB_ICONEXCLAMATION); ExitApplication(); return TB_ERROR; } // Szene initialisieren if(InitScene()) { // Fehler! MessageBox(g_hWindow, "Fehler beim Initialisieren der Szene!", "Fehler", MB_OK | MB_ICONINFORMATION); ExitApplication(); return TB_ERROR; } // Alles OK! return TB_OK; } // Windows-Hauptfunktion int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* pcCmdLine, int iShowCmd) { tbResult Result; // Initialisierung Result = InitApplication(); if(Result == TB_CANCELED) return 0; else if(Result) { MessageBox(NULL, "Fehler beim Initialisieren der Anwendung!", "Fehler", MB_OK | MB_ICONEXCLAMATION); return 1; } // Nachrichtenschleife tbDoMessageLoop(Render, Move); // Herunterfahren ExitApplication(); return 0; } |
C-/C++-Quelltext |
|
1 |
SVertex g_aTriangle; |
C-/C++-Quelltext |
|
1 |
SVertex g_aTriangle[/*anzahl*/];
|
C-/C++-Quelltext |
|
1 |
const g_aTriangle SVertex::dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; |
C-/C++-Quelltext |
|
1 |
const DWORD SVertex::dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; |
Anonymous
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
//------------- // Includes //------------- // Strukturen struct SStruct { ...; ...; }; //-------------- // Globale Variablen |
Anonymous
unregistriert
Werbeanzeige