Basic Geometry Classes
-
- Posts: 14
- Joined: Thu Feb 24, 2005 5:51 pm
Basic Geometry Classes
I am relativly new to the irrlicht engine and noticed the lack of basic geometry primatives apart from the CTestSceneNode so I am going to try to make up a set of geometry classes not currently included. I will try to make Cylinder, Cone, Sphere with a level of detail and a Basic LOD terrain Class I hope these will be of use to some people. I will post the source of the classes to this thread and would be happy to hear of any errors or improvements anyone else may have.
-
- Posts: 14
- Joined: Thu Feb 24, 2005 5:51 pm
Cylinder class
Code: Select all
class CylSampleSceneNode : public scene::ISceneNode
{
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[200];
video::SMaterial Material;
int Detail;
public:
CylSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,int detail)
: scene::ISceneNode(parent, mgr, id)
{
Material.Wireframe = false;
Material.Lighting = false;
Detail = detail;
//base vertex
Vertices[0] = video::S3DVertex(0,-10,0, 0,-1,0, video::SColor(255,255,255,255), 0, 1);
int i;
float I;
float Angle;
Angle = 360/Detail;
int uv;
uv = 0;
//get the base vertexies
for (i=0;i<(Detail+1);i++)
{
I = i;
if (uv == 0)
{
Vertices[i+1] = video::S3DVertex((sin(I*Angle*Pi/180))*10,-10,(cos(I*Angle*Pi/180))*10, (sin(I*Angle*Pi/180)),-1,(cos(I*Angle*Pi/180)), video::SColor(255,255,255,255), 0, 0);
uv = 1;
}
else
{
Vertices[i+1] = video::S3DVertex((sin(I*Angle*Pi/180))*10,-10,(cos(I*Angle*Pi/180))*10, (sin(I*Angle*Pi/180)),-1,(cos(I*Angle*Pi/180)), video::SColor(255,255,255,255), 1, 1);
uv = 0;
}
}
uv = 0;
//get top vertex
Vertices[Detail+1] = video::S3DVertex(0,10,0, 0,1,0 , video::SColor(255,255,255,255), 0, 0);
//get the top vertexies
for (i=0;i<(Detail+1);i++)
{
I = i;
if (uv == 0)
{
Vertices[i+1+Detail+1] = video::S3DVertex((sin(I*Angle*Pi/180))*10,10,(cos(I*Angle*Pi/180))*10, (sin(I*Angle*Pi/180)),1,(cos(I*Angle*Pi/180)), video::SColor(255,255,255,255), 1, 0);
uv = 1;
}
else
{
Vertices[i+1+Detail+1] = video::S3DVertex((sin(I*Angle*Pi/180))*10,10,(cos(I*Angle*Pi/180))*10, (sin(I*Angle*Pi/180)),1,(cos(I*Angle*Pi/180)), video::SColor(255,255,255,255), 0, 1);
uv = 0;
}
}
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<12; ++i)
Box.addInternalPoint(Vertices[i].Pos);
}
virtual void OnPreRender()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnPreRender();
}
virtual void render()
{
int i;
u16 Indices[200];
//draw base
for (i=0;i<(Detail-1);i++)
{
Indices[(i*3)] = 0;
Indices[(i*3)+1] = i+2;
Indices[(i*3)+2] = i+1;
}
//draw top
for (i=0;i<(Detail-1);i++)
{
Indices[(i*3)+(3*Detail)] = Detail+1;
Indices[(i*3)+1+(3*Detail)] = i+1+Detail+1;
Indices[(i*3)+2+(3*Detail)] = i+2+Detail+1;
}
//draw side 1
for (i=0;i<(Detail-1);i++)
{
Indices[(i*3)+(3*Detail)+(3*(Detail-1))] = i+1;
Indices[(i*3)+1+(3*Detail)+(3*(Detail-1))] = i+2+Detail+1;
Indices[(i*3)+2+(3*Detail)+(3*(Detail-1))] = i+1+Detail+1;
}
//draw side 1
for (i=0;i<(Detail-1);i++)
{
Indices[(i*3)+(3*Detail)+(6*(Detail-1))] = i+2+Detail+1;
Indices[(i*3)+1+(3*Detail)+(6*(Detail-1))] = i+1;
Indices[(i*3)+2+(3*Detail)+(6*(Detail-1))] = i+2;
}
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 2*(Detail+1), &Indices[0], 2*(Detail)-1+2*(Detail-1));
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual s32 getMaterialCount()
{
return 1;
}
virtual video::SMaterial& getMaterial(s32 i)
{
return Material;
}
};
-
- Posts: 14
- Joined: Thu Feb 24, 2005 5:51 pm
Cylinder class
The class for a cylinder
Code: Select all
class CylSampleSceneNode : public scene::ISceneNode
{
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[200];
video::SMaterial Material;
int Detail;
public:
CylSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,int detail)
: scene::ISceneNode(parent, mgr, id)
{
Material.Wireframe = false;
Material.Lighting = false;
Detail = detail;
//base vertex
Vertices[0] = video::S3DVertex(0,-10,0, 0,-1,0, video::SColor(255,255,255,255), 0, 1);
int i;
float I;
float Angle;
Angle = 360/Detail;
int uv;
uv = 0;
//get the base vertexies
for (i=0;i<(Detail+1);i++)
{
I = i;
if (uv == 0)
{
Vertices[i+1] = video::S3DVertex((sin(I*Angle*Pi/180))*10,-10,(cos(I*Angle*Pi/180))*10, (sin(I*Angle*Pi/180)),-1,(cos(I*Angle*Pi/180)), video::SColor(255,255,255,255), 0, 0);
uv = 1;
}
else
{
Vertices[i+1] = video::S3DVertex((sin(I*Angle*Pi/180))*10,-10,(cos(I*Angle*Pi/180))*10, (sin(I*Angle*Pi/180)),-1,(cos(I*Angle*Pi/180)), video::SColor(255,255,255,255), 1, 1);
uv = 0;
}
}
uv = 0;
//get top vertex
Vertices[Detail+1] = video::S3DVertex(0,10,0, 0,1,0 , video::SColor(255,255,255,255), 0, 0);
//get the top vertexies
for (i=0;i<(Detail+1);i++)
{
I = i;
if (uv == 0)
{
Vertices[i+1+Detail+1] = video::S3DVertex((sin(I*Angle*Pi/180))*10,10,(cos(I*Angle*Pi/180))*10, (sin(I*Angle*Pi/180)),1,(cos(I*Angle*Pi/180)), video::SColor(255,255,255,255), 1, 0);
uv = 1;
}
else
{
Vertices[i+1+Detail+1] = video::S3DVertex((sin(I*Angle*Pi/180))*10,10,(cos(I*Angle*Pi/180))*10, (sin(I*Angle*Pi/180)),1,(cos(I*Angle*Pi/180)), video::SColor(255,255,255,255), 0, 1);
uv = 0;
}
}
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<12; ++i)
Box.addInternalPoint(Vertices[i].Pos);
}
virtual void OnPreRender()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnPreRender();
}
virtual void render()
{
int i;
u16 Indices[200];
//draw base
for (i=0;i<(Detail-1);i++)
{
Indices[(i*3)] = 0;
Indices[(i*3)+1] = i+2;
Indices[(i*3)+2] = i+1;
}
//draw top
for (i=0;i<(Detail-1);i++)
{
Indices[(i*3)+(3*Detail)] = Detail+1;
Indices[(i*3)+1+(3*Detail)] = i+1+Detail+1;
Indices[(i*3)+2+(3*Detail)] = i+2+Detail+1;
}
//draw side 1
for (i=0;i<(Detail-1);i++)
{
Indices[(i*3)+(3*Detail)+(3*(Detail-1))] = i+1;
Indices[(i*3)+1+(3*Detail)+(3*(Detail-1))] = i+2+Detail+1;
Indices[(i*3)+2+(3*Detail)+(3*(Detail-1))] = i+1+Detail+1;
}
//draw side 1
for (i=0;i<(Detail-1);i++)
{
Indices[(i*3)+(3*Detail)+(6*(Detail-1))] = i+2+Detail+1;
Indices[(i*3)+1+(3*Detail)+(6*(Detail-1))] = i+1;
Indices[(i*3)+2+(3*Detail)+(6*(Detail-1))] = i+2;
}
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 2*(Detail+1), &Indices[0], 2*(Detail)-1+2*(Detail-1));
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual s32 getMaterialCount()
{
return 1;
}
virtual video::SMaterial& getMaterial(s32 i)
{
return Material;
}
};
Check out Spintz's geomipmapping terrain scene node (somewhere on these forums plus in IrrlichtNX). Your work may have already been done for you.Basic LOD terrain Class
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.
Crucible of Stars
Crucible of Stars