mirror of
https://github.com/minetest/irrlicht.git
synced 2025-03-20 11:10:35 +01:00
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:
parent
245dd395cb
commit
6b2a0fab78
@ -1,6 +1,9 @@
|
|||||||
--------------------------
|
--------------------------
|
||||||
Changes in 1.9 (not yet released)
|
Changes in 1.9 (not yet released)
|
||||||
|
|
||||||
|
- createCylinderMesh and createConeMesh in GeometryCreator tessellation numbers now for full instead of semi-circle.
|
||||||
|
Double your tessellation numbers to get same results as in 1.8
|
||||||
|
Sorry had to break as old solution didn't allow for odd numbers. Also was documented otherwise, so was a bug.
|
||||||
- Change in UV's for top/bottom center vertex in CGeometryCreator::createCylinderMesh
|
- Change in UV's for top/bottom center vertex in CGeometryCreator::createCylinderMesh
|
||||||
- Add some default UV's in CGeometryCreator::createConeMesh
|
- Add some default UV's in CGeometryCreator::createConeMesh
|
||||||
- Bugfix: CTriangleSelector::getTriangles with bounding-box parameter no longer ignores an additionally passed matrix transformation in the box check
|
- Bugfix: CTriangleSelector::getTriangles with bounding-box parameter no longer ignores an additionally passed matrix transformation in the box check
|
||||||
|
@ -135,8 +135,8 @@ public:
|
|||||||
|
|
||||||
//! Create an arrow mesh, composed of a cylinder and a cone.
|
//! Create an arrow mesh, composed of a cylinder and a cone.
|
||||||
/**
|
/**
|
||||||
\param tessellationCylinder Number of quads composing half the cylinder.
|
\param tessellationCylinder Number of quads composing the cylinder.
|
||||||
\param tessellationCone Number of triangles composing half the cone's roof.
|
\param tessellationCone Number of triangles composing the cone's roof.
|
||||||
\param height Total height of the arrow
|
\param height Total height of the arrow
|
||||||
\param cylinderHeight Total height of the cylinder, should be lesser
|
\param cylinderHeight Total height of the cylinder, should be lesser
|
||||||
than total height
|
than total height
|
||||||
@ -147,8 +147,8 @@ public:
|
|||||||
\param colorCone color of the cone
|
\param colorCone color of the cone
|
||||||
\return Generated mesh.
|
\return Generated mesh.
|
||||||
*/
|
*/
|
||||||
virtual IMesh* createArrowMesh(const u32 tessellationCylinder = 4,
|
virtual IMesh* createArrowMesh(const u32 tessellationCylinder = 16,
|
||||||
const u32 tessellationCone = 8, const f32 height = 1.f,
|
const u32 tessellationCone = 16, const f32 height = 1.f,
|
||||||
const f32 cylinderHeight = 0.6f, const f32 widthCylinder = 0.05f,
|
const f32 cylinderHeight = 0.6f, const f32 widthCylinder = 0.05f,
|
||||||
const f32 widthCone = 0.3f, const video::SColor colorCylinder = 0xFFFFFFFF,
|
const f32 widthCone = 0.3f, const video::SColor colorCylinder = 0xFFFFFFFF,
|
||||||
const video::SColor colorCone = 0xFFFFFFFF) const =0;
|
const video::SColor colorCone = 0xFFFFFFFF) const =0;
|
||||||
@ -168,7 +168,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
\param radius Radius of the cylinder.
|
\param radius Radius of the cylinder.
|
||||||
\param length Length of the cylinder.
|
\param length Length of the cylinder.
|
||||||
\param tessellation Number of quads around half the circumference of the cylinder.
|
\param tessellation Number of quads around the circumference of the cylinder.
|
||||||
\param color The color of the cylinder.
|
\param color The color of the cylinder.
|
||||||
\param closeTop If true, close the ends of the cylinder, otherwise leave them open.
|
\param closeTop If true, close the ends of the cylinder, otherwise leave them open.
|
||||||
\param oblique X-offset (shear) of top compared to bottom.
|
\param oblique X-offset (shear) of top compared to bottom.
|
||||||
@ -191,7 +191,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
\param radius Radius of the cone.
|
\param radius Radius of the cone.
|
||||||
\param length Length of the cone.
|
\param length Length of the cone.
|
||||||
\param tessellation Number of triangles around half the circumference of the cone.
|
\param tessellation Number of triangles around the circumference of the cone.
|
||||||
\param colorTop The color of the top of the cone.
|
\param colorTop The color of the top of the cone.
|
||||||
\param colorBottom The color of the bottom of the cone.
|
\param colorBottom The color of the bottom of the cone.
|
||||||
\param oblique (to be documented)
|
\param oblique (to be documented)
|
||||||
|
@ -748,16 +748,17 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
|
|||||||
{
|
{
|
||||||
SMeshBuffer* buffer = new SMeshBuffer();
|
SMeshBuffer* buffer = new SMeshBuffer();
|
||||||
|
|
||||||
|
if ( tessellation < 2 )
|
||||||
|
tessellation = 2;
|
||||||
|
|
||||||
const f32 recTessellation = core::reciprocal((f32)tessellation);
|
const f32 recTessellation = core::reciprocal((f32)tessellation);
|
||||||
const f32 recTessellationHalf = recTessellation * 0.5f;
|
|
||||||
const f32 angleStep = (core::PI * 2.f ) * recTessellation;
|
const f32 angleStep = (core::PI * 2.f ) * recTessellation;
|
||||||
const f32 angleStepHalf = angleStep*0.5f;
|
|
||||||
|
|
||||||
u32 i;
|
u32 i;
|
||||||
video::S3DVertex v;
|
video::S3DVertex v;
|
||||||
v.Color = color;
|
v.Color = color;
|
||||||
buffer->Vertices.reallocate(tessellation*4+4+(closeTop?2:1));
|
buffer->Vertices.reallocate(tessellation*2+2+(closeTop?2:1));
|
||||||
buffer->Indices.reallocate((tessellation*2+1)*(closeTop?12:9));
|
buffer->Indices.reallocate(tessellation*(closeTop?12:9));
|
||||||
f32 tcx = 0.f;
|
f32 tcx = 0.f;
|
||||||
for ( i = 0; i <= tessellation; ++i )
|
for ( i = 0; i <= tessellation; ++i )
|
||||||
{
|
{
|
||||||
@ -775,30 +776,6 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
|
|||||||
v.TCoords.Y=0.f;
|
v.TCoords.Y=0.f;
|
||||||
buffer->Vertices.push_back(v);
|
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.X += oblique;
|
||||||
v.Pos.Y = length;
|
v.Pos.Y = length;
|
||||||
switch (normalType)
|
switch (normalType)
|
||||||
@ -812,8 +789,7 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
|
|||||||
tcx += recTessellation;
|
tcx += recTessellation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// indices for the main hull part
|
const u32 nonWrappedSize = tessellation*2;
|
||||||
const u32 nonWrappedSize = tessellation* 4;
|
|
||||||
for (i=0; i != nonWrappedSize; i += 2)
|
for (i=0; i != nonWrappedSize; i += 2)
|
||||||
{
|
{
|
||||||
buffer->Indices.push_back(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);
|
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
|
// close down
|
||||||
v.Pos.X = 0.f;
|
v.Pos.X = 0.f;
|
||||||
v.Pos.Y = 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(i + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->Indices.push_back(index);
|
|
||||||
buffer->Indices.push_back(i + 0);
|
|
||||||
buffer->Indices.push_back(0);
|
|
||||||
|
|
||||||
if (closeTop)
|
if (closeTop)
|
||||||
{
|
{
|
||||||
// close top
|
// close top
|
||||||
@ -879,10 +842,6 @@ IMesh* CGeometryCreator::createCylinderMesh(f32 radius, f32 length,
|
|||||||
buffer->Indices.push_back(index);
|
buffer->Indices.push_back(index);
|
||||||
buffer->Indices.push_back(i + 3);
|
buffer->Indices.push_back(i + 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->Indices.push_back(i + 1);
|
|
||||||
buffer->Indices.push_back(index);
|
|
||||||
buffer->Indices.push_back(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->recalculateBoundingBox();
|
buffer->recalculateBoundingBox();
|
||||||
@ -903,10 +862,6 @@ IMesh* CGeometryCreator::createConeMesh(f32 radius, f32 length, u32 tessellation
|
|||||||
{
|
{
|
||||||
SMeshBuffer* buffer = new SMeshBuffer();
|
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 )
|
if ( tessellation < 2 )
|
||||||
tessellation = 2;
|
tessellation = 2;
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 9.0 KiB |
@ -1,4 +1,4 @@
|
|||||||
Tests finished. 72 tests of 72 passed.
|
Tests finished. 72 tests of 72 passed.
|
||||||
Compiled as DEBUG
|
Compiled as DEBUG
|
||||||
Test suite pass at GMT Wed Dec 13 16:04:52 2023
|
Test suite pass at GMT Sun Dec 31 17:50:49 2023
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user