summaryrefslogtreecommitdiff
path: root/gfx/gl
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/camera.cpp7
-rw-r--r--gfx/gl/camera.h20
2 files changed, 23 insertions, 4 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index fadbfd7..69cfe35 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -25,3 +25,10 @@ Camera::updateView()
viewProjection = projection * view;
inverseViewProjection = glm::inverse(viewProjection);
}
+
+glm::vec3
+Camera::upFromForward(const glm::vec3 & forward)
+{
+ const auto right = glm::cross(forward, ::down);
+ return glm::cross(forward, right);
+}
diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h
index 3182969..2d937a0 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -24,18 +24,28 @@ public:
void
setForward(const glm::vec3 & f)
{
- forward = f;
- updateView();
+ setForward(f, upFromForward(f));
}
void
- setView(const glm::vec3 & p, const glm::vec3 & f, const glm::vec3 & u = ::up)
+ setForward(const glm::vec3 & f, const glm::vec3 & u)
{
- position = p;
forward = f;
up = u;
updateView();
}
void
+ setView(const glm::vec3 & p, const glm::vec3 & f)
+ {
+ position = p;
+ setForward(f);
+ }
+ void
+ setView(const glm::vec3 & p, const glm::vec3 & f, const glm::vec3 & u)
+ {
+ position = p;
+ setView(f, u);
+ }
+ void
lookAt(const glm::vec3 & target)
{
setForward(glm::normalize(target - position));
@@ -51,6 +61,8 @@ public:
return position;
}
+ static glm::vec3 upFromForward(const glm::vec3 & forward);
+
private:
void updateView();