Added Mesh::Transform

Former-commit-id: c0680b23ff81a10a580934fc24d1ae4a13780595
This commit is contained in:
Lynix 2013-06-09 22:05:33 +02:00
parent 6b2af70f1d
commit f3d0618ae6
2 changed files with 46 additions and 0 deletions

View File

@ -108,6 +108,8 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
void SetMaterial(unsigned int matIndex, const NzString& materialPath); void SetMaterial(unsigned int matIndex, const NzString& materialPath);
void SetMaterialCount(unsigned int matCount); void SetMaterialCount(unsigned int matCount);
void Transform(const NzMatrix4f& matrix);
static const NzVertexDeclaration* GetDeclaration(); static const NzVertexDeclaration* GetDeclaration();
private: private:

View File

@ -915,6 +915,50 @@ void NzMesh::SetMaterialCount(unsigned int matCount)
#endif #endif
} }
void NzMesh::Transform(const NzMatrix4f& matrix)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Mesh not created");
return;
}
if (m_impl->animationType != nzAnimationType_Static)
{
NazaraError("Mesh must be static");
return;
}
#endif
if (matrix.IsIdentity())
return;
for (NzSubMesh* subMesh : m_impl->subMeshes)
{
NzStaticMesh* staticMesh = static_cast<NzStaticMesh*>(subMesh);
NzBufferMapper<NzVertexBuffer> mapper(staticMesh->GetVertexBuffer(), nzBufferAccess_ReadWrite);
NzMeshVertex* vertices = static_cast<NzMeshVertex*>(mapper.GetPointer());
NzBoxf aabb(vertices->position.x, vertices->position.y, vertices->position.z, 0.f, 0.f, 0.f);
unsigned int vertexCount = staticMesh->GetVertexCount();
for (unsigned int i = 0; i < vertexCount; ++i)
{
vertices->position = matrix.Transform(vertices->position);
aabb.ExtendTo(vertices->position);
vertices++;
}
staticMesh->SetAABB(aabb);
}
// Il ne faut pas oublier d'invalider notre AABB
m_impl->aabbUpdated = false;
}
const NzVertexDeclaration* NzMesh::GetDeclaration() const NzVertexDeclaration* NzMesh::GetDeclaration()
{ {
static NzVertexDeclaration declaration; static NzVertexDeclaration declaration;