Utility: Refactor some algorithms
This commit is contained in:
@@ -1156,32 +1156,4 @@ namespace Nz
|
||||
outputVertex++;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************Transform*********************************/
|
||||
|
||||
void TransformVertices(VertexPointers vertexPointers, UInt64 vertexCount, const Matrix4f& matrix)
|
||||
{
|
||||
if (vertexPointers.positionPtr)
|
||||
{
|
||||
for (UInt64 i = 0; i < vertexCount; ++i)
|
||||
*vertexPointers.positionPtr++ = matrix.Transform(*vertexPointers.positionPtr);
|
||||
}
|
||||
|
||||
if (vertexPointers.normalPtr || vertexPointers.tangentPtr)
|
||||
{
|
||||
Vector3f scale = matrix.GetScale();
|
||||
|
||||
if (vertexPointers.normalPtr)
|
||||
{
|
||||
for (UInt64 i = 0; i < vertexCount; ++i)
|
||||
*vertexPointers.normalPtr++ = matrix.Transform(*vertexPointers.normalPtr, 0.f) / scale;
|
||||
}
|
||||
|
||||
if (vertexPointers.tangentPtr)
|
||||
{
|
||||
for (UInt64 i = 0; i < vertexCount; ++i)
|
||||
*vertexPointers.tangentPtr++ = matrix.Transform(*vertexPointers.tangentPtr, 0.f) / scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Utility/Algorithm.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
@@ -610,7 +611,7 @@ namespace Nz
|
||||
if (!m_derivedUpdated)
|
||||
UpdateDerived();
|
||||
|
||||
return m_derivedPosition + (m_derivedScale * (ScaleQuaternion(m_derivedScale, m_derivedRotation) * localPosition));
|
||||
return TransformPositionTRS(m_derivedPosition, m_derivedRotation, m_derivedScale, localPosition);
|
||||
}
|
||||
|
||||
Quaternionf Node::ToGlobalRotation(const Quaternionf& localRotation) const
|
||||
@@ -618,7 +619,7 @@ namespace Nz
|
||||
if (!m_derivedUpdated)
|
||||
UpdateDerived();
|
||||
|
||||
return ScaleQuaternion(m_derivedScale, m_derivedRotation) * localRotation;
|
||||
return TransformRotationTRS(m_derivedRotation, m_derivedScale, localRotation);
|
||||
}
|
||||
|
||||
Vector3f Node::ToGlobalScale(const Vector3f& localScale) const
|
||||
@@ -626,7 +627,7 @@ namespace Nz
|
||||
if (!m_derivedUpdated)
|
||||
UpdateDerived();
|
||||
|
||||
return m_derivedScale * localScale;
|
||||
return TransformScaleTRS(m_derivedScale, localScale);
|
||||
}
|
||||
|
||||
Vector3f Node::ToLocalPosition(const Vector3f& globalPosition) const
|
||||
@@ -762,7 +763,7 @@ namespace Nz
|
||||
{
|
||||
Quaternionf rotation = m_initialRotation * m_rotation;
|
||||
if (m_inheritScale)
|
||||
rotation = ScaleQuaternion(m_parent->m_derivedScale, rotation);
|
||||
rotation = Quaternionf::Mirror(rotation, m_parent->m_derivedScale);
|
||||
|
||||
m_derivedRotation = m_parent->m_derivedRotation * rotation;
|
||||
m_derivedRotation.Normalize();
|
||||
@@ -792,27 +793,4 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user