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 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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
//Intro.h #ifndef _INTRO_INC_ #define _INTRO_INC_ class CIntro{ public: CIntro(); ~CIntro(); tbResult Init(); tbResult Load(); tbResult Unload(); tbResult Exit(); tbResult Move(float fTime); tbResult Render(float fTime); //vergangene Zeit seit Zustandsbeginn float m_fTime; //Das Levelmodel tbModel m_vLevelModel; }; #endif //Intro.cpp #include "VierGewinnt.h" CIntro::CIntro(){} CIntro::~CIntro(){} tbResult CIntro::Init(){ TB_INFO("Initalisiere das Intro!"); //Direct3D tbDirect3D &D3D = tbDirect3D::Instance(); //CPin CPin &Pin = CPin::Instance(); //Zeit Variable auf Null setzen m_fTimeSEnd = 0.0f; //Weltmatrix setzen tbMatrix mWorld = tbMatrixTranslation(tbVector3(0.0f, 0.0f, 0.0f)); D3D.SetTransform(D3DTS_WORLD, mWorld); //Sichtmatrix setzen tbMatrix mView = tbMatrixTranslation(tbVector3(0.0f, 2.0f, -3.0f)); D3D.SetTransform(D3DTS_VIEW, mView); //Modelle laden if(Load()){ return TB_ERROR; } //Pins initalisieren int Pos; Pos = CPin::Instance().GetNextFreePlace(); m_dEndPinPos[0] = Pos; Pin.AddPin(Pos,5,1); Pin.SetColor(Pos, FALSE); Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,5,2); Pin.SetColor(Pos, FALSE); Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,5,3); Pin.SetColor(Pos, TRUE); Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,5,4); Pin.SetColor(Pos, TRUE); Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,5,5); Pin.SetColor(Pos, TRUE); Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,5,6); Pin.SetColor(Pos, FALSE); m_dEndPinPos[1] = Pos; Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,4,2); Pin.SetColor(Pos, FALSE); Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,4,3); Pin.SetColor(Pos, TRUE); Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,4,4); Pin.SetColor(Pos, TRUE); Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,4,5); Pin.SetColor(Pos, FALSE); m_dEndPinPos[2] = Pos; Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,3,3); Pin.SetColor(Pos, FALSE); Pos = Pin.GetNextFreePlace(); Pin.AddPin(Pos,3,4); Pin.SetColor(Pos, TRUE); m_dStartPinPos = Pin.GetNextFreePlace(); m_dEndPinPos[3] = Pos; Pin.AddPin(m_dStartPinPos,0,0); Pin.SetColor(m_dStartPinPos, FALSE); Pin.SetPosition(m_dStartPinPos,2,4,FALSE); TB_INFO("Initalisierung des Intros beendet!"); return TB_OK; } tbResult CIntro::Load(){ //Modelle laden if(m_vLevelModel.Init("Model.tbm")){ //Fehler! TB_ERROR("Das Levelmodel konnte nicht geladen werden!", TB_ERROR); } return TB_OK; } tbResult CIntro::Unload(){ //Modelle entladen if(m_vLevelModel.Exit()){ //Fehler! TB_ERROR("Das Levelmodel konnte nicht entladen werden!", TB_ERROR); } return TB_OK; } tbResult CIntro::Exit(){ //Modelle entladen return Unload(); } tbResult CIntro::Move(float fTime){ m_fTime+=fTime; CPin::Instance().Move(fTime); return TB_OK; } tbResult CIntro::Render(float fTime){ //Direct3D tbDirect3D &D3D = tbDirect3D::Instance(); //Es Gibt ein Lichter D3DLIGHT9 m_pLight; //Material D3DMATERIAL9 xMaterial; D3D->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, tbColor(1.0f), 1.0f, 0); D3D->BeginScene(); //Sichtmatrix setzen tbMatrix mView = tbMatrixTranslation(tbVector3(0.0f, 2.0f, -3.0f)) * tbMatrixRotationY(90.0f * m_fTime); D3D.SetTransform(D3DTS_VIEW, mView); // Die Projektionsmatrix erzeugen und einsetzen. tbMatrix mProjection = tbMatrixProjection(TB_DEG_TO_RAD(70.0f), tbDirect3D::Instance().GetAspect(), 0.1f, 100.0f); tbDirect3D::Instance()->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)(&mProjection)); //Sichtmatrix setzen tbMatrix mWorld = tbMatrixTranslation(tbVector3(0.0f, 0.0f, 0.0f)); D3D.SetTransform(D3DTS_WORLD, mWorld); // Render-States D3D.SetRS(D3DRS_FILLMODE, D3DFILL_SOLID); D3D.SetRS(D3DRS_AMBIENT, tbColor(1.0f, 1.0f, 1.0f)); D3D.SetRS(D3DRS_LIGHTING, TRUE); D3D.SetRS(D3DRS_CULLMODE, D3DCULL_NONE); D3D.SetRS(D3DRS_ZENABLE, TRUE); D3D.SetRS(D3DRS_ZWRITEENABLE, TRUE); D3D.Capture(); ZeroMemory(&m_pLight, sizeof(D3DLIGHT9)); m_pLight.Type = D3DLIGHT_POINT; m_pLight.Diffuse = tbColor(1.0f, 1.0f, 1.0f); m_pLight.Ambient = tbColor(1.0f, 1.0f, 1.0f); m_pLight.Specular = tbColor(1.0f, 1.0f, 1.0f); m_pLight.Position = tbVector3(0.0f, 2.0f, -3.0f); m_pLight.Range = 1000.0f; m_pLight.Attenuation0 = 0.0f; m_pLight.Attenuation1 = 0.25f; m_pLight.Attenuation2 = 0.0f; D3D->SetLight(0, &m_pLight); D3D->LightEnable(0, TRUE); xMaterial.Diffuse = tbColor(0.75f,0.75f,0.75f); xMaterial.Ambient = tbColor(0.25f,0.25f,0.25f); xMaterial.Emissive = tbColor(0.0f,0.0f,0.0f); xMaterial.Specular = tbColor(0.25f,0.25f,0.25f); xMaterial.Power = 5.0f; D3D->SetMaterial(&xMaterial); m_vLevelModel.Render(); CPin::Instance().Render(fTime); D3D->EndScene(); return TB_OK; } //Pin.h #ifndef _PIN_INC_ #define _PIN_INC_ class CPin{ public: CPin(); ~CPin(); static CPin& Instance(); tbResult Init(); tbResult Load(); tbResult Unload(); tbResult Exit(); int GetNextFreePlace(); tbResult AddPin(int Place, int Zeile, int Spalte); tbResult SetColor(int Place, BOOL Color); tbResult SetRotation(int Place, BOOL Rotate); tbResult SetPosition(int Place, int Zeile, int Spalte,BOOL Sofort); tbResult Move(float fTime); tbResult Render(float fTime); //Ist Initalisiert? BOOL m_bInitialized; //Positionen der Pins tbVector3 m_vPosition[35]; //Matrizen für die Pin-Modelle tbMatrix m_vPin1Matrix[35]; tbMatrix m_vPin2Matrix[35]; //Weerden die Position von den Pins gewechselt? BOOL m_bPosChange[35]; float m_fTimeSinceStart[35]; tbVector3 m_vEndPos[35]; tbVector2 m_vWay[35]; //Erxisitieren die Pins BOOL m_bExist[35]; //Rotieren die Pins gerade? BOOL m_bRotate[35]; //Wie lange rotieren sie schon? float m_fRotationTime[35]; //Farbe - FALSE = SCHWARZ ; TRUE = WEIS BOOL m_bColor[35]; //Pin Modelle tbModel m_vPinModelWhite1; tbModel m_vPinModelWhite2; tbModel m_vPinModelBlack1; tbModel m_vPinModelBlack2; }; #endif //Pin.cpp #include "VierGewinnt.h" CPin& CPin::Instance(){ static CPin TheOneAndOnly; return TheOneAndOnly; } CPin::CPin(){} CPin::~CPin(){ if(m_bInitialized){ CPin::Instance().Exit(); } } tbResult CPin::Init(){ TB_INFO("CPin wird initalisiert!"); //Modelle laden if(Load()){ return TB_ERROR; } for(int i=0;i<=34;i++){ m_vPosition[i] = tbVector3(0.0f, 0.0f, 0.0f); m_vPin1Matrix[i] = tbMatrixTranslation(tbVector3(0.0f, 0.0f, 0.0f)); m_vPin2Matrix[i] = tbMatrixTranslation(tbVector3(0.0f, 0.0f, 0.0f)); m_bPosChange[i] = FALSE; m_fTimeSinceStart[i] = 0.0f; m_vEndPos[i] = tbVector3(0.0f, 0.0f, 0.0f); m_vWay[i] = tbVector2(0.0f, 0.0f); m_bExist[i] = FALSE; m_bRotate[i] = FALSE; m_fRotationTime[i] = 0.0f; } //Ist Initalisiert? BOOL m_bInitialized = TRUE; TB_INFO("CPin initalisiert!"); return TB_OK; } tbResult CPin::Load(){ //Modelle laden if(m_vPinModelWhite1.Init("PinWhite1.tbm")){ //Fehler! TB_ERROR("Das weiße Pinmodel 1 konnte nicht geladen werden!", TB_ERROR); return TB_ERROR; } if(m_vPinModelWhite2.Init("PinWhite2.tbm")){ //Fehler! TB_ERROR("Das weiße Pinmodel 2 konnte nicht geladen werden!", TB_ERROR); return TB_ERROR; } if(m_vPinModelBlack1.Init("PinBlack1.tbm")){ //Fehler! TB_ERROR("Das schwarze Pinmodel 1 konnte nicht geladen werden!", TB_ERROR); return TB_ERROR; } if(m_vPinModelBlack2.Init("PinBlack2.tbm")){ //Fehler! TB_ERROR("Das schwarze Pinmodel 2 konnte nicht geladen werden!", TB_ERROR); return TB_ERROR; } return TB_OK; } tbResult CPin::Unload(){ //Pin Modelle entladen if(m_vPinModelWhite1.Exit()){ TB_ERROR("Das weiße Pinmodel 1 konnte nicht entladen werden!", TB_ERROR); } if(m_vPinModelWhite2.Exit()){ TB_ERROR("Das weiße Pinmodel 1 konnte nicht entladen werden!", TB_ERROR); } if(m_vPinModelBlack1.Exit()){ TB_ERROR("Das schwarze Pinmodel 1 konnte nicht entladen werden!", TB_ERROR); } if(m_vPinModelBlack2.Exit()){ TB_ERROR("Das schwarze Pinmodel 1 konnte nicht entladen werden!", TB_ERROR); } return TB_OK; } tbResult CPin::Exit(){ TB_INFO("CPin wird heruntergefahren!"); //Alles entladen if(Unload()){ return TB_ERROR; } //CPin heruntergefahren m_bInitialized = FALSE; TB_INFO("CPin ist heruntergefahren!"); return TB_OK; } int CPin::GetNextFreePlace(){ for(int i=0;i<=34;i++){ if(m_bExist[i] == FALSE){ return i; } } return TB_ERROR; } tbResult CPin::AddPin(int Place, int Zeile, int Spalte){ //Position ist nicht ausserhalb des Feldes! if(Zeile>5||Spalte>6){ return TB_ERROR; } //Position 0/0 float x = -1.5; float y = 3.25; float z = 0.0f; //Übergebene Position hinzuberechenen x+=(float)(Zeile*0.5); y+=(float)(Spalte*0.5); m_vPosition[Place] = tbVector3(x, y, z); m_vPin1Matrix[Place] = tbMatrixTranslation(tbVector3(0.0f, 0.0f, 0.0f)); m_vPin2Matrix[Place] = tbMatrixTranslation(tbVector3(0.0f, 0.0f, 0.0f)); m_bPosChange[Place] = FALSE; m_fTimeSinceStart[Place] = 0.0f; m_vEndPos[Place] = tbVector3(0.0f, 0.0f, 0.0f); m_vWay[Place] = tbVector2(0.0f, 0.0f); m_bExist[Place] = TRUE; m_bRotate[Place] = FALSE; m_fRotationTime[Place] = 0.0f; return TB_OK; } tbResult CPin::SetColor(int Place, BOOL Color){ //Farbe wird geändert m_bColor[Place] = Color; return TB_OK; } tbResult CPin::SetRotation(int Place, BOOL Rotate){ if(m_bRotate[Place] == Rotate){ //Es brauchen keine Änderungen vorgenommen werden! return TB_OK; } //Zeit der Rotation wird zurückgesetzt m_fRotationTime[Place] = 0.0f; //Neue Rotation setzen m_bRotate[Place] = Rotate; return TB_OK; } tbResult CPin::SetPosition(int Place, int Zeile, int Spalte,BOOL Sofort){ //Position ist nicht ausserhalb des Feldes! if(Zeile>5||Spalte>6){ return TB_ERROR; } //Position 0/0 float x = -1.5; float y = 3.25; float z = 0.0f; //Übergebene Position hinzuberechenen x+=(float)(Zeile*0.5); y+=(float)(Spalte*0.5); //Soll es einen Positionsübergang geben? if(Sofort==FALSE){ //Position setzen m_vEndPos[Place] = tbVector3(x,y,z); //In der Move Funktion muss der Positionsübergang berechnet werden! m_bPosChange[Place] = TRUE; //Zeit Variable zurücksetzen m_fTimeSinceStart[Place] = 0.0f; //Weg berechnen m_vWay[Place].x = m_vEndPos[Place].x-m_vPosition[Place].x; m_vWay[Place].y = m_vEndPos[Place].y-m_vPosition[Place].y; } else{ //Position setzen m_vPosition[Place] = tbVector3(x,y,z); //Die Position wurde sofort geändert //Es muss kein Übergang berechnet werden m_bPosChange[Place] = FALSE; } return TB_OK; } tbResult CPin::Move(float fTime){ //Alle Pins durchgehen for(int i=0;i<=34;i++){ //Findet gerade ein Positionsübergang statt? if(m_bPosChange[i] == TRUE){ m_fTimeSinceStart[i]+=fTime; if(m_fTimeSinceStart[i] > 1.0f){ m_bPosChange[i] = FALSE; m_vPosition[i] = m_vEndPos[i]; } else{ m_vPosition[i].x += (m_vWay[i].x * m_fTimeSinceStart[i]); m_vPosition[i].y += (m_vWay[i].y * m_fTimeSinceStart[i]); } } if(m_bRotate[i] == TRUE){ //Matrizen für die Pinbewegung berechnen m_vPin1Matrix[i] = tbMatrixRotationX(90.0f * m_fRotationTime[i]); m_vPin2Matrix[i] = tbMatrixRotationY(30.0f * m_fRotationTime[i]); } else{ //Matrizen für die Pinbewegung berechnen m_vPin1Matrix[i] = tbMatrixRotationX(0); m_vPin2Matrix[i] = tbMatrixRotationY(0); } } return TB_OK; } tbResult CPin::Render(float fTime){ //Direct3D tbDirect3D &D3D = tbDirect3D::Instance(); //Variablen tbMatrix mOldWorld; tbMatrix mWorld; //Alte Weltmatrix speichern mOldWorld = D3D.GetTransform(D3DTS_WORLD); for(int i=0;i<=34;i++){ //Neue Weltmatrix einsetzen mWorld = tbMatrixTranslation(m_vPosition[i]) * m_vPin1Matrix[i]; D3D.SetTransform(D3DTS_WORLD, mWorld); //Pin zeichnen if(m_bColor[i] == TRUE){ m_vPinModelWhite1.Render(); } else{ m_vPinModelBlack1.Render(); } //Neue Weltmatrix einsetzen mWorld = tbMatrixTranslation(m_vPosition[i]) * m_vPin2Matrix[i]; D3D.SetTransform(D3DTS_WORLD, mWorld); //Pin zeichnen if(m_bColor[i] == TRUE){ m_vPinModelWhite2.Render(); } else{ m_vPinModelBlack2.Render(); } } //Alte Weltmatrix einsetzen D3D.SetTransform(D3DTS_WORLD, mOldWorld); return TB_OK; } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Harry222« (21.07.2010, 14:14)
C-/C++-Quelltext |
|
1 2 3 4 5 |
// Direct3D initialisieren if(tbDirect3D::Instance().Init(&m_Config, "Vier gewinnt", NULL, LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)))){ // Fehler! TB_ERROR("Fehler beim Initialisieren von Direct3D!", TB_ERROR); } |
C-/C++-Quelltext |
|
1 |
D3D->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, tbColor(1.0f), 1.0f, 0); |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Harry222« (21.07.2010, 15:36)
Werbeanzeige