Box primitives now uses vec3 lengths parameter

Instead of a Box parameter


Former-commit-id: 6c433e883252c6db8eba3b791d1e9364ce5d3b1e
This commit is contained in:
Lynix 2013-06-03 17:14:09 +02:00
parent fb839de33e
commit 9239ff8881
5 changed files with 18 additions and 18 deletions

View File

@ -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());

View File

@ -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);

View File

@ -6,20 +6,20 @@
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Debug.hpp>
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)

View File

@ -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)
{

View File

@ -193,7 +193,7 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params)
indices.resize(indexCount);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzGenerateBox(primitive.box.box, primitive.box.subdivision, primitive.box.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), &indices[0], &aabb);
NzGenerateBox(primitive.box.lengths, primitive.box.subdivision, primitive.box.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), &indices[0], &aabb);
vertexMapper.Unmap();
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);