Utility: Refactor some algorithms
This commit is contained in:
@@ -8,6 +8,59 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Vector3f TransformPositionTRS(const Vector3f& transformTranslation, const Quaternionf& transformRotation, const Vector3f& transformScale, const Vector3f& position)
|
||||
{
|
||||
return transformRotation * (transformScale * position) + transformTranslation;
|
||||
}
|
||||
|
||||
Vector3f TransformNormalTRS(const Quaternionf& transformRotation, const Vector3f& transformScale, const Vector3f& normal)
|
||||
{
|
||||
return Quaternionf::Mirror(transformRotation, transformScale) * normal;
|
||||
}
|
||||
|
||||
inline Quaternionf TransformRotationTRS(const Quaternionf& transformRotation, const Vector3f& transformScale, const Quaternionf& rotation)
|
||||
{
|
||||
return Quaternionf::Mirror(transformRotation, transformScale) * rotation;
|
||||
}
|
||||
|
||||
inline Vector3f TransformScaleTRS(const Vector3f& transformScale, const Vector3f& scale)
|
||||
{
|
||||
return transformScale * scale;
|
||||
}
|
||||
|
||||
inline void TransformTRS(const Vector3f& transformTranslation, const Quaternionf& transformRotation, const Vector3f& transformScale, Vector3f& position, Quaternionf& rotation, Vector3f& scale)
|
||||
{
|
||||
position = TransformPositionTRS(transformTranslation, transformRotation, transformScale, position);
|
||||
rotation = TransformRotationTRS(transformRotation, transformScale, rotation);
|
||||
scale = TransformScaleTRS(transformScale, scale);
|
||||
}
|
||||
|
||||
inline 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> constexpr ComponentType ComponentTypeId()
|
||||
{
|
||||
static_assert(AlwaysFalse<T>::value, "This type cannot be used as a component.");
|
||||
|
||||
Reference in New Issue
Block a user