[C++] The IN55 project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.1KB

  1. #include <iostream>
  2. #include <GL/glut.h>
  3. #include <assimp/cimport.h>
  4. #include <assimp/scene.h>
  5. #include <assimp/postprocess.h>
  6. #include <camera.h>
  7. Camera::Camera()
  8. {
  9. eyePos = Vec3(0.0f, 0.0f, 3.0f);
  10. centerPos = Vec3(0.0f, 0.0f, -5.0f);
  11. upVector = Vec3(0.0f, 1.0f, 0.0f);
  12. }
  13. void Camera::updateCamera()
  14. {
  15. this->calculateUp();
  16. gluLookAt(
  17. eyePos.x, eyePos.y, eyePos.z,
  18. centerPos.x, centerPos.y, centerPos.z,
  19. upVector.x, upVector.y, upVector.z
  20. );
  21. }
  22. void Camera::calculateUp()
  23. {
  24. float l = eyePos.length();
  25. Vec3 v = Vec3(eyePos.x/l, eyePos.y/l, eyePos.z/l);
  26. Vec3 up = Vec3(0.0f, 1.0f, 0.0f);
  27. Vec3 s = Vec3(
  28. v.y * up.z - v.z * up.y,
  29. v.z * up.x - v.x * up.z,
  30. v.x * up.y - v.y * up.x
  31. );
  32. upVector.x = s.y * v.z - s.z * v.y;
  33. upVector.y = s.z * v.x - s.x * v.z;
  34. upVector.z = s.x * v.y - s.y * v.x;
  35. }
  36. void Camera::setPos(Vec3 newPos)
  37. {
  38. eyePos=newPos;
  39. }
  40. void Camera::setOrient(Vec3 newOri)
  41. {
  42. centerPos=newOri;
  43. }
  44. Vec3 Camera::getPos()
  45. {
  46. return eyePos;
  47. }
  48. Vec3 Camera::getOrient()
  49. {
  50. return centerPos;
  51. }