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 |
#include "Framework.h" #include <d3dx9.h> #include <d3d9.h> #include <ctime>struct SVertex { D3DXVECTOR3 vPosition; // Position des Vertex D3DXVECTOR3 vTexture; // 3D-Texturkoordinaten static const DWORD dwFVF; // Vertexformat };const DWORD SVertex::dwFVF = D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0); PDIRECT3DCUBETEXTURE9 g_pEnvMap = NULL; // Die Umgebungstextur SVertex g_aSkyBoxVertex[8]; // Vertizes der Sky-Box unsigned short g_ausSkyBoxIndex[36]; // Indizes der Sky-Box D3DXVECTOR3 vc1(0.0f, -1.0f, -1.0f); D3DXVECTOR3 vc2(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vc3(0.0f, 1.0f, 0.0f); CGame::CGame() { } HRESULT CGame::Load() { HRESULT hResult;if(FAILED(id3d.GetDevice()->SetFVF(SVertex::dwFVF))) {MessageBox(NULL,"Fehler beim setzen des Vertex Formats!","Fehler",MB_OK); } if(FAILED(hResult = D3DXCreateCubeTextureFromFileEx(id3d.GetDevice(), // Device "Data/SkyBox/EnvMap.dds", // Dateiname D3DX_DEFAULT, // Gre 1, // MIP-Maps 0, // Verwendungszweck D3DFMT_UNKNOWN, // Format D3DPOOL_MANAGED, // Speicherklasse D3DX_FILTER_NONE, // Filter D3DX_DEFAULT, // MIP-Map-Filter 0, // Color-Key NULL, // Unwichtig NULL, // Unwichtig &g_pEnvMap))) // Die Textur { // Fehler!MessageBox(NULL,"Fehler beim Laden der CubeTextur","Fehler",MB_OK); } // Die Vertizes der Sky-Box erstellen g_aSkyBoxVertex[0].vPosition = D3DXVECTOR3(-1.0f, 1.0f, 1.0f); g_aSkyBoxVertex[1].vPosition = D3DXVECTOR3( 1.0f, 1.0f, 1.0f); g_aSkyBoxVertex[2].vPosition = D3DXVECTOR3( 1.0f, 1.0f, -1.0f); g_aSkyBoxVertex[3].vPosition = D3DXVECTOR3(-1.0f, 1.0f, -1.0f); g_aSkyBoxVertex[4].vPosition = D3DXVECTOR3(-1.0f, -1.0f, 1.0f); g_aSkyBoxVertex[5].vPosition = D3DXVECTOR3( 1.0f, -1.0f, 1.0f); g_aSkyBoxVertex[6].vPosition = D3DXVECTOR3( 1.0f, -1.0f, -1.0f); g_aSkyBoxVertex[7].vPosition = D3DXVECTOR3(-1.0f, -1.0f, -1.0f); // Die Texturkoordinaten brauchen wir nicht per Hand einzutragen: sie entsprechen // ganz einfach den Positionsangaben.for(int iVertex = 0; iVertex < 8; iVertex++) { g_aSkyBoxVertex[iVertex].vTexture = g_aSkyBoxVertex[iVertex].vPosition; } // Nun tragen wir die Indizes ein. unsigned short ausIndex[36] = {7, 3, 0, 4, 7, 0, // Vorderseite 5, 1, 2, 6, 5, 2, // Hinterseite 4, 0, 1, 5, 4, 1, // Linke Seite 6, 2, 3, 7, 6, 3, // Rechte Seite 2, 1, 0, 3, 2, 0, // Oberseite 4, 5, 6, 7, 4, 6}; // Unterseite // In das globale Array kopierenmemcpy(g_ausSkyBoxIndex, ausIndex, 36 * sizeof(unsigned short));return 0; } HRESULT CGame::Unload() {return 0; }HRESULT CGame::Render(float stime) { D3DXMATRIX ViewMatrix; D3DXMATRIX ProjectionMatrix; D3DXMATRIX Translation; D3DXMATRIX World; D3DXMatrixLookAtLH(&ViewMatrix, &vc1, &vc2, &vc3); D3DXMatrixPerspectiveFovLH(&ProjectionMatrix, D3DXToRadian(60.f),1.f,1.f,100.f); id3d.GetDevice()->SetTransform(D3DTS_VIEW, &ViewMatrix); id3d.GetDevice()->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix); id3d.BeginRendering(0xA8B600FF); id3d.GetDevice()->SetTexture(0, g_pEnvMap); id3d.GetDevice()->SetTexture(1, NULL); D3DXMatrixTranslation(&Translation,0.0f,0.0f,0.0f); World = Translation; id3d.GetDevice()->SetTransform(D3DTS_WORLD,&World); id3d.GetDevice()->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, // Dreiecksliste 0, // Beginn bei 0 8, // Grter Index 12, // Anz. Dreiecke g_ausSkyBoxIndex, // Indizes D3DFMT_INDEX16, // 16 Bits g_aSkyBoxVertex, // Vertizessizeof(SVertex)); // Die Umgebungstextur ist in der ersten Texturschicht. Es werden die ntigen // Einstellungen fr die automatische Texturkoordinatengenerierung vorgenommen. id3d.GetDevice()->SetTexture(0, g_pEnvMap); id3d.GetDevice()->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR); id3d.GetDevice()->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3); id3d.EndRendering();return 0; }HRESULT CGame::Move(float stime) {if(FAILED(di.GetKeyboard()->GetDeviceState(sizeof(buffer),(LPVOID)&buffer))) di.GetKeyboard()->Acquire();return 0; } |
idontknow
unregistriert
Administrator
Werbeanzeige