From 23c948380c10cbf740e930a89f40338cc2291b8f Mon Sep 17 00:00:00 2001 From: mrzzzrm Date: Sat, 19 Apr 2014 00:42:13 +0200 Subject: [PATCH 1/2] Add glowutils::Camera::projectionOffset --- source/glowutils/include/glowutils/Camera.h | 15 ++++++++++----- source/glowutils/source/Camera.cpp | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/source/glowutils/include/glowutils/Camera.h b/source/glowutils/include/glowutils/Camera.h index a8d86dcb..389086ec 100644 --- a/source/glowutils/include/glowutils/Camera.h +++ b/source/glowutils/include/glowutils/Camera.h @@ -10,12 +10,12 @@ namespace glowutils /** \brief Represents matrices for a typical 3d look at camera with perspective. - A camera is specified via near, far, fovy, as well as an eye, a center, and an up + A camera is specified via near, far, fovy, as well as an eye, a center, and an up vector. Furthermore the viewport should be specified. Camera itself does not use - any OpenGL calls, but merely provides lazzy math to all common matrices required - for affine transformation of a scene, namely the view and projection matrices, their + any OpenGL calls, but merely provides lazy math to all common matrices required + for affine transformation of a scene, namely the view and projection matrices, their combination and all related inverses (as well as a normal matrix). - The class relies on lazzy computation of all matrices, causing less recomputations + The class relies on lazy computation of all matrices, causing less recomputations of, e.g., matrices and inverse matrices requested on an irregular basis. */ class GLOWUTILS_API Camera @@ -23,7 +23,7 @@ class GLOWUTILS_API Camera public: Camera( const glm::vec3 & eye = glm::vec3(0.0, 0.0, 1.0) - , const glm::vec3 & center = glm::vec3(0.0, 0.0, 0.0) + , const glm::vec3 & center = glm::vec3(0.0, 0.0, 0.0) , const glm::vec3 & up = glm::vec3(0.0, 1.0, 0.0)); virtual ~Camera(); @@ -43,6 +43,9 @@ class GLOWUTILS_API Camera float fovy() const; void setFovy(float fovy); + const glm::vec3 & projectionOffset() const; + void setProjectionOffset(const glm::vec3 & projectionCenterOffset); + const glm::ivec2 & viewport() const; void setViewport(const glm::ivec2 & viewport); void setViewport(int width, int height); @@ -80,6 +83,8 @@ class GLOWUTILS_API Camera float m_zNear; float m_zFar; + glm::vec3 m_projectionOffset; + glm::ivec2 m_viewport; CachedValue m_view; diff --git a/source/glowutils/source/Camera.cpp b/source/glowutils/source/Camera.cpp index 9cf0a7d6..a3a42d17 100644 --- a/source/glowutils/source/Camera.cpp +++ b/source/glowutils/source/Camera.cpp @@ -5,6 +5,9 @@ #include #include +#include + + using namespace glm; namespace glowutils @@ -140,6 +143,16 @@ void Camera::setFovy(const float fovy) dirty(); } +const glm::vec3 & Camera::projectionOffset() const +{ + return m_projectionOffset; +} + +void Camera::setProjectionOffset(const glm::vec3 & projectionOffset) +{ + m_projectionOffset = projectionOffset; +} + const ivec2 & Camera::viewport() const { return m_viewport; @@ -182,7 +195,7 @@ const mat4 & Camera::view() const { if (m_dirty) update(); - + if (!m_view.isValid()) m_view.setValue(lookAt(m_eye, m_center, m_up)); @@ -195,7 +208,7 @@ const mat4 & Camera::projection() const update(); if (!m_projection.isValid()) - m_projection.setValue(perspective(m_fovy, m_aspect, m_zNear, m_zFar)); + m_projection.setValue(glm::translate(m_projectionOffset) * perspective(m_fovy, m_aspect, m_zNear, m_zFar)); return m_projection.value(); } @@ -207,7 +220,7 @@ const mat4 & Camera::viewProjection() const if (!m_viewProjection.isValid()) m_viewProjection.setValue(projection() * view()); - + return m_viewProjection.value(); } From c3615879af0f317d2b8ec8b3ae2474a233c3c965 Mon Sep 17 00:00:00 2001 From: mrzzzrm Date: Sun, 27 Apr 2014 20:58:09 +0200 Subject: [PATCH 2/2] Make Camera::setProjectionOffset() call dirty() --- source/glowutils/source/Camera.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/glowutils/source/Camera.cpp b/source/glowutils/source/Camera.cpp index a3a42d17..ea5111b0 100644 --- a/source/glowutils/source/Camera.cpp +++ b/source/glowutils/source/Camera.cpp @@ -151,6 +151,8 @@ const glm::vec3 & Camera::projectionOffset() const void Camera::setProjectionOffset(const glm::vec3 & projectionOffset) { m_projectionOffset = projectionOffset; + + dirty(); } const ivec2 & Camera::viewport() const