Updated ComputeAAB and TransformVertices functions

They now take sparse pointers instead of template type


Former-commit-id: 92a3de59b6a321136b8bad324048239f83381534
This commit is contained in:
Lynix
2015-01-26 17:44:32 +01:00
parent 025fdf6846
commit 35a37f8507
4 changed files with 40 additions and 49 deletions

View File

@@ -632,6 +632,23 @@ namespace
/**********************************NzCompute**********************************/
NzBoxf NzComputeAABB(NzSparsePtr<const NzVector3f> 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;
}
}

View File

@@ -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<NzVertexBuffer> mapper(m_vertexBuffer, nzBufferAccess_ReadOnly);
m_aabb = NzComputeAABB(static_cast<const NzMeshVertex*>(mapper.GetPointer()), m_vertexBuffer->GetVertexCount());
NzVertexMapper mapper(m_vertexBuffer, nzBufferAccess_ReadOnly);
m_aabb = NzComputeAABB(mapper.GetComponentPtr<const NzVector3f>(nzVertexComponent_Position), m_vertexBuffer->GetVertexCount());
return true;
}