Entity.cpp 879 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. }
  14. void Entity::draw()
  15. {
  16. if (model)
  17. {
  18. glPushMatrix();
  19. glTranslatef(position.x, position.y, position.z);
  20. glRotatef(rotation.x, 1, 0, 0);
  21. glRotatef(rotation.y, 0, 1, 0);
  22. glRotatef(rotation.z, 0, 0, 1);
  23. glScalef(scale, scale, scale);
  24. glEnable(GL_CULL_FACE);
  25. glCullFace(GL_BACK);
  26. model->draw();
  27. glCullFace(GL_FRONT);
  28. model->draw();
  29. glDisable(GL_CULL_FACE);
  30. glPopMatrix();
  31. }
  32. }
  33. bool Entity::inObject(const Vec3f & point)
  34. {
  35. if (!model)
  36. return false;
  37. Vec3f center = position + model->center;
  38. float distance = sqrt((point.x - center.x) * (point.x - center.x) + (point.z - center.z)*(point.z - center.z));
  39. if (distance < model->radius*scale)
  40. return true;
  41. return false;
  42. }