From 35a37f850790ac74cd35e0f26ac42ba6094fcecd Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 26 Jan 2015 17:44:32 +0100 Subject: [PATCH] Updated ComputeAAB and TransformVertices functions They now take sparse pointers instead of template type Former-commit-id: 92a3de59b6a321136b8bad324048239f83381534 --- include/Nazara/Utility/Algorithm.hpp | 7 ++--- include/Nazara/Utility/Algorithm.inl | 42 ---------------------------- src/Nazara/Utility/Algorithm.cpp | 36 ++++++++++++++++++++++++ src/Nazara/Utility/StaticMesh.cpp | 4 +-- 4 files changed, 40 insertions(+), 49 deletions(-) delete mode 100644 include/Nazara/Utility/Algorithm.inl diff --git a/include/Nazara/Utility/Algorithm.hpp b/include/Nazara/Utility/Algorithm.hpp index 35ad30f91..c3e0cc9e0 100644 --- a/include/Nazara/Utility/Algorithm.hpp +++ b/include/Nazara/Utility/Algorithm.hpp @@ -32,7 +32,7 @@ struct NzVertexPointers NzSparsePtr uvPtr; }; -template NzBoxf NzComputeAABB(const T* vertices, unsigned int vertexCount); +NAZARA_API NzBoxf NzComputeAABB(NzSparsePtr positionPtr, unsigned int vertexCount); NAZARA_API void NzComputeBoxIndexVertexCount(const NzVector3ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount); NAZARA_API unsigned int NzComputeCacheMissCount(NzIndexIterator indices, unsigned int indexCount); NAZARA_API void NzComputeConeIndexVertexCount(unsigned int subdivision, unsigned int* indexCount, unsigned int* vertexCount); @@ -41,7 +41,6 @@ NAZARA_API void NzComputeIcoSphereIndexVertexCount(unsigned int recursionLevel, 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); -///TODO: Remplacer le pointeur vertices par une structure composée de plusieurs SparsePtr NAZARA_API void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzVertexPointers vertexPointers, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); NAZARA_API void NzGenerateCone(float length, float radius, unsigned int subdivision, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzVertexPointers vertexPointers, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzVertexPointers vertexPointers, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); @@ -55,8 +54,6 @@ NAZARA_API void NzSkinPosition(const NzSkinningData& data, unsigned int startVer NAZARA_API void NzSkinPositionNormal(const NzSkinningData& data, unsigned int startVertex, unsigned int vertexCount); NAZARA_API void NzSkinPositionNormalTangent(const NzSkinningData& data, unsigned int startVertex, unsigned int vertexCount); -template void NzTransformVertices(T* vertices, unsigned int vertexCount, const NzMatrix4f& matrix); - -#include +NAZARA_API void NzTransformVertices(NzVertexPointers vertexPointers, unsigned int vertexCount, const NzMatrix4f& matrix); #endif // NAZARA_ALGORITHM_UTILITY_HPP diff --git a/include/Nazara/Utility/Algorithm.inl b/include/Nazara/Utility/Algorithm.inl deleted file mode 100644 index eb0d1ab6e..000000000 --- a/include/Nazara/Utility/Algorithm.inl +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2015 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include - -template -NzBoxf NzComputeAABB(const T* vertices, unsigned int vertexCount) -{ - NzBoxf aabb; - if (vertexCount > 0) - { - aabb.Set(vertices->position.x, vertices->position.y, vertices->position.z, 0.f, 0.f, 0.f); - vertices++; - - for (unsigned int i = 1; i < vertexCount; ++i) - { - aabb.ExtendTo(vertices->position); - vertices++; - } - } - else - aabb.MakeZero(); - - return aabb; -} - -template -void NzTransformVertices(T* vertices, unsigned int vertexCount, const NzMatrix4f& matrix) -{ - NzVector3f scale = matrix.GetScale(); - - for (unsigned int i = 0; i < vertexCount; ++i) - { - 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 diff --git a/src/Nazara/Utility/Algorithm.cpp b/src/Nazara/Utility/Algorithm.cpp index 39f72889c..28f1daf9d 100644 --- a/src/Nazara/Utility/Algorithm.cpp +++ b/src/Nazara/Utility/Algorithm.cpp @@ -632,6 +632,23 @@ namespace /**********************************NzCompute**********************************/ +NzBoxf NzComputeAABB(NzSparsePtr positionPtr, unsigned int vertexCount) +{ + NzBoxf aabb; + if (vertexCount > 0) + { + aabb.Set(positionPtr->x, positionPtr->y, positionPtr->z, 0.f, 0.f, 0.f); + positionPtr++; + + for (unsigned int i = 1; i < vertexCount; ++i) + aabb.ExtendTo(*positionPtr++); + } + else + aabb.MakeZero(); + + return aabb; +} + void NzComputeBoxIndexVertexCount(const NzVector3ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount) { unsigned int xIndexCount, yIndexCount, zIndexCount; @@ -1128,3 +1145,22 @@ void NzSkinPositionNormalTangent(const NzSkinningData& skinningInfos, unsigned i outputVertex++; } } + +/*********************************NzTransform*********************************/ + +void NzTransformVertices(NzVertexPointers vertexPointers, unsigned int vertexCount, const NzMatrix4f& matrix) +{ + ///DOC: Pointeur read/write + NzVector3f scale = matrix.GetScale(); + + for (unsigned int i = 0; i < vertexCount; ++i) + { + *vertexPointers.positionPtr++ = matrix.Transform(*vertexPointers.positionPtr); + + if (vertexPointers.normalPtr) + *vertexPointers.normalPtr++ = matrix.Transform(*vertexPointers.normalPtr, 0.f) / scale; + + if (vertexPointers.tangentPtr) + *vertexPointers.tangentPtr++ = matrix.Transform(*vertexPointers.tangentPtr, 0.f) / scale; + } +} diff --git a/src/Nazara/Utility/StaticMesh.cpp b/src/Nazara/Utility/StaticMesh.cpp index 430feba03..14d5459d1 100644 --- a/src/Nazara/Utility/StaticMesh.cpp +++ b/src/Nazara/Utility/StaticMesh.cpp @@ -67,8 +67,8 @@ void NzStaticMesh::Destroy() bool NzStaticMesh::GenerateAABB() { // On lock le buffer pour itérer sur toutes les positions et composer notre AABB - NzBufferMapper mapper(m_vertexBuffer, nzBufferAccess_ReadOnly); - m_aabb = NzComputeAABB(static_cast(mapper.GetPointer()), m_vertexBuffer->GetVertexCount()); + NzVertexMapper mapper(m_vertexBuffer, nzBufferAccess_ReadOnly); + m_aabb = NzComputeAABB(mapper.GetComponentPtr(nzVertexComponent_Position), m_vertexBuffer->GetVertexCount()); return true; }