Entity.cpp 761 B

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