Camera.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "anki/scene/Camera.h"
  2. namespace anki {
  3. //==============================================================================
  4. // Camera =
  5. //==============================================================================
  6. //==============================================================================
  7. Camera::~Camera()
  8. {}
  9. //==============================================================================
  10. void Camera::lookAtPoint(const Vec3& point)
  11. {
  12. const Vec3& j = Vec3(0.0, 1.0, 0.0);
  13. Vec3 vdir = (point - getLocalTransform().getOrigin()).getNormalized();
  14. Vec3 vup = j - vdir * j.dot(vdir);
  15. Vec3 vside = vdir.cross(vup);
  16. Mat3 rot = getLocalTransform().getRotation();
  17. rot.setColumns(vside, vup, -vdir);
  18. setLocalRotation(rot);
  19. }
  20. //==============================================================================
  21. // PerspectiveCamera =
  22. //==============================================================================
  23. //==============================================================================
  24. PerspectiveCamera::PerspectiveCamera(const char* name, Scene* scene,
  25. uint movableFlags, Movable* movParent)
  26. : Camera(CT_PERSPECTIVE, name, scene, movableFlags, movParent, &frustum)
  27. {
  28. Property<PerspectiveFrustum>& prop =
  29. addNewProperty(new ReadWritePointerProperty<PerspectiveFrustum>(
  30. "frustum", &frustum));
  31. ANKI_CONNECT(&prop, valueChanged, this, updateFrustumSlot);
  32. }
  33. //==============================================================================
  34. // OrthographicCamera =
  35. //==============================================================================
  36. //==============================================================================
  37. OrthographicCamera::OrthographicCamera(const char* name, Scene* scene,
  38. uint movableFlags, Movable* movParent)
  39. : Camera(CT_ORTHOGRAPHIC, name, scene, movableFlags, movParent, &frustum)
  40. {
  41. Property<OrthographicFrustum>& prop =
  42. addNewProperty(new ReadWritePointerProperty<OrthographicFrustum>(
  43. "frustum", &frustum));
  44. ANKI_CONNECT(&prop, valueChanged, this, updateFrustumSlot);
  45. }
  46. } // end namespace