Skip to content

Commit

Permalink
Add support for an initial camera roll angle
Browse files Browse the repository at this point in the history
  • Loading branch information
Robadob committed Oct 19, 2024
1 parent 564f44e commit ada904a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions include/flamegpu/visualiser/config/ModelConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/flamegpu/visualiser/Visualiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void addLine(std::shared_ptr<Draw> &lines, const std::shared_ptr<LineConfig> &li
}
Visualiser::Visualiser(const ModelConfig& modelcfg)
: hud(std::make_shared<HUD>(modelcfg.windowDimensions[0], modelcfg.windowDimensions[1]))
, camera(std::make_shared<NoClipCamera>(*reinterpret_cast<const glm::vec3*>(&modelcfg.cameraLocation[0]), *reinterpret_cast<const glm::vec3*>(&modelcfg.cameraTarget[0])))
, camera(std::make_shared<NoClipCamera>(*reinterpret_cast<const glm::vec3*>(&modelcfg.cameraLocation[0]), *reinterpret_cast<const glm::vec3*>(&modelcfg.cameraTarget[0]), modelcfg.cameraRoll))
, isInitialised(false)
, continueRender(false)
, buffersAllocated(false)
Expand Down
5 changes: 2 additions & 3 deletions src/flamegpu/visualiser/camera/NoClipCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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() {
}
Expand Down
3 changes: 2 additions & 1 deletion src/flamegpu/visualiser/camera/NoClipCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions src/flamegpu/visualiser/config/ModelConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit ada904a

Please sign in to comment.