|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "svl/util/camera.h"
-
- #include "glm/gtc/matrix_transform.hpp"
-
- namespace svl {
- namespace util {
-
- Camera::Camera(const glm::vec2 &viewport, CameraProjectionMode mode)
- {
- mViewport = viewport;
- mFieldOfView = 45.0f;
- mNearPlane = 0.01f;
- mFarPlane = 100.0f;
- mProjectionMode = mode;
- }
-
- Camera::~Camera()
- {
- }
-
- void Camera::updateProjectMatrix()
- {
- if (mProjectionMode == CameraProjectionMode::Perspective)
- {
- mProjectMatrix = glm::perspective(glm::radians(mFieldOfView), mViewport.x * 1.0f / mViewport.y, mNearPlane, mFarPlane);
- }
- else
- {
- mProjectMatrix = glm::ortho(-mViewport.x / 2.0f, mViewport.x / 2.0f, -mViewport.y / 2.0f, mViewport.y / 2.0f, mNearPlane, mFarPlane);
- }
- }
-
- glm::mat4 Camera::orientation() const
- {
- glm::mat4 orientation;
- orientation = glm::rotate(orientation, glm::radians(mVerticalAngle), glm::vec3(1, 0, 0));
- orientation = glm::rotate(orientation, glm::radians(mHorizontalAngle), glm::vec3(0, 1, 0));
- return orientation;
- }
-
- void Camera::lookAt(const glm::vec3 &at)
- {
- assert(mPosition != at);
- //position =
- }
-
- void Camera::move(const glm::vec3 &offset)
- {
- mPosition += offset;
- }
-
- void Camera::moveTo(const glm::vec3 &pos)
- {
- if (mPosition != pos)
- {
- mPosition = pos;
- }
- }
-
- const glm::mat4 &Camera::projectionMatrix()
- {
- return mProjectMatrix;
- }
-
- const glm::mat4 &Camera::viewMatrix()
- {
- return mViewMatrix;
- }
-
- } // namespace util
- } // namespace svl
-
|