Skip to content

Commit

Permalink
SCENEGRAPH: added a rotate helper to the node and allow world transla…
Browse files Browse the repository at this point in the history
…tion, too
  • Loading branch information
mgerhardy committed Aug 20, 2024
1 parent 8ed08ea commit f9bd26e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
27 changes: 21 additions & 6 deletions src/modules/scenegraph/SceneGraphNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/modules/scenegraph/SceneGraphNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f9bd26e

Please sign in to comment.