Skip to content

Commit

Permalink
Added rotation to CoordinateFrame.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Nov 23, 2024
1 parent aba69e1 commit a3ed880
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/vsg/nodes/CoordinateFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace vsg

std::string name;
dvec3 origin;
dquat rotation;

dmat4 transform(const dmat4& mv) const override;

Expand Down
2 changes: 1 addition & 1 deletion src/vsg/app/RecordTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ void RecordTraversal::apply(const CoordinateFrame& cf)

if (viewMatrix)
{
_state->modelviewMatrixStack.push(viewMatrix->transform(cf.origin));
_state->modelviewMatrixStack.push(viewMatrix->transform(cf.origin) * vsg::rotate(cf.rotation));
}
else
{
Expand Down
10 changes: 7 additions & 3 deletions src/vsg/nodes/CoordinateFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ CoordinateFrame::CoordinateFrame()
CoordinateFrame::CoordinateFrame(const CoordinateFrame& rhs, const CopyOp& copyop) :
Inherit(rhs, copyop),
name(rhs.name),
origin(rhs.origin)
origin(rhs.origin),
rotation(rhs.rotation)
{
}

Expand All @@ -35,14 +36,16 @@ int CoordinateFrame::compare(const Object& rhs_object) const

const auto& rhs = static_cast<decltype(*this)>(rhs_object);
if ((result = compare_value(name, rhs.name)) != 0) return result;
return compare_value(origin, rhs.origin);
if ((result = compare_value(origin, rhs.origin)) != 0) return result;
return compare_value(rotation, rhs.rotation);
}

void CoordinateFrame::read(Input& input)
{
Node::read(input);
input.read("name", name);
input.read("origin", origin);
input.read("rotation", rotation);
input.read("subgraphRequiresLocalFrustum", subgraphRequiresLocalFrustum);
input.readObjects("children", children);
}
Expand All @@ -52,11 +55,12 @@ void CoordinateFrame::write(Output& output) const
Node::write(output);
output.write("name", name);
output.write("origin", origin);
output.write("rotation", rotation);
output.write("subgraphRequiresLocalFrustum", subgraphRequiresLocalFrustum);
output.writeObjects("children", children);
}

dmat4 CoordinateFrame::transform(const dmat4& mv) const
{
return mv * translate(dvec3(origin));
return mv * translate(dvec3(origin)) * rotate(rotation);
}

0 comments on commit a3ed880

Please sign in to comment.