Skip to content

Commit

Permalink
SCENEGRAPH: allow to access a dirty local transform matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerhardy committed Jan 13, 2025
1 parent f36020e commit 6c72aaa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/modules/scenegraph/CoordinateSystemUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include "CoordinateSystemUtil.h"
#include "core/GLMConst.h"
#include "scenegraph/CoordinateSystem.h"
#include "SceneGraph.h"
#include "scenegraph/SceneGraph.h"
#include "scenegraph/SceneGraphTransform.h"

namespace scenegraph {

Expand Down Expand Up @@ -148,4 +149,10 @@ bool convertCoordinateSystem(CoordinateSystem from, CoordinateSystem to, scenegr
return true;
}

SceneGraphTransform convertCoordinateSystem(CoordinateSystem from, const SceneGraphTransform &fromTransform) {
SceneGraphTransform transform;
transform.setLocalMatrix(convertCoordinateSystem(from, fromTransform.calculateLocalMatrix()));
return transform;
}

} // namespace scenegraph
9 changes: 9 additions & 0 deletions src/modules/scenegraph/CoordinateSystemUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace scenegraph {

class SceneGraph;
class SceneGraphTransform;

bool coordinateSystemToMatrix(CoordinateSystem sys, glm::mat4 &matrix);

Expand Down Expand Up @@ -49,4 +50,12 @@ inline glm::mat4 convertCoordinateSystem(CoordinateSystem from, const glm::mat4
return convertCoordinateSystem(from, CoordinateSystem::Vengi, fromMatrix);
}

/**
* @param[in] from This specifies the coordinate system of the format and is used to perform the transform
* into the coordinate system of vengi (x right, y up, z back) @c FormatCoordinateSystem::Vengi
* @param[in] fromMatrix The matrix to convert to the target coordinate system
* @note This does not update the volume coordinates, only the node transforms.
*/
SceneGraphTransform convertCoordinateSystem(CoordinateSystem from, const SceneGraphTransform &fromTransform);

} // namespace scenegraph
4 changes: 4 additions & 0 deletions src/modules/scenegraph/SceneGraphTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ const glm::vec3 &SceneGraphTransform::worldScale() const {
return _worldScale;
}

const glm::mat4x4 SceneGraphTransform::calculateLocalMatrix() const {
return glm::translate(_localTranslation) * glm::mat4_cast(_localOrientation) * glm::scale(glm::vec3(_localScale));
}

void SceneGraphTransform::update(const SceneGraph &sceneGraph, SceneGraphNode &node, FrameIndex frameIdx,
bool updateChildren) {
if (_dirty == 0u) {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/scenegraph/SceneGraphTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class alignas(16) SceneGraphTransform {
const glm::quat &localOrientation() const;
const glm::vec3 &localScale() const;

const glm::mat4x4 calculateLocalMatrix() const;

void update(const SceneGraph &sceneGraph, SceneGraphNode &node, FrameIndex frameIdx, bool updateChildren);

bool validate() const;
Expand Down

0 comments on commit 6c72aaa

Please sign in to comment.