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 |
#include <d3d9.h> #include <d3dx9.h> #include "InitWindow.h" #include "InitD3D.h" #include <iostream> #include <fstream> #include "Vektor3D.h" #include "Color.h" using namespace std; CInitD3D id3d; CWindow cw; float stime = 0.0f; float TranslationX = 0.0f; float TranslationY = 0.0f; float TranslationZ = 0.0f; float APositionX = 0.0f; float APositionY = -14.0f; float APositionZ = -25.0f; LPD3DXMESH g_pSphereModel = NULL; PDIRECT3DTEXTURE9 g_pSphereTexture = NULL; D3DXVECTOR3 g_vCameraPosition = D3DXVECTOR3(0.0f, -14.0f, -25.0f); // Die Kameraposition float g_fCameraAngle = 0.0f; // Drehwinkel der Kamera #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1) HRESULT Render() { D3DXMATRIX ViewMatrix; D3DXMATRIX ProjectionMatrix; D3DXMATRIX TranslationMatrix; D3DXMATRIX WorldMatrix; D3DXMatrixLookAtLH(&ViewMatrix, &g_vCameraPosition, &D3DXVECTOR3(sinf(g_fCameraAngle), 0.0f, cosf(g_fCameraAngle)), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH(&ProjectionMatrix, D3DXToRadian(60.f),1.f,1.f,100.f); D3DXMatrixTranslation(&TranslationMatrix, TranslationX, TranslationY, TranslationZ); id3d.pd3dDevice->SetTransform(D3DTS_VIEW, &ViewMatrix); id3d.pd3dDevice->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix); WorldMatrix = TranslationMatrix; id3d.pd3dDevice->SetTransform(D3DTS_WORLD, &WorldMatrix); HRESULT hresult; if(FAILED(hresult = id3d.pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 63), 1.0f, 0))) { MessageBox(NULL,"Fehler beim Leeren des Backbuffers","Fehler",MB_OK); return 1; } id3d.pd3dDevice->BeginScene(); id3d.pd3dDevice->SetTexture(0, g_pSphereTexture); g_pSphereModel->DrawSubset(0); id3d.pd3dDevice->EndScene(); id3d.pd3dDevice->Present(NULL,NULL,NULL,NULL); return 0; } HRESULT InitScene() { HRESULT hresult; hresult = id3d.pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX); if(FAILED(hresult)) { MessageBox(NULL,"Fehler beim Setzen des Vertexformat","Fehler",MB_OK); return 1; } id3d.pd3dDevice->SetRenderState(D3DRS_LIGHTING,FALSE); id3d.pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE); id3d.pd3dDevice->SetRenderState(D3DRS_DITHERENABLE,TRUE); D3DXMATRIX ProjMatrix; D3DXMatrixPerspectiveFovLH(&ProjMatrix, D3DX_PI/4, static_cast<float>(cw.Breite) / static_cast<float>(cw.Höhe), 1.0f, 100.0f ); id3d.pd3dDevice->SetTransform(D3DTS_PROJECTION, &ProjMatrix); HRESULT hResult; if(FAILED(hResult = D3DXCreateTextureFromFileEx(id3d.pd3dDevice, // Device "Tex.jpg", // Dateiname D3DX_DEFAULT, // Breite D3DX_DEFAULT, // Höhe D3DX_DEFAULT, // 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_pSphereTexture))) // Die Textur { // Fehler! MessageBox(NULL,"D3DXCreateTextureFromFileEx", "", MB_OK); } D3DXLoadMeshFromX("Men.x", D3DXMESH_MANAGED, id3d.pd3dDevice, NULL, NULL, NULL, NULL, &g_pSphereModel); return 0; } HRESULT Move() { D3DXVECTOR3 d3dm = D3DXVECTOR3(TranslationX,TranslationY,TranslationZ); if(GetAsyncKeyState(VK_RIGHT)) TranslationX += stime; if(GetAsyncKeyState(VK_LEFT)) TranslationX -= stime; if(GetAsyncKeyState(VK_UP)) TranslationY += stime; if(GetAsyncKeyState(VK_DOWN)) TranslationY -= stime; g_vCameraPosition.x = (APositionX + TranslationX); g_vCameraPosition.y = (APositionY + TranslationY); g_vCameraPosition.z = (APositionZ + TranslationZ); return 0; } |
C-/C++-Quelltext |
|
1 2 3 |
id3d.pd3dDevice->SetTransform(D3DTS_WORLD, &WorldMatrix); // 1 id3d.pd3dDevice->SetTransform(D3DTS_VIEW, &ViewMatrix); // 2 |
C-/C++-Quelltext |
|
1 |
D3DXVECTOR3 d3dm = D3DXVECTOR3(TranslationX,TranslationY,TranslationZ);
|
C-/C++-Quelltext |
|
1 2 3 |
id3d.pd3dDevice->SetTransform(D3DTS_WORLD, &WorldMatrix); id3d.pd3dDevice->SetTransform(D3DTS_VIEW, &ViewMatrix); id3d.pd3dDevice->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix); |
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 |
#include <d3d9.h> #include <d3dx9.h> #include "InitWindow.h" #include "InitD3D.h" #include <iostream> #include <fstream> #include "Vektor3D.h" #include "Color.h" using namespace std; CInitD3D id3d; CWindow cw; float stime = 0.0f; float TranslationX = 0.0f; float TranslationY = 0.0f; float TranslationZ = 0.0f; float APositionX = 0.0f; float APositionY = -14.0f; float APositionZ = -25.0f; LPD3DXMESH g_pSphereModel = NULL; PDIRECT3DTEXTURE9 g_pSphereTexture = NULL; D3DXVECTOR3 g_vCameraPosition = D3DXVECTOR3(0.0f, -14.0f, -25.0f); // Die Kameraposition float g_fCameraAngle = 0.0f; // Drehwinkel der Kamera #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1) HRESULT Render() { D3DXMATRIX ViewMatrix; D3DXMATRIX ProjectionMatrix; D3DXMATRIX TranslationMatrix; D3DXMATRIX WorldMatrix; D3DXMatrixLookAtLH(&ViewMatrix, &g_vCameraPosition, &D3DXVECTOR3(sinf(g_fCameraAngle), 0.0f, cosf(g_fCameraAngle)), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixPerspectiveFovLH(&ProjectionMatrix, D3DXToRadian(60.f),1.f,1.f,100.f); D3DXMatrixTranslation(&TranslationMatrix, TranslationX, TranslationY, TranslationZ); WorldMatrix = TranslationMatrix; id3d.pd3dDevice->SetTransform(D3DTS_WORLD, &WorldMatrix); id3d.pd3dDevice->SetTransform(D3DTS_VIEW, &ViewMatrix); id3d.pd3dDevice->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix); HRESULT hresult; if(FAILED(hresult = id3d.pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 63), 1.0f, 0))) { MessageBox(NULL,"Fehler beim Leeren des Backbuffers","Fehler",MB_OK); return 1; } id3d.pd3dDevice->BeginScene(); id3d.pd3dDevice->SetTexture(0, g_pSphereTexture); g_pSphereModel->DrawSubset(0); id3d.pd3dDevice->EndScene(); id3d.pd3dDevice->Present(NULL,NULL,NULL,NULL); return 0; } HRESULT InitScene() { HRESULT hresult; hresult = id3d.pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX); if(FAILED(hresult)) { MessageBox(NULL,"Fehler beim Setzen des Vertexformat","Fehler",MB_OK); return 1; } id3d.pd3dDevice->SetRenderState(D3DRS_LIGHTING,FALSE); id3d.pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE); id3d.pd3dDevice->SetRenderState(D3DRS_DITHERENABLE,TRUE); D3DXMATRIX ProjMatrix; D3DXMatrixPerspectiveFovLH(&ProjMatrix, D3DX_PI/4, static_cast<float>(cw.Breite) / static_cast<float>(cw.Höhe), 1.0f, 100.0f ); id3d.pd3dDevice->SetTransform(D3DTS_PROJECTION, &ProjMatrix); HRESULT hResult; if(FAILED(hResult = D3DXCreateTextureFromFileEx(id3d.pd3dDevice, // Device "Tex.jpg", // Dateiname D3DX_DEFAULT, // Breite D3DX_DEFAULT, // Höhe D3DX_DEFAULT, // 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_pSphereTexture))) // Die Textur { // Fehler! MessageBox(NULL,"D3DXCreateTextureFromFileEx", "", MB_OK); } D3DXLoadMeshFromX("Men.x", D3DXMESH_MANAGED, id3d.pd3dDevice, NULL, NULL, NULL, NULL, &g_pSphereModel); return 0; } HRESULT Move() { if(GetAsyncKeyState(VK_RIGHT)) TranslationX += stime - (stime - 0.009f); if(GetAsyncKeyState(VK_LEFT)) TranslationX -= stime - (stime - 0.009f); if(GetAsyncKeyState(VK_UP)) TranslationY += stime - (stime - 0.009f); if(GetAsyncKeyState(VK_DOWN)) TranslationY -= stime - (stime - 0.009f); g_vCameraPosition.x = (APositionX + TranslationX); g_vCameraPosition.y = (APositionY + TranslationY); g_vCameraPosition.z = (APositionZ + TranslationZ); 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 |
HRESULT Move() { if(GetAsyncKeyState(VK_RIGHT)) { TranslationX += stime - (stime - 0.009f); g_vCameraPosition.x += (stime - (stime - 0.009f)) * 3; } if(GetAsyncKeyState(VK_LEFT)) { TranslationX -= stime - (stime - 0.009f); g_vCameraPosition.x -= (stime - (stime - 0.009f)) * 3; } if(GetAsyncKeyState(VK_UP)) { TranslationY += stime - (stime - 0.009f); g_vCameraPosition.y += (stime - (stime - 0.009f)) * 3; } if(GetAsyncKeyState(VK_DOWN)) { TranslationY -= stime - (stime - 0.009f); g_vCameraPosition.y -= (stime - (stime - 0.009f)) * 3; } return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 |
... (*MoveGame)(); (*RenderGame)(); ... |
Werbeanzeige