Entity.cpp 930 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. glEnable(GL_CULL_FACE);
  27. glCullFace(GL_BACK);
  28. model->draw();
  29. glCullFace(GL_FRONT);
  30. model->draw();
  31. glDisable(GL_CULL_FACE);
  32. glPopMatrix();
  33. }
  34. }
  35. bool Entity::inObject(const Vec3f & point)
  36. {
  37. if (!model)
  38. return false;
  39. Vec3f center = position + model->center;
  40. float distance = ((point.x - center.x) * (point.x - center.x) + (point.z - center.z)*(point.z - center.z));
  41. if (distance < model->radius*scale*model->radius*scale)
  42. return true;
  43. return false;
  44. }