Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add glowutils::Camera::projectionOffset #1

Open
wants to merge 2 commits into
base: voxellancer
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 16 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,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;
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()

}

const ivec2 & Camera::viewport() const
{
return m_viewport;
Expand Down Expand Up @@ -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));

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

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

return m_viewProjection.value();
}

Expand Down