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 |
int maus_y = 0, maus_x = 0; POINT curCursorPos; POINT g_fenstermitte; float acceptNewClickTime = 0.50f; float recognizeNextClick = acceptNewClickTime; bool nextClick = true; bool Render(float secsPassed) { g_time += secsPassed; geschwindigkeit = 10.0f*secsPassed; GetCursorPos(&curCursorPos); maus_x = curCursorPos.x - g_fenstermitte.x; maus_y = curCursorPos.y - g_fenstermitte.y; //Kamera um x-Achse drehen if(maus_y > min_maus_ausschlag_y && g_time > 0.1) //Spieler verändert Sicht (hoch oder runter) { press_key = true; D3DXMatrixRotationX(&matrixRotateX,-0.02f); } else if(maus_y < -min_maus_ausschlag_y && g_time > 0.1) //Spieler verändert Sicht (hoch oder runter) { press_key = true; D3DXMatrixRotationX(&matrixRotateX,0.02f); } //Kamera um y-Achse drehen else if(maus_x > min_maus_ausschlag_x && g_time > 0.1) //Spieler verändert Sicht (hoch oder runter) { press_key = true; D3DXMatrixRotationY(&matrixRotateY,-0.02f); } else if(maus_x < -min_maus_ausschlag_x && g_time > 0.1) //Spieler verändert Sicht (hoch oder runter) { press_key = true; D3DXMatrixRotationY(&matrixRotateY,0.02f); } g_maus.x =GetSystemMetrics(SM_CXSCREEN)/2; g_maus.y =GetSystemMetrics(SM_CYSCREEN)/2; g_fenstermitte.x = g_maus.x; g_fenstermitte.y = g_maus.y; SetCursorPos(g_maus.x,g_maus.y); //Kamera zoom if(GetAsyncKeyState(VK_PRIOR)) { fov-= deg_to_rad(15.0f) * geschwindigkeit; press_key = true; } if(GetAsyncKeyState(VK_NEXT)) { fov+= deg_to_rad(15.0f) * geschwindigkeit; press_key = true; } //Kamera auf x-Achse bewegen if(GetAsyncKeyState(VK_LEFT)) { playerposition.x -= geschwindigkeit; press_key = true; D3DXMatrixTranslation(&matrixTrans,geschwindigkeit,0.0f,0.0f); } if(GetAsyncKeyState(VK_RIGHT)) { playerposition.x += geschwindigkeit; press_key = true; D3DXMatrixTranslation(&matrixTrans,-geschwindigkeit,0.0f,0.0f); } //Kamera auf z-Achse bewegen if(GetAsyncKeyState(VK_UP)) { playerposition.z += geschwindigkeit; press_key = true; D3DXMatrixTranslation(&matrixTrans,0.0f,0.0f,-geschwindigkeit); } if(GetAsyncKeyState(VK_DOWN)) { playerposition.z -= geschwindigkeit; press_key = true; D3DXMatrixTranslation(&matrixTrans,0.0f,0.0f,geschwindigkeit); } //Mapgrenzen kontrollieren if(playerposition.x > map.right ) { playerposition.x = map.right; press_key = false; } if(playerposition.x < map.left ) { playerposition.x = map.left; press_key = false; } if(playerposition.y > map.top ) { playerposition.y = map.top; press_key = false; } if(playerposition.y < map.bottom ) { playerposition.y = map.bottom; press_key = false; } if(playerposition.z > map.depth ) { playerposition.z = map.depth; press_key = false; } if(playerposition.z < map.back ) { playerposition.z = map.back; press_key = false; } if(press_key == false) //eine andere oder keine Taste wurde gedrückt { D3DXMatrixIdentity(&matrixTrans); //keine Verschiebung("Translation") D3DXMatrixIdentity(&matrixRotateX); //keine Drehung("Rotation") D3DXMatrixIdentity(&matrixRotateY); //keine Drehung("Rotation") D3DXMatrixIdentity(&matrixRotateZ); //keine Drehung("Rotation") } if (fov >= deg_to_rad(180.0f)) fov = deg_to_rad(179.9f); else if(fov <= deg_to_rad(0.0f)) fov = deg_to_rad(0.1f); D3DXMatrixMultiply(&matrixView,&matrixView,&matrixRotateX); D3DXMatrixMultiply(&matrixView,&matrixView,&matrixRotateY); D3DXMatrixMultiply(&matrixView,&matrixView,&matrixRotateZ); D3DXMatrixMultiply(&matrixView,&matrixView,&matrixTrans); pD3DDevice->SetTransform(D3DTS_VIEW, &matrixView); D3DXMATRIX mProjection = matrixProjection(fov, aspect, 0.1f, 250.0f); pD3DDevice->SetTransform(D3DTS_PROJECTION, (&mProjection)); press_key = false; return true; } |
Quellcode |
|
1 |
D3DXMatrixMultiply(&matrixView,&matrixView,&matrixRotateZ); |
C-/C++-Quelltext |
|
1 |
D3DXMatrixIdentity(&matrixView);
|
Zitat von »"kickerxy123"«
Ich vermute inzwischen, dass ich hierbei nicht um Sinus und Kosinus herumkomme, denn die Achsen haben ja Abhängigkeiten voneinander. Sehe ich das richtig?
Werbeanzeige