diff --git a/lib/glow b/lib/glow index 7581ec99..c3615879 160000 --- a/lib/glow +++ b/lib/glow @@ -1 +1 @@ -Subproject commit 7581ec99b718e481fcdb7af122ce6b5b34a1868f +Subproject commit c3615879af0f317d2b8ec8b3ae2474a233c3c965 diff --git a/src/camera/camera.cpp b/src/camera/camera.cpp index c60ac19a..65e0971b 100644 --- a/src/camera/camera.cpp +++ b/src/camera/camera.cpp @@ -1,153 +1,41 @@ #include "camera.h" +#include + +#include +#include #include Camera::Camera(int viewportWidth, int viewportHeight): - m_fovy(glm::radians(60.f)), - m_aspect(1.f), - m_zNear(1), - m_zFar(9999) + m_orientationDirty(true) { - setViewport(glm::ivec2(viewportWidth, viewportHeight)); -} - -Camera::~Camera(){ - -} - -void Camera::viewDirty() { - m_view = glm::mat4_cast(glm::inverse(m_orientation)) * glm::translate(-m_position); - m_viewProjection = m_projection * m_view; -} - -void Camera::projectionDirty() { - m_projection = glm::perspective(m_fovy, m_aspect, m_zNear, m_zFar); - m_projection = glm::translate(m_projectionOffset) * m_projection; - m_viewProjection = m_projection * m_view; -} - -void Camera::move(glm::vec3 dist){ - Transform::move(dist); - viewDirty(); -} - -void Camera::setPosition(glm::vec3 pos){ - Transform::setPosition(pos); - viewDirty(); -} - -void Camera::rotateX(float rot){ - Transform::rotate(glm::angleAxis(rot, glm::vec3(1,0,0))); - viewDirty(); -} - -void Camera::rotateY(float rot){ - Transform::rotate(glm::angleAxis(rot, glm::vec3(0, 1, 0))); - viewDirty(); -} - -void Camera::rotateZ(float rot){ - Transform::rotate(glm::angleAxis(rot, glm::vec3(0, 0, -1))); - viewDirty(); -} - -void Camera::setOrientation(glm::quat quat){ - Transform::setOrientation(quat); - viewDirty(); -} - -const glm::mat4& Camera::view() const{ - return m_view; -} - -const glm::mat4& Camera::viewInverted() const { - return glm::inverse(m_view); -} - -const glm::quat& Camera::orientation() const { - return Transform::orientation(); -} - -const glm::vec3& Camera::position() const { - return m_position; -} - -float Camera::zNear() const { - return m_zNear; -} - -void Camera::setZNear(const float zNear) { - if (zNear == m_zNear) { - return; - } - - m_zNear = zNear; - assert(m_zNear > 0.0); - - projectionDirty(); -} - -float Camera::zFar() const { - return m_zFar; -} - -void Camera::setZFar(const float zFar) { - if (zFar == m_zFar) { - return; - } + setViewport(viewportWidth, viewportHeight); - m_zFar = zFar; - assert(m_zFar > m_zNear); - projectionDirty(); -} + setFovy(glm::radians(60.0f)); -float Camera::fovy() const { - return m_fovy; + setZNear(1.0f); + setZFar(10000.0f); } -void Camera::setFovy(const float fovy) { - if (fovy == m_fovy) { - return; +glm::quat Camera::orientation() const { + if (m_orientationDirty) { + const_cast(m_orientation) = glm::quat_cast(glm::inverse(view())); + m_orientationDirty = false; } - - m_fovy = fovy; - assert(m_fovy > 0.0); - projectionDirty(); + return m_orientation; } -const glm::ivec2 Camera::viewport() const { - return m_viewport; -} +void Camera::setOrientation(const glm::quat& orientation) { + glowutils::Camera::setUp(orientation * glm::vec3(0, 1, 0)); + glowutils::Camera::setCenter(eye() + orientation * glm::vec3(0, 0, -1)); -void Camera::setViewport(const glm::ivec2& viewport) { - if (viewport == m_viewport) { - return; - } - - m_aspect = viewport.x / glm::max(static_cast(viewport.y), 1.f); - m_viewport = viewport; - projectionDirty(); + // changed() will be called anyway, no need to set m_orientationDirty = true } -const glm::vec3& Camera::projectionOffset() const { - return m_projectionOffset; +void Camera::changed() const { + glowutils::Camera::changed(); + m_orientationDirty = true; } -void Camera::setProjectionOffset(const glm::vec3& projectionOffset) { - m_projectionOffset = projectionOffset; - projectionDirty(); -} - -float Camera::aspectRatio() const { - return m_aspect; -} - -const glm::mat4& Camera::projection() const { - return m_projection; -} - -const glm::mat4& Camera::viewProjection() const { - return m_viewProjection; -} diff --git a/src/camera/camera.h b/src/camera/camera.h index 637c9d65..bccee15f 100644 --- a/src/camera/camera.h +++ b/src/camera/camera.h @@ -1,72 +1,24 @@ #pragma once +#include + #include #include "geometry/transform.h" -/** - * Represents the camera. matrix thus is the view matrix for all other objects - */ -class Camera : protected Transform { //protected so we don't have matrix, because we want view + +class Camera : public glowutils::Camera { public: Camera(int viewportWidth, int viewportHeight); - virtual ~Camera(); - - /* Overwrite WorldObject functions for performance: - * WorldObject recalculates the matrix on every read access, - * Camera should recalculate on every write access, as reads are more common */ - - void move(glm::vec3 dist); - void setPosition(glm::vec3 pos); - - void rotateX(float rot); - void rotateY(float rot); - void rotateZ(float rot); - void setOrientation(glm::quat quat); - - const glm::mat4& view() const; - const glm::mat4& viewInverted() const; - const glm::quat& orientation() const; - const glm::vec3& position() const; - - /* Projection from glow::Camera */ - - float zNear() const; - void setZNear(float zNear); - float zFar() const; - void setZFar(float zFar); - float fovy() const; - void setFovy(float fovy); + glm::quat orientation() const; + void setOrientation(const glm::quat& orientation); - const glm::ivec2 viewport() const; - void setViewport(const glm::ivec2 & viewport); - - const glm::vec3& projectionOffset() const; - void setProjectionOffset(const glm::vec3& projectionOffset); - - float aspectRatio() const; - - const glm::mat4& projection() const; - - const glm::mat4& viewProjection() const; + void changed() const override; protected: - void viewDirty(); - void projectionDirty(); - - float m_fovy; - float m_aspect; - float m_zNear; - float m_zFar; - - glm::ivec2 m_viewport; - - glm::vec3 m_projectionOffset; - - glm::mat4 m_view; - glm::mat4 m_projection; - glm::mat4 m_viewProjection; + mutable bool m_orientationDirty; + glm::quat m_orientation; }; diff --git a/src/display/monoview.cpp b/src/display/monoview.cpp index 0594341d..8a40fe41 100644 --- a/src/display/monoview.cpp +++ b/src/display/monoview.cpp @@ -52,7 +52,7 @@ void MonoView::draw(const Scene& scene, const CameraHead& cameraHead) { glViewport(m_viewport.x(), m_viewport.y(), sampleWidth, sampleHeight); m_camera->setViewport(glm::ivec2(sampleWidth, sampleHeight)); - m_camera->setPosition(cameraHead.position()); + m_camera->setEye(cameraHead.position()); m_camera->setOrientation(cameraHead.orientation()); scene.draw(*m_camera, glow::FrameBufferObject::defaultFBO(), m_viewport); diff --git a/src/display/rendering/skybox.cpp b/src/display/rendering/skybox.cpp index b4a93dc0..2f3b528a 100644 --- a/src/display/rendering/skybox.cpp +++ b/src/display/rendering/skybox.cpp @@ -55,7 +55,7 @@ void Skybox::initialize() { glm::vec3(-1, -1, 0), glm::vec3(1, -1, 0), glm::vec3(1, 1, 0), - glm::vec3(-1, 1, 0) + glm::vec3(-1, 1, 0) }; m_vertexArrayObject = new glow::VertexArrayObject(); diff --git a/src/display/rendering/starfield.cpp b/src/display/rendering/starfield.cpp index 3669f7d8..3fecc182 100644 --- a/src/display/rendering/starfield.cpp +++ b/src/display/rendering/starfield.cpp @@ -143,7 +143,7 @@ void Starfield::createBinding(int index, std::string name, int offset, int size) } void Starfield::addLocation(const Camera& camera, int side) { - CameraLocation location = CameraLocation{ m_time, camera.position(), camera.orientation() }; + CameraLocation location = CameraLocation{ m_time, camera.eye(), camera.orientation() }; m_locations[side].push_back(location); } @@ -172,7 +172,7 @@ glm::mat4 Starfield::getMatrixFromPast(const Camera& camera, int side) { assert(interpolation >= 0 && interpolation <= 1); Camera c(camera); - c.setPosition(glm::mix(after.position, before.position, interpolation)); + c.setEye(glm::mix(after.position, before.position, interpolation)); c.setOrientation(glm::slerp(after.orientation, before.orientation, interpolation)); return c.viewProjection(); diff --git a/src/display/stereovieweye.cpp b/src/display/stereovieweye.cpp index 21eb2700..5a36008a 100644 --- a/src/display/stereovieweye.cpp +++ b/src/display/stereovieweye.cpp @@ -20,7 +20,7 @@ StereoViewEye::StereoViewEye(const glm::ivec2& viewportResolution, const StereoR m_camera(new Camera(viewportResolution.x, viewportResolution.y)), m_distortionScale(stereoRenderInfo.distortionScale()), m_fbo(new FrameBuffer()), - m_antialiasing("vfx.antialiasing") + m_antialiasing("vfx.antialiasing") { setViewportResolution(viewportResolution); @@ -35,18 +35,16 @@ StereoViewEye::StereoViewEye(const glm::ivec2& viewportResolution, const StereoR } } +StereoViewEye::~StereoViewEye() = default; + const Camera& StereoViewEye::camera() const { return *m_camera; } -StereoViewEye::~StereoViewEye() = default; - FrameBuffer& StereoViewEye::fbo() { return *m_fbo; } - - void StereoViewEye::draw(const Scene& scene, const CameraHead& cameraHead) { int samplingFactor = 1; if (m_antialiasing.get() == Antialiasing::SSAA) { @@ -56,7 +54,7 @@ void StereoViewEye::draw(const Scene& scene, const CameraHead& cameraHead) { int sampleHeight = static_cast(m_textureSize.y * samplingFactor); m_camera->setViewport(glm::ivec2(sampleWidth, sampleHeight)); - m_camera->setPosition(cameraHead.position() + cameraHead.orientation() * m_offset); + m_camera->setEye(cameraHead.position() + cameraHead.orientation() * m_offset); m_camera->setOrientation(cameraHead.orientation()); m_fbo->bind(); @@ -76,3 +74,4 @@ void StereoViewEye::setViewportResolution(const glm::ivec2& viewportResolution) m_fbo->setResolution(m_textureSize); } + diff --git a/src/display/stereovieweye.h b/src/display/stereovieweye.h index cb209f3f..e3f0096b 100644 --- a/src/display/stereovieweye.h +++ b/src/display/stereovieweye.h @@ -8,6 +8,7 @@ #include "eyeside.h" #include "property/property.h" + namespace glow { class FrameBufferObject; } diff --git a/src/main.cpp b/src/main.cpp index 1dd069a3..0c8df30b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -243,6 +243,7 @@ int main(int argc, char* argv[]) { game->viewer().switchToStereoView(StereoRenderInfo::dummy()); } } + game->gamePlay().updateView(); delete loadingScreen; delete initTimer; diff --git a/src/utils/inertiafollower.h b/src/utils/inertiafollower.h index 211b3905..c9819560 100644 --- a/src/utils/inertiafollower.h +++ b/src/utils/inertiafollower.h @@ -7,7 +7,6 @@ * Follows a position and orientation with a given inertia between * 0 = instant follow and 100 = never moves */ - class InertiaFollower { public: InertiaFollower(float directionalInertia, float angularInertia);