From ada904a413214d242ab586ba634bc5ed6590ccef Mon Sep 17 00:00:00 2001 From: Robert Chisholm Date: Sat, 19 Oct 2024 17:38:36 +0100 Subject: [PATCH] Add support for an initial camera roll angle --- include/flamegpu/visualiser/config/ModelConfig.h | 4 ++++ src/flamegpu/visualiser/Visualiser.cpp | 2 +- src/flamegpu/visualiser/camera/NoClipCamera.cpp | 5 ++--- src/flamegpu/visualiser/camera/NoClipCamera.h | 3 ++- src/flamegpu/visualiser/config/ModelConfig.cpp | 2 ++ 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/flamegpu/visualiser/config/ModelConfig.h b/include/flamegpu/visualiser/config/ModelConfig.h index 7446bae..d273ce3 100644 --- a/include/flamegpu/visualiser/config/ModelConfig.h +++ b/include/flamegpu/visualiser/config/ModelConfig.h @@ -90,6 +90,10 @@ struct ModelConfig { * @note Defaults to (0,0,0) */ float cameraTarget[3]; + /** + * The initial camera roll angle in radians + */ + float cameraRoll; /** * The movement speed of the camera in units per millisecond, and the shift key multiplier * When shift is pressed the movement speed is multiplied by this value diff --git a/src/flamegpu/visualiser/Visualiser.cpp b/src/flamegpu/visualiser/Visualiser.cpp index 74e6678..016e520 100644 --- a/src/flamegpu/visualiser/Visualiser.cpp +++ b/src/flamegpu/visualiser/Visualiser.cpp @@ -125,7 +125,7 @@ void addLine(std::shared_ptr &lines, const std::shared_ptr &li } Visualiser::Visualiser(const ModelConfig& modelcfg) : hud(std::make_shared(modelcfg.windowDimensions[0], modelcfg.windowDimensions[1])) - , camera(std::make_shared(*reinterpret_cast(&modelcfg.cameraLocation[0]), *reinterpret_cast(&modelcfg.cameraTarget[0]))) + , camera(std::make_shared(*reinterpret_cast(&modelcfg.cameraLocation[0]), *reinterpret_cast(&modelcfg.cameraTarget[0]), modelcfg.cameraRoll)) , isInitialised(false) , continueRender(false) , buffersAllocated(false) diff --git a/src/flamegpu/visualiser/camera/NoClipCamera.cpp b/src/flamegpu/visualiser/camera/NoClipCamera.cpp index 7fc227a..7cde22d 100644 --- a/src/flamegpu/visualiser/camera/NoClipCamera.cpp +++ b/src/flamegpu/visualiser/camera/NoClipCamera.cpp @@ -16,7 +16,7 @@ NoClipCamera::NoClipCamera(const glm::vec3 &eye) : NoClipCamera(eye, glm::vec3(0, 0, 0)) {} // Initialiser list written to remove any references to member variables // Because member variables are initialised via initaliser lists in the order they are declared in the class declaration (rather than the order of the initialiser list) -NoClipCamera::NoClipCamera(const glm::vec3 &eye, const glm::vec3 &target) +NoClipCamera::NoClipCamera(const glm::vec3 &eye, const glm::vec3 &target, const float _roll) : Camera(eye) , pureUp(0.0f, 1.0f, 0.0f) , look(normalize(target - eye)) @@ -27,8 +27,7 @@ NoClipCamera::NoClipCamera(const glm::vec3 &eye, const glm::vec3 &target) // this->look = target - eye; // Look is the direction from eye to target // this->right = cross(look, pureUp); // Right is perpendicular to look and pureUp // this->up = cross(right, look); // Up is perpendicular to right and look - - this->updateViews(); + this->roll(_roll); } NoClipCamera::~NoClipCamera() { } diff --git a/src/flamegpu/visualiser/camera/NoClipCamera.h b/src/flamegpu/visualiser/camera/NoClipCamera.h index e2b540f..515215e 100644 --- a/src/flamegpu/visualiser/camera/NoClipCamera.h +++ b/src/flamegpu/visualiser/camera/NoClipCamera.h @@ -22,8 +22,9 @@ class NoClipCamera : public Camera { * Initialises the camera located at eye directed at target * @param eye The coordinates the camera is located * @param target The coordinates the camera is directed towards + * @param _roll The camera roll in radians */ - NoClipCamera(const glm::vec3 &eye, const glm::vec3 &target); + NoClipCamera(const glm::vec3 &eye, const glm::vec3 &target, float _roll = 0); /** * Default destructor */ diff --git a/src/flamegpu/visualiser/config/ModelConfig.cpp b/src/flamegpu/visualiser/config/ModelConfig.cpp index 78800b3..a28d5c2 100644 --- a/src/flamegpu/visualiser/config/ModelConfig.cpp +++ b/src/flamegpu/visualiser/config/ModelConfig.cpp @@ -19,6 +19,7 @@ ModelConfig::ModelConfig(const char* _windowTitle) , fpsColor{1, 1, 1} , cameraLocation{1.5f, 1.5f, 1.5f} , cameraTarget{0, 0, 0} + , cameraRoll(0) , cameraSpeed{0.05f, 5} , nearFarClip{0.05f, 5000} , stepVisible(true) @@ -39,6 +40,7 @@ ModelConfig &ModelConfig::operator=(const ModelConfig &other) { memcpy(fpsColor, other.fpsColor, sizeof(fpsColor)); memcpy(cameraLocation, other.cameraLocation, sizeof(cameraLocation)); memcpy(cameraTarget, other.cameraTarget, sizeof(cameraTarget)); + cameraRoll = other.cameraRoll; memcpy(cameraSpeed, other.cameraSpeed, sizeof(cameraSpeed)); memcpy(nearFarClip, other.nearFarClip, sizeof(nearFarClip)); stepVisible = other.stepVisible;