CSceneManager.cpp
Code: Select all
//! Adds an arrow mesh to the mesh pool.
IAnimatedMesh* CSceneManager::addArrowMesh(const c8* name,
video::SColor vtxColor0, video::SColor vtxColor1,
u32 tesselationCylinder, u32 tesselationCone, f32 height,
f32 cylinderHeight, f32 width0,f32 width1)
{
if (!name)
return 0;
if (MeshCache->isMeshLoaded(name))
return MeshCache->getMeshByFilename(name);
IMesh* mesh = CGeometryCreator::createArrowMesh( tesselationCylinder,
tesselationCone, height, cylinderHeight, width0,width1,
vtxColor0, vtxColor1);
if (!mesh)
return 0;
SAnimatedMesh* animatedMesh = new SAnimatedMesh();
if (!animatedMesh)
{
mesh->drop();
return 0;
}
animatedMesh->addMesh(mesh);
mesh->drop();
animatedMesh->recalculateBoundingBox();
MeshCache->addMesh(name, animatedMesh);
animatedMesh->drop();
return animatedMesh;
}
CGeometryCreator
Code: Select all
/*
a cone
point up on (0,1.f, 0.f )
*/
IMesh* CGeometryCreator::createConeMesh(const u32 tesselationCone,
const f32 offset,
const f32 width,
const video::SColor vtxColor)
{
SMeshBuffer* buffer;
video::S3DVertex v;
u32 i;
v.Color = vtxColor;
// cone
buffer = new SMeshBuffer();
f32 angleStep = (core::PI * 2.f ) / tesselationCone;
v.Color = vtxColor;
for ( i = 0; i != tesselationCone; ++i )
{
f32 angle = angleStep * f32(i);
v.Color = vtxColor;
v.Pos.X = width * cosf ( angle );
v.Pos.Y = offset;
v.Pos.Z = width * sinf ( angle );
v.Normal = v.Pos;
v.Normal.normalize ();
buffer->Vertices.push_back ( v );
angle += angleStep / 2.f;
v.Color = vtxColor;
v.Pos.X = width * cosf ( angle );
v.Pos.Y = offset;
v.Pos.Z = width * sinf ( angle );
v.Normal = v.Pos;
v.Normal.normalize ();
buffer->Vertices.push_back ( v );
}
u32 nonWrappedSize = buffer->Vertices.size () - 1;
// close top
v.Pos.X = 0.f;
v.Pos.Y = offset;
v.Pos.Z = 0.f;
v.Normal.X = 0.f;
v.Normal.Y = 1.f;
v.Normal.Z = 0.f;
buffer->Vertices.push_back ( v );
u32 index = buffer->Vertices.size () - 1;
for ( i = 0; i != nonWrappedSize; i += 1 )
{
buffer->Indices.push_back ( i + 0 );
buffer->Indices.push_back ( index );
buffer->Indices.push_back ( i + 1 );
}
buffer->Indices.push_back ( i + 0 );
buffer->Indices.push_back ( index );
buffer->Indices.push_back ( 0 );
// close down
v.Pos.X = 0.f;
v.Pos.Y = offset;
v.Pos.Z = 0.f;
v.Normal.X = 0.f;
v.Normal.Y = -1.f;
v.Normal.Z = 0.f;
buffer->Vertices.push_back ( v );
index = buffer->Vertices.size () - 1;
for ( i = 0; i != nonWrappedSize; i += 1 )
{
buffer->Indices.push_back ( index );
buffer->Indices.push_back ( i + 0 );
buffer->Indices.push_back ( i + 1 );
}
buffer->Indices.push_back ( index );
buffer->Indices.push_back ( i + 0 );
buffer->Indices.push_back ( 0 );
// add to mesh
SMesh* mesh = new SMesh();
buffer->recalculateBoundingBox();
mesh->addMeshBuffer(buffer);
buffer->drop();
mesh->recalculateBoundingBox();
return mesh;
}