|
|
|
|
@@ -3,74 +3,10 @@
|
|
|
|
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
|
|
|
|
|
|
|
|
#include <Nazara/Utility/Node.hpp>
|
|
|
|
|
#include <Nazara/Core/Algorithm.hpp>
|
|
|
|
|
#include <Nazara/Utility/Algorithm.hpp>
|
|
|
|
|
#include <Nazara/Utility/Debug.hpp>
|
|
|
|
|
|
|
|
|
|
namespace Nz
|
|
|
|
|
{
|
|
|
|
|
Node::Node() :
|
|
|
|
|
m_initialRotation(Quaternionf::Identity()),
|
|
|
|
|
m_rotation(Quaternionf::Identity()),
|
|
|
|
|
m_initialPosition(Vector3f::Zero()),
|
|
|
|
|
m_initialScale(Vector3f(1.f, 1.f, 1.f)),
|
|
|
|
|
m_position(Vector3f::Zero()),
|
|
|
|
|
m_scale(Vector3f(1.f, 1.f, 1.f)),
|
|
|
|
|
m_parent(nullptr),
|
|
|
|
|
m_derivedUpdated(false),
|
|
|
|
|
m_inheritPosition(true),
|
|
|
|
|
m_inheritRotation(true),
|
|
|
|
|
m_inheritScale(true),
|
|
|
|
|
m_transformMatrixUpdated(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node::Node(const Node& node) :
|
|
|
|
|
m_initialRotation(node.m_initialRotation),
|
|
|
|
|
m_rotation(node.m_rotation),
|
|
|
|
|
m_initialPosition(node.m_initialPosition),
|
|
|
|
|
m_initialScale(node.m_initialScale),
|
|
|
|
|
m_position(node.m_position),
|
|
|
|
|
m_scale(node.m_scale),
|
|
|
|
|
m_parent(nullptr),
|
|
|
|
|
m_derivedUpdated(false),
|
|
|
|
|
m_inheritPosition(node.m_inheritPosition),
|
|
|
|
|
m_inheritRotation(node.m_inheritRotation),
|
|
|
|
|
m_inheritScale(node.m_inheritScale),
|
|
|
|
|
m_transformMatrixUpdated(false)
|
|
|
|
|
{
|
|
|
|
|
SetParent(node.m_parent, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node::Node(Node&& node) noexcept :
|
|
|
|
|
OnNodeInvalidation(std::move(node.OnNodeInvalidation)),
|
|
|
|
|
OnNodeNewParent(std::move(node.OnNodeNewParent)),
|
|
|
|
|
OnNodeRelease(std::move(node.OnNodeRelease)),
|
|
|
|
|
m_childs(std::move(node.m_childs)),
|
|
|
|
|
m_initialRotation(node.m_initialRotation),
|
|
|
|
|
m_rotation(node.m_rotation),
|
|
|
|
|
m_initialPosition(node.m_initialPosition),
|
|
|
|
|
m_initialScale(node.m_initialScale),
|
|
|
|
|
m_position(node.m_position),
|
|
|
|
|
m_scale(node.m_scale),
|
|
|
|
|
m_parent(node.m_parent),
|
|
|
|
|
m_derivedUpdated(false),
|
|
|
|
|
m_inheritPosition(node.m_inheritPosition),
|
|
|
|
|
m_inheritRotation(node.m_inheritRotation),
|
|
|
|
|
m_inheritScale(node.m_inheritScale),
|
|
|
|
|
m_transformMatrixUpdated(false)
|
|
|
|
|
{
|
|
|
|
|
if (m_parent)
|
|
|
|
|
{
|
|
|
|
|
m_parent->RemoveChild(&node);
|
|
|
|
|
m_parent->AddChild(this);
|
|
|
|
|
node.m_parent = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Node* child : m_childs)
|
|
|
|
|
child->m_parent = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node::~Node()
|
|
|
|
|
{
|
|
|
|
|
OnNodeRelease(this);
|
|
|
|
|
@@ -79,195 +15,25 @@ namespace Nz
|
|
|
|
|
{
|
|
|
|
|
// child->SetParent(nullptr); serait problématique car elle nous appellerait
|
|
|
|
|
child->m_parent = nullptr;
|
|
|
|
|
child->InvalidateNode();
|
|
|
|
|
child->InvalidateNode(Invalidation::InvalidateRecursively);
|
|
|
|
|
child->OnParenting(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetParent(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::EnsureDerivedUpdate() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::EnsureTransformMatrixUpdate() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_transformMatrixUpdated)
|
|
|
|
|
UpdateTransformMatrix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetBackward() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedRotation * Vector3f::Backward();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::vector<Node*>& Node::GetChilds() const
|
|
|
|
|
{
|
|
|
|
|
return m_childs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetDown() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedRotation * Vector3f::Down();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetForward() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedRotation * Vector3f::Forward();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Node::GetInheritPosition() const
|
|
|
|
|
{
|
|
|
|
|
return m_inheritPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Node::GetInheritRotation() const
|
|
|
|
|
{
|
|
|
|
|
return m_inheritRotation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Node::GetInheritScale() const
|
|
|
|
|
{
|
|
|
|
|
return m_inheritScale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetInitialPosition() const
|
|
|
|
|
{
|
|
|
|
|
return m_initialPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Quaternionf Node::GetInitialRotation() const
|
|
|
|
|
{
|
|
|
|
|
return m_initialRotation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetInitialScale() const
|
|
|
|
|
{
|
|
|
|
|
return m_initialScale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetLeft() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedRotation * Vector3f::Left();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NodeType Node::GetNodeType() const
|
|
|
|
|
{
|
|
|
|
|
return NodeType::Default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Node* Node::GetParent() const
|
|
|
|
|
{
|
|
|
|
|
return m_parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetPosition(CoordSys coordSys) const
|
|
|
|
|
Node& Node::Interpolate(const Node& nodeA, const Node& nodeB, float interpolation, CoordSys coordSys, Invalidation invalidation)
|
|
|
|
|
{
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
case CoordSys::Global:
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedPosition;
|
|
|
|
|
|
|
|
|
|
case CoordSys::Local:
|
|
|
|
|
return m_position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NazaraError("Coordinate system out of enum (0x" + NumberToString(UnderlyingCast(coordSys), 16) + ')');
|
|
|
|
|
return Vector3f();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetRight() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedRotation * Vector3f::Right();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Quaternionf Node::GetRotation(CoordSys coordSys) const
|
|
|
|
|
{
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
case CoordSys::Global:
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedRotation;
|
|
|
|
|
|
|
|
|
|
case CoordSys::Local:
|
|
|
|
|
return m_rotation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NazaraError("Coordinate system out of enum (0x" + NumberToString(UnderlyingCast(coordSys), 16) + ')');
|
|
|
|
|
return Quaternionf();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetScale(CoordSys coordSys) const
|
|
|
|
|
{
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
case CoordSys::Global:
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedScale;
|
|
|
|
|
|
|
|
|
|
case CoordSys::Local:
|
|
|
|
|
return m_scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NazaraError("Coordinate system out of enum (0x" + NumberToString(UnderlyingCast(coordSys), 16) + ')');
|
|
|
|
|
return Vector3f();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Matrix4f& Node::GetTransformMatrix() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_transformMatrixUpdated)
|
|
|
|
|
UpdateTransformMatrix();
|
|
|
|
|
|
|
|
|
|
return m_transformMatrix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::GetUp() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedRotation * Vector3f::Up();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Node::HasChilds() const
|
|
|
|
|
{
|
|
|
|
|
return !m_childs.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node& Node::Interpolate(const Node& nodeA, const Node& nodeB, float interpolation, CoordSys coordSys)
|
|
|
|
|
{
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
case CoordSys::Global:
|
|
|
|
|
if (!nodeA.m_derivedUpdated)
|
|
|
|
|
nodeA.UpdateDerived();
|
|
|
|
|
|
|
|
|
|
if (!nodeB.m_derivedUpdated)
|
|
|
|
|
nodeB.UpdateDerived();
|
|
|
|
|
nodeA.EnsureDerivedUpdate();
|
|
|
|
|
nodeB.EnsureDerivedUpdate();
|
|
|
|
|
|
|
|
|
|
m_position = ToLocalPosition(Vector3f::Lerp(nodeA.m_derivedPosition, nodeB.m_derivedPosition, interpolation));
|
|
|
|
|
m_rotation = ToLocalRotation(Quaternionf::Slerp(nodeA.m_derivedRotation, nodeB.m_derivedRotation, interpolation));
|
|
|
|
|
@@ -281,11 +47,12 @@ namespace Nz
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
Invalidate(invalidation);
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node& Node::Move(const Vector3f& movement, CoordSys coordSys)
|
|
|
|
|
Node& Node::Move(const Vector3f& movement, CoordSys coordSys, Invalidation invalidation)
|
|
|
|
|
{
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
@@ -293,8 +60,7 @@ namespace Nz
|
|
|
|
|
{
|
|
|
|
|
if (m_parent)
|
|
|
|
|
{
|
|
|
|
|
if (!m_parent->m_derivedUpdated)
|
|
|
|
|
m_parent->UpdateDerived();
|
|
|
|
|
m_parent->EnsureDerivedUpdate();
|
|
|
|
|
|
|
|
|
|
m_position += (m_parent->m_derivedRotation.GetConjugate()*(movement - m_parent->m_derivedPosition))/m_parent->m_derivedScale; // Compensation
|
|
|
|
|
}
|
|
|
|
|
@@ -309,146 +75,36 @@ namespace Nz
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
Invalidate(invalidation);
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node& Node::Move(float moveX, float moveY, float moveZ, CoordSys coordSys)
|
|
|
|
|
Node& Node::Rotate(const Quaternionf& rotation, CoordSys coordSys, Invalidation invalidation)
|
|
|
|
|
{
|
|
|
|
|
return Move(Vector3f(moveX, moveY, moveZ), coordSys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node& Node::Rotate(const Quaternionf& rotation, CoordSys coordSys)
|
|
|
|
|
{
|
|
|
|
|
// Évitons toute mauvaise surprise ..
|
|
|
|
|
Quaternionf q(rotation);
|
|
|
|
|
q.Normalize();
|
|
|
|
|
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
case CoordSys::Global:
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
EnsureDerivedUpdate();
|
|
|
|
|
|
|
|
|
|
m_rotation *= m_derivedRotation.GetInverse() * q * m_derivedRotation; ///FIXME: Correct ?
|
|
|
|
|
m_rotation *= m_derivedRotation.GetInverse() * rotation * m_derivedRotation; ///FIXME: Correct ?
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case CoordSys::Local:
|
|
|
|
|
m_rotation *= q;
|
|
|
|
|
m_rotation *= rotation;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_rotation.Normalize();
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
Invalidate(invalidation);
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node& Node::Scale(const Vector3f& scale)
|
|
|
|
|
{
|
|
|
|
|
m_scale *= scale;
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node& Node::Scale(float scale)
|
|
|
|
|
{
|
|
|
|
|
m_scale *= scale;
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node& Node::Scale(float scaleX, float scaleY, float scaleZ)
|
|
|
|
|
{
|
|
|
|
|
m_scale.x *= scaleX;
|
|
|
|
|
m_scale.y *= scaleY;
|
|
|
|
|
m_scale.z *= scaleZ;
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetInheritPosition(bool inheritPosition)
|
|
|
|
|
{
|
|
|
|
|
///DOC: Un appel redondant est sans effet
|
|
|
|
|
if (m_inheritPosition != inheritPosition)
|
|
|
|
|
{
|
|
|
|
|
m_inheritPosition = inheritPosition;
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetInheritRotation(bool inheritRotation)
|
|
|
|
|
{
|
|
|
|
|
///DOC: Un appel redondant est sans effet
|
|
|
|
|
if (m_inheritRotation != inheritRotation)
|
|
|
|
|
{
|
|
|
|
|
m_inheritRotation = inheritRotation;
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetInheritScale(bool inheritScale)
|
|
|
|
|
{
|
|
|
|
|
///DOC: Un appel redondant est sans effet
|
|
|
|
|
if (m_inheritScale != inheritScale)
|
|
|
|
|
{
|
|
|
|
|
m_inheritScale = inheritScale;
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetInitialPosition(const Vector3f& position)
|
|
|
|
|
{
|
|
|
|
|
m_initialPosition = position;
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetInitialPosition(float positionX, float positionY, float positionZ)
|
|
|
|
|
{
|
|
|
|
|
m_initialPosition.Set(positionX, positionY, positionZ);
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetInitialRotation(const Quaternionf& rotation)
|
|
|
|
|
{
|
|
|
|
|
m_initialRotation = rotation;
|
|
|
|
|
m_initialRotation.Normalize(); // Évitons toute mauvaise surprise ...
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetInitialScale(const Vector3f& scale)
|
|
|
|
|
{
|
|
|
|
|
m_initialScale = scale;
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetInitialScale(float scale)
|
|
|
|
|
{
|
|
|
|
|
m_initialScale.Set(scale);
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetInitialScale(float scaleX, float scaleY, float scaleZ)
|
|
|
|
|
{
|
|
|
|
|
m_initialScale.Set(scaleX, scaleY, scaleZ);
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetParent(const Node* node, bool keepDerived)
|
|
|
|
|
void Node::SetParent(const Node* node, bool keepDerived, Invalidation invalidation)
|
|
|
|
|
{
|
|
|
|
|
#if NAZARA_UTILITY_SAFE
|
|
|
|
|
// On vérifie que le node n'est pas son propre parent
|
|
|
|
|
@@ -470,8 +126,7 @@ namespace Nz
|
|
|
|
|
|
|
|
|
|
if (keepDerived)
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
EnsureDerivedUpdate();
|
|
|
|
|
|
|
|
|
|
if (m_parent)
|
|
|
|
|
m_parent->RemoveChild(this);
|
|
|
|
|
@@ -480,9 +135,11 @@ namespace Nz
|
|
|
|
|
if (m_parent)
|
|
|
|
|
m_parent->AddChild(this);
|
|
|
|
|
|
|
|
|
|
SetRotation(m_derivedRotation, CoordSys::Global);
|
|
|
|
|
SetScale(m_derivedScale, CoordSys::Global);
|
|
|
|
|
SetPosition(m_derivedPosition, CoordSys::Global);
|
|
|
|
|
SetRotation(m_derivedRotation, CoordSys::Global, Invalidation::DontInvalidate);
|
|
|
|
|
SetScale(m_derivedScale, CoordSys::Global, Invalidation::DontInvalidate);
|
|
|
|
|
SetPosition(m_derivedPosition, CoordSys::Global, Invalidation::DontInvalidate);
|
|
|
|
|
|
|
|
|
|
Invalidate(invalidation);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
@@ -493,52 +150,39 @@ namespace Nz
|
|
|
|
|
if (m_parent)
|
|
|
|
|
m_parent->AddChild(this);
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
Invalidate(invalidation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnParenting(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetParent(const Node& node, bool keepDerived)
|
|
|
|
|
{
|
|
|
|
|
SetParent(&node, keepDerived);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetPosition(const Vector3f& position, CoordSys coordSys)
|
|
|
|
|
void Node::SetPosition(const Vector3f& position, CoordSys coordSys, Invalidation invalidation)
|
|
|
|
|
{
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
case CoordSys::Global:
|
|
|
|
|
{
|
|
|
|
|
if (m_parent && m_inheritPosition)
|
|
|
|
|
{
|
|
|
|
|
if (!m_parent->m_derivedUpdated)
|
|
|
|
|
m_parent->UpdateDerived();
|
|
|
|
|
m_parent->EnsureDerivedUpdate();
|
|
|
|
|
|
|
|
|
|
m_position = (m_parent->m_derivedRotation.GetConjugate()*(position - m_parent->m_derivedPosition))/m_parent->m_derivedScale - m_initialPosition;
|
|
|
|
|
m_position = (m_parent->m_derivedRotation.GetConjugate() * (position - m_parent->m_derivedPosition)) / m_parent->m_derivedScale - m_initialPosition;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_position = position - m_initialPosition;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case CoordSys::Local:
|
|
|
|
|
m_position = position;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
Invalidate(invalidation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetPosition(float positionX, float positionY, float positionZ, CoordSys coordSys)
|
|
|
|
|
void Node::SetRotation(const Quaternionf& rotation, CoordSys coordSys, Invalidation invalidation)
|
|
|
|
|
{
|
|
|
|
|
SetPosition(Vector3f(positionX, positionY, positionZ), coordSys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetRotation(const Quaternionf& rotation, CoordSys coordSys)
|
|
|
|
|
{
|
|
|
|
|
// Évitons toute mauvaise surprise ..
|
|
|
|
|
Quaternionf q(rotation);
|
|
|
|
|
q.Normalize();
|
|
|
|
|
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
case CoordSys::Global:
|
|
|
|
|
@@ -546,28 +190,22 @@ namespace Nz
|
|
|
|
|
{
|
|
|
|
|
Quaternionf rot(m_parent->GetRotation() * m_initialRotation);
|
|
|
|
|
|
|
|
|
|
m_rotation = rot.GetConjugate() * q;
|
|
|
|
|
m_rotation = rot.GetConjugate() * rotation;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_rotation = q;
|
|
|
|
|
m_rotation = rotation;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CoordSys::Local:
|
|
|
|
|
m_rotation = q;
|
|
|
|
|
m_rotation = rotation;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
Invalidate(invalidation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetScale(const Vector2f& scale, CoordSys coordSys)
|
|
|
|
|
{
|
|
|
|
|
// Prevent Z scale at zero (can happen when using SetScale with a Vec2)
|
|
|
|
|
SetScale(scale.x, scale.y, 1.f, coordSys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetScale(const Vector3f& scale, CoordSys coordSys)
|
|
|
|
|
void Node::SetScale(const Vector3f& scale, CoordSys coordSys, Invalidation invalidation)
|
|
|
|
|
{
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
@@ -583,152 +221,64 @@ namespace Nz
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
Invalidate(invalidation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetScale(float scale, CoordSys coordSys)
|
|
|
|
|
void Node::SetTransform(const Vector3f& position, const Quaternionf& rotation, const Vector3f& scale, CoordSys coordSys, Invalidation invalidation)
|
|
|
|
|
{
|
|
|
|
|
SetScale(Vector3f(scale), coordSys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetScale(float scaleX, float scaleY, float scaleZ, CoordSys coordSys)
|
|
|
|
|
{
|
|
|
|
|
SetScale(Vector3f(scaleX, scaleY, scaleZ), coordSys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::SetTransformMatrix(const Matrix4f& matrix)
|
|
|
|
|
{
|
|
|
|
|
SetPosition(matrix.GetTranslation(), CoordSys::Global);
|
|
|
|
|
SetRotation(matrix.GetRotation(), CoordSys::Global);
|
|
|
|
|
SetScale(matrix.GetScale(), CoordSys::Global);
|
|
|
|
|
|
|
|
|
|
m_transformMatrix = matrix;
|
|
|
|
|
m_transformMatrixUpdated = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::ToGlobalPosition(const Vector3f& localPosition) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return TransformPositionTRS(m_derivedPosition, m_derivedRotation, m_derivedScale, localPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Quaternionf Node::ToGlobalRotation(const Quaternionf& localRotation) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return TransformRotationTRS(m_derivedRotation, m_derivedScale, localRotation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::ToGlobalScale(const Vector3f& localScale) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return TransformScaleTRS(m_derivedScale, localScale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::ToLocalPosition(const Vector3f& globalPosition) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedRotation.GetConjugate()*(globalPosition - m_derivedPosition)/m_derivedScale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Quaternionf Node::ToLocalRotation(const Quaternionf& globalRotation) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return m_derivedRotation.GetConjugate() * globalRotation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3f Node::ToLocalScale(const Vector3f& globalScale) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
|
|
|
|
|
return globalScale / m_derivedScale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node& Node::operator=(const Node& node)
|
|
|
|
|
{
|
|
|
|
|
SetParent(node.m_parent);
|
|
|
|
|
|
|
|
|
|
m_inheritPosition = node.m_inheritPosition;
|
|
|
|
|
m_inheritRotation = node.m_inheritRotation;
|
|
|
|
|
m_inheritScale = node.m_inheritScale;
|
|
|
|
|
m_initialPosition = node.m_initialPosition;
|
|
|
|
|
m_initialRotation = node.m_initialRotation;
|
|
|
|
|
m_initialScale = node.m_initialScale;
|
|
|
|
|
m_position = node.m_position;
|
|
|
|
|
m_rotation = node.m_rotation;
|
|
|
|
|
m_scale = node.m_scale;
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Node& Node::operator=(Node&& node) noexcept
|
|
|
|
|
{
|
|
|
|
|
if (m_parent)
|
|
|
|
|
SetParent(nullptr);
|
|
|
|
|
|
|
|
|
|
m_inheritPosition = node.m_inheritPosition;
|
|
|
|
|
m_inheritRotation = node.m_inheritRotation;
|
|
|
|
|
m_inheritScale = node.m_inheritScale;
|
|
|
|
|
m_initialPosition = node.m_initialPosition;
|
|
|
|
|
m_initialRotation = node.m_initialRotation;
|
|
|
|
|
m_initialScale = node.m_initialScale;
|
|
|
|
|
m_position = node.m_position;
|
|
|
|
|
m_rotation = node.m_rotation;
|
|
|
|
|
m_scale = node.m_scale;
|
|
|
|
|
|
|
|
|
|
m_childs = std::move(node.m_childs);
|
|
|
|
|
for (Node* child : m_childs)
|
|
|
|
|
child->m_parent = this;
|
|
|
|
|
|
|
|
|
|
m_parent = node.m_parent;
|
|
|
|
|
if (m_parent)
|
|
|
|
|
switch (coordSys)
|
|
|
|
|
{
|
|
|
|
|
m_parent->RemoveChild(&node);
|
|
|
|
|
m_parent->AddChild(this);
|
|
|
|
|
node.m_parent = nullptr;
|
|
|
|
|
case CoordSys::Global:
|
|
|
|
|
{
|
|
|
|
|
// Position
|
|
|
|
|
if (m_parent && m_inheritPosition)
|
|
|
|
|
{
|
|
|
|
|
m_parent->EnsureDerivedUpdate();
|
|
|
|
|
|
|
|
|
|
m_position = (m_parent->m_derivedRotation.GetConjugate() * (position - m_parent->m_derivedPosition)) / m_parent->m_derivedScale - m_initialPosition;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_position = position - m_initialPosition;
|
|
|
|
|
|
|
|
|
|
// Rotation
|
|
|
|
|
if (m_parent && m_inheritRotation)
|
|
|
|
|
{
|
|
|
|
|
Quaternionf rot(m_parent->GetRotation() * m_initialRotation);
|
|
|
|
|
|
|
|
|
|
m_rotation = rot.GetConjugate() * rotation;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_rotation = rotation;
|
|
|
|
|
|
|
|
|
|
// Scale
|
|
|
|
|
if (m_parent && m_inheritScale)
|
|
|
|
|
m_scale = scale / (m_initialScale * m_parent->GetScale());
|
|
|
|
|
else
|
|
|
|
|
m_scale = scale / m_initialScale;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case CoordSys::Local:
|
|
|
|
|
m_position = position;
|
|
|
|
|
m_rotation = rotation;
|
|
|
|
|
m_scale = scale;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnNodeInvalidation = std::move(node.OnNodeInvalidation);
|
|
|
|
|
OnNodeNewParent = std::move(node.OnNodeNewParent);
|
|
|
|
|
OnNodeRelease = std::move(node.OnNodeRelease);
|
|
|
|
|
|
|
|
|
|
InvalidateNode();
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
Invalidate(invalidation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::AddChild(Node* node) const
|
|
|
|
|
{
|
|
|
|
|
#ifdef NAZARA_DEBUG
|
|
|
|
|
if (std::find(m_childs.begin(), m_childs.end(), node) != m_childs.end())
|
|
|
|
|
{
|
|
|
|
|
NazaraWarning("Child node is already a child of parent node");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
m_childs.push_back(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::InvalidateNode()
|
|
|
|
|
void Node::InvalidateNode(Invalidation invalidation)
|
|
|
|
|
{
|
|
|
|
|
m_derivedUpdated = false;
|
|
|
|
|
m_transformMatrixUpdated = false;
|
|
|
|
|
|
|
|
|
|
for (Node* node : m_childs)
|
|
|
|
|
node->InvalidateNode();
|
|
|
|
|
if (invalidation == Invalidation::InvalidateRecursively)
|
|
|
|
|
{
|
|
|
|
|
for (Node* node : m_childs)
|
|
|
|
|
node->InvalidateNode(invalidation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnNodeInvalidation(this);
|
|
|
|
|
}
|
|
|
|
|
@@ -738,21 +288,11 @@ namespace Nz
|
|
|
|
|
OnNodeNewParent(this, parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::RemoveChild(Node* node) const
|
|
|
|
|
{
|
|
|
|
|
auto it = std::find(m_childs.begin(), m_childs.end(), node);
|
|
|
|
|
if (it != m_childs.end())
|
|
|
|
|
m_childs.erase(it);
|
|
|
|
|
else
|
|
|
|
|
NazaraWarning("Child not found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Node::UpdateDerived() const
|
|
|
|
|
{
|
|
|
|
|
if (m_parent)
|
|
|
|
|
{
|
|
|
|
|
if (!m_parent->m_derivedUpdated)
|
|
|
|
|
m_parent->UpdateDerived();
|
|
|
|
|
m_parent->EnsureDerivedUpdate();
|
|
|
|
|
|
|
|
|
|
if (m_inheritPosition)
|
|
|
|
|
m_derivedPosition = m_parent->m_derivedRotation*(m_parent->m_derivedScale * (m_initialPosition + m_position)) + m_parent->m_derivedPosition;
|
|
|
|
|
@@ -787,8 +327,7 @@ namespace Nz
|
|
|
|
|
|
|
|
|
|
void Node::UpdateTransformMatrix() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_derivedUpdated)
|
|
|
|
|
UpdateDerived();
|
|
|
|
|
EnsureDerivedUpdate();
|
|
|
|
|
|
|
|
|
|
m_transformMatrix.MakeTransform(m_derivedPosition, m_derivedRotation, m_derivedScale);
|
|
|
|
|
m_transformMatrixUpdated = true;
|
|
|
|
|
|