Fix tessellation numbers in createCylinderMesh, createConeMesh, createArrowMesh

Double tessellation numbers for these 3 functions in your code to get same results as in Irrlicht 1.8

I noticed in last commit those all tessellated semi-circles instead of circles. I just documented it there, but it's annoying as that bug doesn't allow odd numbered tessellation. So for example one couldn't create a triangle pyramid. 
I considered adding another parameter to describe what this number means, but... just too ugly. And it was always documented otherwise, so this could be considered a bug. Sorry if this changes the look of existing apps.

Also cleaned up code in CGeometryCreator::createCylinderMesh. No idea what the idea behind old code was. Aside from creating twice the tessellation numbers.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6581 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien
2023-12-31 18:04:15 +00:00
parent 245dd395cb
commit 6b2a0fab78
5 changed files with 16 additions and 58 deletions

View File

@ -748,16 +748,17 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
{
SMeshBuffer* buffer = new SMeshBuffer();
if ( tessellation < 2 )
tessellation = 2;
const f32 recTessellation = core::reciprocal((f32)tessellation);
const f32 recTessellationHalf = recTessellation * 0.5f;
const f32 angleStep = (core::PI * 2.f ) * recTessellation;
const f32 angleStepHalf = angleStep*0.5f;
u32 i;
video::S3DVertex v;
v.Color = color;
buffer->Vertices.reallocate(tessellation*4+4+(closeTop?2:1));
buffer->Indices.reallocate((tessellation*2+1)*(closeTop?12:9));
buffer->Vertices.reallocate(tessellation*2+2+(closeTop?2:1));
buffer->Indices.reallocate(tessellation*(closeTop?12:9));
f32 tcx = 0.f;
for ( i = 0; i <= tessellation; ++i )
{
@ -775,30 +776,6 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
v.TCoords.Y=0.f;
buffer->Vertices.push_back(v);
v.Pos.X += oblique;
v.Pos.Y = length;
switch (normalType)
{
case 0: v.Normal = v.Pos; break;
case 1: v.Normal = core::vector3df(v.Pos.X-oblique, 0, v.Pos.Z); break;
}
v.Normal.normalize();
v.TCoords.Y=1.f;
buffer->Vertices.push_back(v);
v.Pos.X = radius * cosf(angle + angleStepHalf);
v.Pos.Y = 0.f;
v.Pos.Z = radius * sinf(angle + angleStepHalf);
switch (normalType)
{
case 0: v.Normal = v.Pos; break;
case 1: v.Normal = v.Pos; break;
}
v.Normal.normalize();
v.TCoords.X=tcx+recTessellationHalf;
v.TCoords.Y=0.f;
buffer->Vertices.push_back(v);
v.Pos.X += oblique;
v.Pos.Y = length;
switch (normalType)
@ -812,8 +789,7 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
tcx += recTessellation;
}
// indices for the main hull part
const u32 nonWrappedSize = tessellation* 4;
const u32 nonWrappedSize = tessellation*2;
for (i=0; i != nonWrappedSize; i += 2)
{
buffer->Indices.push_back(i + 2);
@ -825,15 +801,6 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
buffer->Indices.push_back(i + 3);
}
// two closing quads between end and start
buffer->Indices.push_back(0);
buffer->Indices.push_back(i + 0);
buffer->Indices.push_back(i + 1);
buffer->Indices.push_back(0);
buffer->Indices.push_back(i + 1);
buffer->Indices.push_back(1);
// close down
v.Pos.X = 0.f;
v.Pos.Y = 0.f;
@ -854,10 +821,6 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
buffer->Indices.push_back(i + 2);
}
buffer->Indices.push_back(index);
buffer->Indices.push_back(i + 0);
buffer->Indices.push_back(0);
if (closeTop)
{
// close top
@ -879,10 +842,6 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
buffer->Indices.push_back(index);
buffer->Indices.push_back(i + 3);
}
buffer->Indices.push_back(i + 1);
buffer->Indices.push_back(index);
buffer->Indices.push_back(1);
}
buffer->recalculateBoundingBox();
@ -903,10 +862,6 @@ IMesh* CGeometryCreator::createConeMesh(f32 radius, f32 length, u32 tessellation
{
SMeshBuffer* buffer = new SMeshBuffer();
// TODO: For backward compatibility tessellation is per semi-circle
// We probably need another parameter to allow odd numbered tesselation without breaking existing code :-(
if ( tessellation > 0 )
tessellation = 2*tessellation;
if ( tessellation < 2 )
tessellation = 2;