Entity.cpp 1004 B

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