Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #236 from TeamWisp/feature_rotation_quat
Browse files Browse the repository at this point in the history
Added ability to set quaternion directly
  • Loading branch information
LaisoEmilio committed Apr 4, 2019
2 parents 1242b73 + a873e71 commit 3790979
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/scene_graph/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace wr
Node::Node()
{
SignalTransformChange();
m_used_quaternion = false;
}

void Node::SignalChange()
Expand Down Expand Up @@ -49,6 +50,13 @@ namespace wr
SignalTransformChange();
}

void Node::SetQuaternionRotation( float x, float y, float z, float w )
{
m_rotation = { x,y,z,w };
m_used_quaternion = true;
SignalTransformChange();
}

void Node::SetPosition(DirectX::XMVECTOR position)
{
m_position = position;
Expand All @@ -70,7 +78,14 @@ namespace wr

void Node::UpdateTransform()
{
m_rotation = DirectX::XMQuaternionRotationRollPitchYawFromVector(m_rotation_radians);
if( m_used_quaternion )
{
m_used_quaternion == false; // reset
}
else
{
m_rotation = DirectX::XMQuaternionRotationRollPitchYawFromVector(m_rotation_radians);
}
DirectX::XMMATRIX translation_mat = DirectX::XMMatrixTranslationFromVector(m_position);
DirectX::XMMATRIX rotation_mat = DirectX::XMMatrixRotationQuaternion(m_rotation);
DirectX::XMMATRIX scale_mat = DirectX::XMMatrixScalingFromVector(m_scale);
Expand Down
5 changes: 4 additions & 1 deletion src/scene_graph/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace wr
//Takes roll, pitch and yaw and converts it to quaternion
virtual void SetRotation(DirectX::XMVECTOR roll_pitch_yaw);

//Takes raw values of a quaternion
virtual void SetQuaternionRotation( float x, float y, float z, float w );

//Sets position
virtual void SetPosition(DirectX::XMVECTOR position);

Expand Down Expand Up @@ -56,6 +59,6 @@ namespace wr

std::bitset<3> m_requires_update;
std::bitset<3> m_requires_transform_update;

bool m_used_quaternion;
};
} // namespace wr

0 comments on commit 3790979

Please sign in to comment.