Added ComputeVerticesAABB algorithm
Made TransformVertices template Removed TransformVertex Former-commit-id: 68c7bdae2bd21adbed3fc7c54361c439ea0e5d37
This commit is contained in:
parent
a478926570
commit
542ce665c2
|
|
@ -21,6 +21,7 @@ NAZARA_API void NzComputeCubicSphereIndexVertexCount(unsigned int subdivision, u
|
|||
NAZARA_API void NzComputeIcoSphereIndexVertexCount(unsigned int recursionLevel, unsigned int* indexCount, unsigned int* vertexCount);
|
||||
NAZARA_API void NzComputePlaneIndexVertexCount(const NzVector2ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount);
|
||||
NAZARA_API void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int stackCount, unsigned int* indexCount, unsigned int* vertexCount);
|
||||
template<typename T> NzBoxf NzComputeVerticesAABB(const T* vertices, unsigned int vertexCount);
|
||||
|
||||
NAZARA_API void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
|
|
@ -30,8 +31,7 @@ NAZARA_API void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned
|
|||
|
||||
NAZARA_API void NzOptimizeIndices(NzIndexIterator indices, unsigned int indexCount);
|
||||
|
||||
inline void NzTransformVertex(NzMeshVertex* vertex, const NzMatrix4f& matrix);
|
||||
inline void NzTransformVertices(NzMeshVertex* vertices, unsigned int vertexCount, const NzMatrix4f& matrix);
|
||||
template<typename T> void NzTransformVertices(T* vertices, unsigned int vertexCount, const NzMatrix4f& matrix);
|
||||
|
||||
#include <Nazara/Utility/Algorithm.inl>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,21 +4,42 @@
|
|||
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
void NzTransformVertex(NzMeshVertex* vertex, const NzMatrix4f& matrix)
|
||||
template<typename T>
|
||||
NzBoxf NzComputeVerticesAABB(const T* vertices, unsigned int vertexCount)
|
||||
{
|
||||
vertex->normal = matrix.Transform(vertex->normal, 0.f);
|
||||
vertex->position = matrix.Transform(vertex->position);
|
||||
vertex->tangent = matrix.Transform(vertex->tangent, 0.f);
|
||||
vertex++;
|
||||
NzBoxf aabb;
|
||||
if (vertexCount > 0)
|
||||
{
|
||||
aabb.Set(vertices->position);
|
||||
vertices++;
|
||||
|
||||
for (unsigned int i = 1; i < vertexCount; ++i)
|
||||
{
|
||||
aabb.ExtendTo(vertices->position);
|
||||
vertices++;
|
||||
}
|
||||
}
|
||||
else
|
||||
aabb.MakeZero();
|
||||
|
||||
return aabb;
|
||||
}
|
||||
|
||||
void NzTransformVertices(NzMeshVertex* vertices, unsigned int vertexCount, const NzMatrix4f& matrix)
|
||||
template<typename T>
|
||||
void NzTransformVertices(T* vertices, unsigned int vertexCount, const NzMatrix4f& matrix)
|
||||
{
|
||||
if (matrix.IsIdentity())
|
||||
return;
|
||||
|
||||
NzVector3f scale = matrix.GetScale();
|
||||
|
||||
for (unsigned int i = 0; i < vertexCount; ++i)
|
||||
NzTransformVertex(vertices++, matrix);
|
||||
{
|
||||
vertices->normal = matrix.Transform(vertices->normal, 0.f) / scale;
|
||||
vertices->position = matrix.Transform(vertices->position);
|
||||
vertices->tangent = matrix.Transform(vertices->tangent, 0.f) / scale;
|
||||
vertices++;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
|
|
|
|||
Loading…
Reference in New Issue