Utility/Node: Fix negative scaling not affecting rotation
This commit is contained in:
parent
c10b0c22ed
commit
3760c8b5c4
|
|
@ -205,6 +205,7 @@ Nazara Engine:
|
|||
- ⚠ Removed all Set methods from math classes taking their own type (e.g. Box::Set(Box))
|
||||
- Added Matrix4::Decompose
|
||||
- ⚠ Node::Get[Position|Rotation|Scale] now defaults to local space
|
||||
- Fixed Node rotation when using a negative scale
|
||||
|
||||
Nazara Development Kit:
|
||||
- Added ImageWidget (#139)
|
||||
|
|
|
|||
|
|
@ -105,6 +105,8 @@ namespace Nz
|
|||
virtual void UpdateDerived() const;
|
||||
virtual void UpdateTransformMatrix() const;
|
||||
|
||||
static Quaternionf ScaleQuaternion(const Vector3f& scale, Quaternionf quaternion);
|
||||
|
||||
mutable std::vector<Node*> m_childs;
|
||||
mutable Matrix4f m_transformMatrix;
|
||||
mutable Quaternionf m_derivedRotation;
|
||||
|
|
|
|||
|
|
@ -574,7 +574,7 @@ namespace Nz
|
|||
if (!m_derivedUpdated)
|
||||
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
|
||||
|
|
@ -582,7 +582,7 @@ namespace Nz
|
|||
if (!m_derivedUpdated)
|
||||
UpdateDerived();
|
||||
|
||||
return m_derivedRotation * localRotation;
|
||||
return ScaleQuaternion(m_derivedScale, m_derivedRotation) * localRotation;
|
||||
}
|
||||
|
||||
Vector3f Node::ToGlobalScale(const Vector3f& localScale) const
|
||||
|
|
@ -598,7 +598,7 @@ namespace Nz
|
|||
if (!m_derivedUpdated)
|
||||
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
|
||||
|
|
@ -688,7 +688,11 @@ namespace Nz
|
|||
|
||||
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();
|
||||
}
|
||||
else
|
||||
|
|
@ -716,4 +720,27 @@ namespace Nz
|
|||
m_transformMatrix.MakeTransform(m_derivedPosition, m_derivedRotation, m_derivedScale);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue