Entity.cpp 986 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "Entity.h"
  2. #include "cmath"
  3. #include <GL/freeglut.h>
  4. #include "Model.h"
  5. Entity::Entity()
  6. {
  7. model = NULL;
  8. scale = 1;
  9. canCollide = true;
  10. }
  11. Entity::~Entity()
  12. {
  13. if(model)
  14. Model::unload(model);
  15. }
  16. void Entity::draw()
  17. {
  18. if (model)
  19. {
  20. glPushMatrix();
  21. glTranslatef(position.x, position.y, position.z);
  22. glRotatef(rotation.x, 1, 0, 0);
  23. glRotatef(rotation.y, 0, 1, 0);
  24. glRotatef(rotation.z, 0, 0, 1);
  25. glScalef(scale, scale, scale);
  26. glTranslatef(-model->center.x, 0, -model->center.z);
  27. glEnable(GL_CULL_FACE);
  28. glCullFace(GL_BACK);
  29. model->draw();
  30. glCullFace(GL_FRONT);
  31. model->draw();
  32. glDisable(GL_CULL_FACE);
  33. glPopMatrix();
  34. }
  35. }
  36. bool Entity::inObject(const Vec3f & point)
  37. {
  38. if (!model)
  39. return false;
  40. Vec3f center = position + model->center;
  41. float distance = ((point.x - center.x) * (point.x - center.x) + (point.z - center.z)*(point.z - center.z));
  42. if (distance < model->radius*scale*model->radius*scale)
  43. return true;
  44. return false;
  45. }