From 9239ff8881bb616b9aaca369c180ebf331ed397c Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 3 Jun 2013 17:14:09 +0200 Subject: [PATCH] Box primitives now uses vec3 lengths parameter Instead of a Box parameter Former-commit-id: 6c433e883252c6db8eba3b791d1e9364ce5d3b1e --- include/Nazara/Core/PrimitiveList.hpp | 4 ++-- include/Nazara/Utility/Algorithm.hpp | 2 +- src/Nazara/Core/PrimitiveList.cpp | 8 ++++---- src/Nazara/Utility/Algorithm.cpp | 20 ++++++++++---------- src/Nazara/Utility/Mesh.cpp | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/Nazara/Core/PrimitiveList.hpp b/include/Nazara/Core/PrimitiveList.hpp index f5c0b4943..7c553b2ce 100644 --- a/include/Nazara/Core/PrimitiveList.hpp +++ b/include/Nazara/Core/PrimitiveList.hpp @@ -17,8 +17,8 @@ class NAZARA_API NzPrimitiveList NzPrimitiveList() = default; ~NzPrimitiveList() = default; - void AddBox(const NzBoxf& box, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& matrix = NzMatrix4f::Identity()); - void AddBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + void AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& matrix = NzMatrix4f::Identity()); + void AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); void AddCubicSphere(float size, unsigned int subdivision = 4, const NzMatrix4f& matrix = NzMatrix4f::Identity()); void AddCubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); void AddIcoSphere(float size, unsigned int recursionLevel = 1, const NzMatrix4f& matrix = NzMatrix4f::Identity()); diff --git a/include/Nazara/Utility/Algorithm.hpp b/include/Nazara/Utility/Algorithm.hpp index 7461d7a40..11c7ef3ca 100644 --- a/include/Nazara/Utility/Algorithm.hpp +++ b/include/Nazara/Utility/Algorithm.hpp @@ -21,7 +21,7 @@ NAZARA_API void NzComputePlaneIndexVertexCount(const NzVector2ui& subdivision, u NAZARA_API void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int stackCount, unsigned int* indexCount, unsigned int* vertexCount); ///TODO: Itérateur sur les indices -NAZARA_API void NzGenerateBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); +NAZARA_API void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); NAZARA_API void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); NAZARA_API void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); diff --git a/src/Nazara/Core/PrimitiveList.cpp b/src/Nazara/Core/PrimitiveList.cpp index de161f0da..65da5775c 100644 --- a/src/Nazara/Core/PrimitiveList.cpp +++ b/src/Nazara/Core/PrimitiveList.cpp @@ -6,20 +6,20 @@ #include #include -void NzPrimitiveList::AddBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzMatrix4f& matrix) +void NzPrimitiveList::AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix) { NzPrimitive primitive; primitive.type = nzPrimitiveType_Box; - primitive.box.box = box; // box.box = box, parce que je le vaux bien + primitive.box.lengths = lengths; primitive.box.matrix = matrix; primitive.box.subdivision = subdivision; m_primitives.push_back(primitive); } -void NzPrimitiveList::AddBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) +void NzPrimitiveList::AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) { - AddBox(box, subdivision, NzMatrix4f::Transform(position, rotation)); + AddBox(lengths, subdivision, NzMatrix4f::Transform(position, rotation)); } void NzPrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix) diff --git a/src/Nazara/Utility/Algorithm.cpp b/src/Nazara/Utility/Algorithm.cpp index 8ca4dbcf4..d06edd9e9 100644 --- a/src/Nazara/Utility/Algorithm.cpp +++ b/src/Nazara/Utility/Algorithm.cpp @@ -202,7 +202,7 @@ void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int sta *vertexCount = sliceCount * stackCount; } -void NzGenerateBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) +void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) { unsigned int xIndexCount, yIndexCount, zIndexCount; unsigned int xVertexCount, yVertexCount, zVertexCount; @@ -214,37 +214,37 @@ void NzGenerateBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzMa NzMeshVertex* oldVertices = vertices; // Face +X - NzGeneratePlane(NzVector2ui(subdivision.y, subdivision.z), box.GetPosition() + NzVector3f::UnitX() * box.width/2.f, NzVector3f::UnitX(), NzVector2f(box.height, box.depth), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.y, subdivision.z), NzVector3f::UnitX() * lengths.x/2.f, NzVector3f::UnitX(), NzVector2f(lengths.y, lengths.z), vertices, indices, nullptr, indexOffset); indexOffset += xVertexCount; indices += xIndexCount; vertices += xVertexCount; // Face +Y - NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), box.GetPosition() + NzVector3f::UnitY() * box.height/2.f, NzVector3f::UnitY(), NzVector2f(box.width, box.depth), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), NzVector3f::UnitY() * lengths.y/2.f, NzVector3f::UnitY(), NzVector2f(lengths.x, lengths.z), vertices, indices, nullptr, indexOffset); indexOffset += yVertexCount; indices += yIndexCount; vertices += yVertexCount; // Face +Z - NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), box.GetPosition() + NzVector3f::UnitZ() * box.depth/2.f, NzVector3f::UnitZ(), NzVector2f(box.width, box.height), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), NzVector3f::UnitZ() * lengths.z/2.f, NzVector3f::UnitZ(), NzVector2f(lengths.x, lengths.y), vertices, indices, nullptr, indexOffset); indexOffset += zVertexCount; indices += zIndexCount; vertices += zVertexCount; // Face -X - NzGeneratePlane(NzVector2ui(subdivision.y, subdivision.z), box.GetPosition() - NzVector3f::UnitX() * box.width/2.f, -NzVector3f::UnitX(), NzVector2f(box.height, box.depth), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.y, subdivision.z), -NzVector3f::UnitX() * lengths.x/2.f, -NzVector3f::UnitX(), NzVector2f(lengths.y, lengths.z), vertices, indices, nullptr, indexOffset); indexOffset += xVertexCount; indices += xIndexCount; vertices += xVertexCount; // Face -Y - NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), box.GetPosition() - NzVector3f::UnitY() * box.height/2.f, -NzVector3f::UnitY(), NzVector2f(box.width, box.depth), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), -NzVector3f::UnitY() * lengths.y/2.f, -NzVector3f::UnitY(), NzVector2f(lengths.x, lengths.z), vertices, indices, nullptr, indexOffset); indexOffset += yVertexCount; indices += yIndexCount; vertices += yVertexCount; // Face -Z - NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), box.GetPosition() - NzVector3f::UnitZ() * box.depth/2.f, -NzVector3f::UnitZ(), NzVector2f(box.width, box.height), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), -NzVector3f::UnitZ() * lengths.z/2.f, -NzVector3f::UnitZ(), NzVector2f(lengths.x, lengths.y), vertices, indices, nullptr, indexOffset); indexOffset += zVertexCount; indices += zIndexCount; vertices += zVertexCount; @@ -253,7 +253,7 @@ void NzGenerateBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzMa if (aabb) { - aabb->Set(NzVector3f::Unit()); + aabb->Set(lengths); aabb->Transform(matrix, 0.f); } } @@ -263,8 +263,8 @@ void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4 unsigned int vertexCount; NzComputeBoxIndexVertexCount(NzVector3ui(subdivision), nullptr, &vertexCount); - // On envoie une matrice identité de sorte à ce que le box ne subisse aucune transformation (rendant plus facile l'étape suivante) - NzGenerateBox(NzBoxf(size, size, size), NzVector3ui(subdivision), NzMatrix4f::Identity(), vertices, indices, nullptr, indexOffset); + // On envoie une matrice identité de sorte à ce que la boîte ne subisse aucune transformation (rendant plus facile l'étape suivante) + NzGenerateBox(NzVector3f(size, size, size), NzVector3ui(subdivision), NzMatrix4f::Identity(), vertices, indices, nullptr, indexOffset); if (aabb) { diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index 0773c6711..cce70e0e8 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -193,7 +193,7 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params) indices.resize(indexCount); NzBufferMapper vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly); - NzGenerateBox(primitive.box.box, primitive.box.subdivision, primitive.box.matrix, static_cast(vertexMapper.GetPointer()), &indices[0], &aabb); + NzGenerateBox(primitive.box.lengths, primitive.box.subdivision, primitive.box.matrix, static_cast(vertexMapper.GetPointer()), &indices[0], &aabb); vertexMapper.Unmap(); NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);