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 |
... DWORD indizes[36] = { 0,1,2, 1,2,3, 4,5,6, 5,6,7, 8,9,10, 9,10,11, 12,13,14, 13,14,15, 16,17,18, 17,18,19, 20,21,22, 21,22,23 }; ... void makeCubes(int anzahl) { wuerfels = new dice[anzahl]; //Random time(×); srand((unsigned int)time); for(int i = 0; i < anzahl; i++) { //////////////////////////KOORDINATEN////////////////////////// //Vorne wuerfels[i].wuerfel[0].pos = D3DXVECTOR3(-0.5f,0.5f,-0.5f); //Oben-Links wuerfels[i].wuerfel[1].pos = D3DXVECTOR3(0.5f,0.5f,-0.5f); //Oben-Rechts wuerfels[i].wuerfel[2].pos = D3DXVECTOR3(-0.5f,-0.5f,-0.5f); //Unten-Links wuerfels[i].wuerfel[3].pos = D3DXVECTOR3(0.5f,-0.5f,-0.5f); //Unten-Rechts //Hinten wuerfels[i].wuerfel[4].pos = D3DXVECTOR3(-0.5f,0.5f,0.5f); //Oben-Links wuerfels[i].wuerfel[5].pos = D3DXVECTOR3(0.5f,0.5f,0.5f); //Oben-Rechts wuerfels[i].wuerfel[6].pos = D3DXVECTOR3(-0.5f,-0.5f,0.5f); //Unten-Links wuerfels[i].wuerfel[7].pos = D3DXVECTOR3(0.5f,-0.5f,0.5f); //Unten-Rechts //Oben wuerfels[i].wuerfel[8].pos = D3DXVECTOR3(-0.5f,0.5f,0.5f); //Vorne-Links wuerfels[i].wuerfel[9].pos = D3DXVECTOR3(0.5f,0.5f,0.5f); //Vorne-Rechts wuerfels[i].wuerfel[10].pos = D3DXVECTOR3(-0.5f,0.5f,-0.5f); //Hinten-Links wuerfels[i].wuerfel[11].pos = D3DXVECTOR3(0.5f,0.5f,-0.5f); //Hinten-Rechts //Unten wuerfels[i].wuerfel[12].pos = D3DXVECTOR3(-0.5f,-0.5f,0.5f); //Vorne-Links wuerfels[i].wuerfel[13].pos = D3DXVECTOR3(0.5f,-0.5f,0.5f); //Vorne-Rechts wuerfels[i].wuerfel[14].pos = D3DXVECTOR3(-0.5f,-0.5f,-0.5f); //Hinten-Links wuerfels[i].wuerfel[15].pos = D3DXVECTOR3(0.5f,-0.5f,-0.5f); //Hinten-Rechts //Rechts wuerfels[i].wuerfel[16].pos = D3DXVECTOR3(0.5f,0.5f,0.5f); //Oben-Vorne wuerfels[i].wuerfel[17].pos = D3DXVECTOR3(0.5f,0.5f,-0.5f); //Oben-Hinten wuerfels[i].wuerfel[18].pos = D3DXVECTOR3(0.5f,-0.5f,0.5f); //Unten-Vorne wuerfels[i].wuerfel[19].pos = D3DXVECTOR3(0.5f,-0.5f,-0.5f); //Unten-Hinten //Links wuerfels[i].wuerfel[20].pos = D3DXVECTOR3(-0.5f,0.5f,0.5f); //Oben-Vorne wuerfels[i].wuerfel[21].pos = D3DXVECTOR3(-0.5f,0.5f,-0.5f); //Oben-Hinten wuerfels[i].wuerfel[22].pos = D3DXVECTOR3(-0.5f,-0.5f,0.5f); //Unten-Vorne wuerfels[i].wuerfel[23].pos = D3DXVECTOR3(-0.5f,-0.5f,-0.5f); //Unten-Hinten //////////////////////////NORMALENVEKTOREN////////////////////////// //Vorne wuerfels[i].wuerfel[0].normal = D3DXVECTOR3(0.0f,0.0f,-1.0f); //Oben-Links wuerfels[i].wuerfel[1].normal = D3DXVECTOR3(0.0f,0.0f,-1.0f); //Oben-Rechts wuerfels[i].wuerfel[2].normal = D3DXVECTOR3(0.0f,0.0f,-1.0f); //Unten-Links wuerfels[i].wuerfel[3].normal = D3DXVECTOR3(0.0f,0.0f,-1.0f); //Unten-Rechts //Hinten wuerfels[i].wuerfel[4].normal = D3DXVECTOR3(0.0f,0.0f,1.0f); //Oben-Links wuerfels[i].wuerfel[5].normal = D3DXVECTOR3(0.0f,0.0f,1.0f); //Oben-Rechts wuerfels[i].wuerfel[6].normal = D3DXVECTOR3(0.0f,0.0f,1.0f); //Unten-Links wuerfels[i].wuerfel[7].normal = D3DXVECTOR3(0.0f,0.0f,1.0f); //Unten-Rechts //Oben wuerfels[i].wuerfel[8].normal = D3DXVECTOR3(0.0f,1.0f,0.0f); //Vorne-Links wuerfels[i].wuerfel[9].normal = D3DXVECTOR3(0.0f,1.0f,0.0f); //Vorne-Rechts wuerfels[i].wuerfel[10].normal = D3DXVECTOR3(0.0f,1.0f,0.0f); //Hinten-Links wuerfels[i].wuerfel[11].normal = D3DXVECTOR3(0.0f,1.0f,0.0f); //Hinten-Rechts //Unten wuerfels[i].wuerfel[12].normal = D3DXVECTOR3(0.0f,-1.0f,0.0f);//Vorne-Links wuerfels[i].wuerfel[13].normal = D3DXVECTOR3(0.0f,-1.0f,0.0f);//Vorne-Rechts wuerfels[i].wuerfel[14].normal = D3DXVECTOR3(0.0f,-1.0f,0.0f);//Hinten-Links wuerfels[i].wuerfel[15].normal = D3DXVECTOR3(0.0f,-1.0f,0.0f);//Hinten-Rechts //Rechts wuerfels[i].wuerfel[16].normal = D3DXVECTOR3(1.0f,0.0f,0.0f); //Oben-Vorne wuerfels[i].wuerfel[17].normal = D3DXVECTOR3(1.0f,0.0f,0.0f); //Oben-Hinten wuerfels[i].wuerfel[18].normal = D3DXVECTOR3(1.0f,0.0f,0.0f); //Unten-Vorne wuerfels[i].wuerfel[19].normal = D3DXVECTOR3(1.0f,0.0f,0.0f); //Unten-Hinten //Links wuerfels[i].wuerfel[20].normal = D3DXVECTOR3(-1.0f,0.0f,0.0f);//Oben-Vorne wuerfels[i].wuerfel[21].normal = D3DXVECTOR3(-1.0f,0.0f,0.0f);//Oben-Hinten wuerfels[i].wuerfel[22].normal = D3DXVECTOR3(-1.0f,0.0f,0.0f);//Unten-Vorne wuerfels[i].wuerfel[23].normal = D3DXVECTOR3(-1.0f,0.0f,0.0f);//Unten-Hinten Zufallszahl[0] = rand(); Zufallszahl[1] = rand(); Zufallszahl[2] = rand(); for(int j = 0; j < 24; j++) wuerfels[i].wuerfel[j].diffuse = D3DCOLOR_XRGB((Zufallszahl[0]%255)+1,(Zufallszahl[2]%255+1),(Zufallszahl[1]%255+1)); ////////////Velocity,Rotation etc.//////////// wuerfels[i].pos = NULLPUNKT; wuerfels[i].velo = D3DXVECTOR3(((float)(Zufallszahl[0]%20)+1)/10,0.0f,-1.0f); wuerfels[i].rotation = D3DXVECTOR3(0.0f,0.0f,0.0f); wuerfels[i].rotationvelo = D3DXVECTOR3(3.0f,2.0f,1.0f); } } ... void RenderFunction(float dwTime) { D3DXMATRIX rotX,rotY,rotZ; D3DXMATRIX translate,back; D3DXMATRIX view; D3DXMATRIX proj; d3d9_device->Clear(0,NULL,D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0),1.0f,0); d3d9_device->BeginScene(); for(int i = 0; i < anzahlCubes; i++) { vBuffer->Lock(0,0,(void **)&locker,0); memcpy(locker,wuerfels[i].wuerfel,sizeof(wuerfels[i].wuerfel)); vBuffer->Unlock(); //Verschiebung und Rotation D3DXMatrixTranslation(&back,0.0f,-0.5f,0.0f); D3DXMatrixRotationX(&rotX,D3DXToRadian(180*wuerfels[i].rotation.x)); D3DXMatrixRotationY(&rotY,D3DXToRadian(180*wuerfels[i].rotation.y)); D3DXMatrixRotationZ(&rotZ,D3DXToRadian(180*wuerfels[i].rotation.z)); D3DXMatrixTranslation(&translate,wuerfels[i].pos.x,wuerfels[i].pos.y+0.5f,wuerfels[i].pos.z+3.0f); //View-Transformation berechnen D3DXMatrixLookAtLH(&view,&D3DXVECTOR3(0.0f,0.0f,-10.0f),&D3DXVECTOR3(0.0f,0.0f,0.0f),&D3DXVECTOR3(0.0f,1.0f,0.0f)); //Projektions-Transformation berechnen bei einer Bildgröße von 1200x800 D3DXMatrixPerspectiveFovLH(&proj,D3DXToRadian(90),1200.0f/800.0f,0.1f,1000.0f); //Transformationen setzen d3d9_device->SetTransform(D3DTS_WORLD,&(back*rotX*rotY*rotZ*translate)); d3d9_device->SetTransform(D3DTS_VIEW,&view); d3d9_device->SetTransform(D3DTS_PROJECTION,&proj); d3d9_device->SetStreamSource(0,vBuffer,0,sizeof(myVertex)); d3d9_device->SetIndices(iBuffer); d3d9_device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,24,0,12); } d3d9_device->EndScene(); d3d9_device->Present(NULL,NULL,NULL,NULL); } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Daispro« (11.11.2012, 15:27)
Werbeanzeige