World.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <GL/gl.h>
  2. #include "World.h"
  3. #include "Player.h"
  4. #include <string>
  5. #include "Model.h"
  6. World* World::instance = nullptr;
  7. World::World()
  8. {
  9. objects[0].position = Vec3f(GridSizeX*SizeX/2,-5,GridSizeY*SizeY/2);
  10. objects[0].scale = 200;
  11. objects[1].position = Vec3f(30,-5,30);
  12. objects[1].scale = 2;
  13. objects[1].text = "Gebruiker invloed met Z en X";
  14. objects[2].position = Vec3f(40,-5,30);
  15. objects[2].scale = 2;
  16. objects[2].text = "Stil staand object";
  17. objects[3].position = Vec3f(50,-5,30);
  18. objects[3].scale = 2;
  19. objects[3].text = "Nog een stil staand object";
  20. objects[4].position = Vec3f(60,-5,30);
  21. objects[4].scale = 2;
  22. objects[4].text = "Automatisch bewegend object";
  23. randomobject.position = Vec3f(70,-5,30);
  24. randomobject.text = "Door computer gegenereerd";
  25. randomobject.scale = 2;
  26. entity.model = Model::load("models/Bob.obj");
  27. entity.position = Vec3f(80, -5, 30);
  28. entity.text = "Een model ingeladen";
  29. entity2.model = Model::load("models/IronMan.obj");
  30. entity2.position = Vec3f(100, -5, 30);
  31. entity2.scale = 1;
  32. entity2.text = "Nog een model ingeladen";
  33. }
  34. World::~World()
  35. {
  36. }
  37. World* World::getInstance()
  38. {
  39. if (instance == nullptr)
  40. instance = new World();
  41. return instance;
  42. }
  43. void World::init()
  44. {
  45. instance = new World();
  46. }
  47. void World::draw(void) {
  48. Player::getInstance()->setCamera();
  49. Player::getInstance()->draw();
  50. for (unsigned int x = 0; x < GridSizeX; ++x){
  51. for (unsigned int y = 0; y < GridSizeY; ++y) {
  52. glBegin(GL_QUADS);
  53. if ((x+y)&0x00000001) //modulo 2
  54. glColor3f(1.0f,1.0f,1.0f); //white
  55. else
  56. glColor3f(0.0f,0.0f,0.0f); //black
  57. glVertex3f(x*SizeX, -10, y*SizeY);
  58. glVertex3f((x+1)*SizeX, -10, y*SizeY);
  59. glVertex3f((x+1)*SizeX, -10, (y+1)*SizeY);
  60. glVertex3f(x*SizeX, -10, (y+1)*SizeY);
  61. glEnd();
  62. }
  63. }
  64. for(auto e:objects)
  65. e.draw();
  66. randomobject.draw();
  67. entity.draw();
  68. }
  69. void World::update(float deltaTime)
  70. {
  71. objects[4].rotation.x += 20*deltaTime;
  72. objects[0].rotation.x += 20*deltaTime;
  73. }