Utility/Node: Fix negative scaling not affecting rotation
This commit is contained in:
@@ -205,6 +205,7 @@ Nazara Engine:
|
|||||||
- ⚠ Removed all Set methods from math classes taking their own type (e.g. Box::Set(Box))
|
- ⚠ Removed all Set methods from math classes taking their own type (e.g. Box::Set(Box))
|
||||||
- Added Matrix4::Decompose
|
- Added Matrix4::Decompose
|
||||||
- ⚠ Node::Get[Position|Rotation|Scale] now defaults to local space
|
- ⚠ Node::Get[Position|Rotation|Scale] now defaults to local space
|
||||||
|
- Fixed Node rotation when using a negative scale
|
||||||
|
|
||||||
Nazara Development Kit:
|
Nazara Development Kit:
|
||||||
- Added ImageWidget (#139)
|
- Added ImageWidget (#139)
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ namespace Nz
|
|||||||
virtual void UpdateDerived() const;
|
virtual void UpdateDerived() const;
|
||||||
virtual void UpdateTransformMatrix() const;
|
virtual void UpdateTransformMatrix() const;
|
||||||
|
|
||||||
|
static Quaternionf ScaleQuaternion(const Vector3f& scale, Quaternionf quaternion);
|
||||||
|
|
||||||
mutable std::vector<Node*> m_childs;
|
mutable std::vector<Node*> m_childs;
|
||||||
mutable Matrix4f m_transformMatrix;
|
mutable Matrix4f m_transformMatrix;
|
||||||
mutable Quaternionf m_derivedRotation;
|
mutable Quaternionf m_derivedRotation;
|
||||||
|
|||||||
@@ -574,7 +574,7 @@ namespace Nz
|
|||||||
if (!m_derivedUpdated)
|
if (!m_derivedUpdated)
|
||||||
UpdateDerived();
|
UpdateDerived();
|
||||||
|
|
||||||
return m_derivedPosition + (m_derivedScale * (m_derivedRotation * localPosition));
|
return m_derivedPosition + (m_derivedScale * (ScaleQuaternion(m_derivedScale, m_derivedRotation) * localPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternionf Node::ToGlobalRotation(const Quaternionf& localRotation) const
|
Quaternionf Node::ToGlobalRotation(const Quaternionf& localRotation) const
|
||||||
@@ -582,7 +582,7 @@ namespace Nz
|
|||||||
if (!m_derivedUpdated)
|
if (!m_derivedUpdated)
|
||||||
UpdateDerived();
|
UpdateDerived();
|
||||||
|
|
||||||
return m_derivedRotation * localRotation;
|
return ScaleQuaternion(m_derivedScale, m_derivedRotation) * localRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f Node::ToGlobalScale(const Vector3f& localScale) const
|
Vector3f Node::ToGlobalScale(const Vector3f& localScale) const
|
||||||
@@ -598,7 +598,7 @@ namespace Nz
|
|||||||
if (!m_derivedUpdated)
|
if (!m_derivedUpdated)
|
||||||
UpdateDerived();
|
UpdateDerived();
|
||||||
|
|
||||||
return (m_derivedRotation.GetConjugate()*(globalPosition - m_derivedPosition))/m_derivedScale;
|
return (m_derivedScale, m_derivedRotation.GetConjugate()*(globalPosition - m_derivedPosition))/m_derivedScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternionf Node::ToLocalRotation(const Quaternionf& globalRotation) const
|
Quaternionf Node::ToLocalRotation(const Quaternionf& globalRotation) const
|
||||||
@@ -688,7 +688,11 @@ namespace Nz
|
|||||||
|
|
||||||
if (m_inheritRotation)
|
if (m_inheritRotation)
|
||||||
{
|
{
|
||||||
m_derivedRotation = m_parent->m_derivedRotation * m_initialRotation * m_rotation;
|
Quaternionf rotation = m_initialRotation * m_rotation;
|
||||||
|
if (m_inheritScale)
|
||||||
|
rotation = ScaleQuaternion(m_parent->m_derivedScale, rotation);
|
||||||
|
|
||||||
|
m_derivedRotation = m_parent->m_derivedRotation * rotation;
|
||||||
m_derivedRotation.Normalize();
|
m_derivedRotation.Normalize();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -716,4 +720,27 @@ namespace Nz
|
|||||||
m_transformMatrix.MakeTransform(m_derivedPosition, m_derivedRotation, m_derivedScale);
|
m_transformMatrix.MakeTransform(m_derivedPosition, m_derivedRotation, m_derivedScale);
|
||||||
m_transformMatrixUpdated = true;
|
m_transformMatrixUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Quaternionf Node::ScaleQuaternion(const Vector3f& scale, Quaternionf quaternion)
|
||||||
|
{
|
||||||
|
if (std::signbit(scale.x))
|
||||||
|
{
|
||||||
|
quaternion.z = -quaternion.z;
|
||||||
|
quaternion.y = -quaternion.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::signbit(scale.y))
|
||||||
|
{
|
||||||
|
quaternion.x = -quaternion.x;
|
||||||
|
quaternion.z = -quaternion.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::signbit(scale.z))
|
||||||
|
{
|
||||||
|
quaternion.x = -quaternion.x;
|
||||||
|
quaternion.y = -quaternion.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return quaternion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user