diff --git a/src/modules/scenegraph/SceneGraphNode.cpp b/src/modules/scenegraph/SceneGraphNode.cpp index 8b1851c08..6265ceb6c 100644 --- a/src/modules/scenegraph/SceneGraphNode.cpp +++ b/src/modules/scenegraph/SceneGraphNode.cpp @@ -218,16 +218,31 @@ glm::vec3 SceneGraphNode::worldPivot() const { return r.getLowerCornerf() + _pivot * glm::vec3(r.getDimensionsInVoxels()); } -/** - * @brief Apply the given @c translation vector to all keyframe transform of this node - */ -void SceneGraphNode::translate(const glm::vec3 &translation) { +void SceneGraphNode::translate(const glm::vec3 &translation, bool world) { Log::debug("Translate the node by %f %f %f", translation.x, translation.y, translation.z); for (auto *keyFrames : _keyFramesMap) { for (SceneGraphKeyFrame &keyFrame : keyFrames->value) { SceneGraphTransform &transform = keyFrame.transform(); - const glm::vec3 &t = transform.localTranslation() + glm::conjugate(transform.localOrientation()) * translation; - transform.setLocalTranslation(t); + if (world) { + const glm::vec3 &t = transform.worldTranslation() + glm::conjugate(transform.worldOrientation()) * translation; + transform.setWorldTranslation(t); + } else { + const glm::vec3 &t = transform.localTranslation() + glm::conjugate(transform.localOrientation()) * translation; + transform.setLocalTranslation(t); + } + } + } +} + +void SceneGraphNode::rotate(const glm::quat &rotation, bool world) { + for (auto *keyFrames : _keyFramesMap) { + for (SceneGraphKeyFrame &keyFrame : keyFrames->value) { + SceneGraphTransform &transform = keyFrame.transform(); + if (world) { + transform.setWorldOrientation(glm::normalize(transform.worldOrientation() * rotation)); + } else { + transform.setLocalOrientation(glm::normalize(transform.localOrientation() * rotation)); + } } } } diff --git a/src/modules/scenegraph/SceneGraphNode.h b/src/modules/scenegraph/SceneGraphNode.h index 9da2b0827..c89166ae6 100644 --- a/src/modules/scenegraph/SceneGraphNode.h +++ b/src/modules/scenegraph/SceneGraphNode.h @@ -144,7 +144,8 @@ class SceneGraphNode { /** * @brief Apply the given @c translation vector to all keyframe transform of this node */ - void translate(const glm::vec3 &translation); + void translate(const glm::vec3 &translation, bool world = false); + void rotate(const glm::quat &rotation, bool world = false); SceneGraphNodeType type() const;