Entity.cpp 864 B

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