Entity.cpp 746 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. model->draw();
  24. glPopMatrix();
  25. }
  26. }
  27. bool Entity::inObject(const Vec3f & point)
  28. {
  29. if (!model)
  30. return false;
  31. Vec3f center = position + model->center;
  32. float distance = sqrt((point.x - center.x) * (point.x - center.x) + (point.z - center.z)*(point.z - center.z));
  33. if (distance < model->radius*scale)
  34. return true;
  35. return false;
  36. }