WORLD.CPP
Upload User: nthssl
Upload Date: 2022-04-05
Package Size: 25357k
Code Size: 1k
Category:

OpenCV

Development Platform:

Visual C++

  1. #include "world.h"
  2. CWorld::CWorld()
  3. {
  4. terrain = new CTerrain(256, 0.5);
  5. }
  6. CWorld::~CWorld()
  7. {
  8. audioSystem->Shutdown();
  9. delete terrain;
  10. delete audioSystem;
  11. delete worldSound;
  12. }
  13. CWorld::CWorld(CCamera *c)
  14. {
  15. camera = c;
  16. terrain = new CTerrain(256, 0.4f);
  17. enemy = new CEntity;
  18. enemy2 = new CEntity;
  19. audioSystem = new CAudioSystem;
  20. audioSystem->InitDirectXAudio(NULL);
  21. enemy->AttachTo(terrain);
  22. enemy2->AttachTo(terrain);
  23. worldSound = audioSystem->Create("ambient.wav", false);
  24. audioSystem->Play(worldSound, DMUS_SEG_REPEAT_INFINITE);
  25. enemy->Load("models\sodf8\tris.md2", "models\sodf8\abarlith.pcx");
  26. enemy->SetState(MODEL_RUN);
  27. enemy->direction = 45.0;
  28. enemy2->Load("models\ogro\tris.md2", "models\ogro\ogrobase.pcx");
  29. enemy2->SetState(MODEL_RUN);
  30. enemy2->direction = 225.0;
  31. enemy2->position = CVector(200.0, 0.0, 200.0);
  32. }
  33. void CWorld::Animate(float deltaTime)
  34. {
  35. // 根据地形设置摄像机的高度位置
  36. camera->position.y = terrain->GetHeight(camera->position.x, camera->position.z) + 10.0f;
  37. terrain->Animate(deltaTime);
  38. }
  39. void CWorld::Draw(CCamera *camera)
  40. {
  41. terrain->Draw(camera);
  42. }
  43. void CWorld::OnPrepare()
  44. {
  45. glClearColor(terrain->fogColor[0], terrain->fogColor[1], terrain->fogColor[2], terrain->fogColor[3]);
  46. terrain->Prepare();
  47. }