Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions source/glowutils/include/glowutils/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ 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
{
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();
Expand All @@ -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);
Expand Down Expand Up @@ -80,6 +83,8 @@ class GLOWUTILS_API Camera
float m_zNear;
float m_zFar;

glm::vec3 m_projectionOffset;

glm::ivec2 m_viewport;

CachedValue<glm::mat4> m_view;
Expand Down
21 changes: 18 additions & 3 deletions source/glowutils/source/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_inverse.hpp>

#include <glm/gtx/transform.hpp>


using namespace glm;

namespace glowutils
Expand Down Expand Up @@ -140,6 +143,18 @@ 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably call dirty()


dirty();
}

const ivec2 & Camera::viewport() const
{
return m_viewport;
Expand Down Expand Up @@ -182,7 +197,7 @@ const mat4 & Camera::view() const
{
if (m_dirty)
update();

if (!m_view.isValid())
m_view.setValue(lookAt(m_eye, m_center, m_up));

Expand All @@ -195,7 +210,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();
}
Expand All @@ -207,7 +222,7 @@ const mat4 & Camera::viewProjection() const

if (!m_viewProjection.isValid())
m_viewProjection.setValue(projection() * view());

return m_viewProjection.value();
}

Expand Down