drawIndexedTriangleFan()

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
maverickbu
Posts: 17
Joined: Tue Dec 05, 2006 5:07 pm

drawIndexedTriangleFan()

Post by maverickbu »

Can someone point me to a good example and explanation of the drawIndexedTriangleFan() method? I see that the drawIndexedTriangleList() is used in the Customer Scene Node tutorial, but I don't fully understand all the arguments, particularly how the indices are assigned. Thanks alot.

<butt-kissing>Just wanted to add that from a C++ programmer with ZERO graphics experience, Irrlicht has been fantastic in the past few months I've used it. It really lets you dive in and get started.</butt-kissing>
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

For those who don't know, the index buffer is an array of integers that is used to index into the vertex buffer. It is how you describe the relationship between vertices on a mesh.

For a triangle list, the index buffer will have 3 indices for every triangle. Those indices describe the corners of the triangle as well as the 'winding order'. The winding order tells the graphics card which side of the triangle is front facing and which side is back facing. This is used to do back-face culling.

For a triangle fan, the index buffer will have 2 initial indices, plus one additional index for every triangle. The first index in a fan is the 'center', and the second index is used to indicate the first 'edge' of the fan. All triangles in the fan will share the center vertex and the last edge. The next vertex will finish off the first triangle, and the active edge of the fan will be the one between the center and the last specified vertex. This repeats for every index after the first two.

A triangle strip is very similar to a triangle fan, the difference being that the strip uses the last two vertices instead of the first and last vertices.

It is probably best to just look elsewhere for a description. It is explained well in many other places, they usually include graphics...

triangle fan
triangle strip
maverickbu
Posts: 17
Joined: Tue Dec 05, 2006 5:07 pm

Post by maverickbu »

Thanks vitek. Your advice has lead me to the more fitting drawVertexPrimitiveList() method. Unfortunately, I need to upgrade to Irrlicht 1.2 for that (I'm currently using the 1.1 SDK). Hopefully it goes smoothly. I'm using this method to draw a 3D line (but need more flexibility then the draw3DLine() function offers). If I should be doing it another way, I'm open to advice. Thanks again.
maverickbu
Posts: 17
Joined: Tue Dec 05, 2006 5:07 pm

Post by maverickbu »

OK, successfully updated. As you may be able to surmise from the time between my last post and this one, the update went rather easily. :wink:

And if drawVertexPrimitiveList() with EPT_LINE_STRIP in a custom scene node (need the node for holding other information) is overkill for a 3D line I need to be able to resize, color, thicken, and move, let me know what a better alternative is.
zenaku
Posts: 212
Joined: Tue Jun 07, 2005 11:23 pm

Post by zenaku »

From CCubeSceneNode.cpp

Code: Select all

	u16 u[36] = {   0,2,1,   0,3,2,   1,5,4,   1,2,5,   4,6,7,   4,5,6, 
            7,3,0,   7,6,3,   9,5,2,   9,8,5,   0,11,10,   0,10,7};


	Vertices[0]  = video::S3DVertex(0,0,0, -1,-1,-1, video::SColor(255,255,255,255), 0, 1); 
	Vertices[1]  = video::S3DVertex(1,0,0,  1,-1,-1, video::SColor(255,255,255,255), 1, 1); 
	Vertices[2]  = video::S3DVertex(1,1,0,  1, 1,-1, video::SColor(255,255,255,255), 1, 0); 
	Vertices[3]  = video::S3DVertex(0,1,0, -1, 1,-1, video::SColor(255,255,255,255), 0, 0); 
	Vertices[4]  = video::S3DVertex(1,0,1,  1,-1, 1, video::SColor(255,255,255,255), 0, 1); 
	Vertices[5]  = video::S3DVertex(1,1,1,  1, 1, 1, video::SColor(255,255,255,255), 0, 0); 
	Vertices[6]  = video::S3DVertex(0,1,1, -1, 1, 1, video::SColor(255,255,255,255), 1, 0); 
	Vertices[7]  = video::S3DVertex(0,0,1, -1,-1, 1, video::SColor(255,255,255,255), 1, 1); 
	Vertices[8]  = video::S3DVertex(0,1,1, -1, 1, 1, video::SColor(255,255,255,255), 0, 1); 
	Vertices[9]  = video::S3DVertex(0,1,0, -1, 1,-1, video::SColor(255,255,255,255), 1, 1); 
	Vertices[10] = video::S3DVertex(1,0,1,  1,-1, 1, video::SColor(255,255,255,255), 1, 0); 
	Vertices[11] = video::S3DVertex(1,0,0,  1,-1,-1, video::SColor(255,255,255,255), 0, 0); 

...


void CTestSceneNode::render()
{
	/*
        011         111
          /6--------/5        y
         /  |      / |        ^  z
        /   |     /  |        | /
    010 3---------2  |        |/
        |   7- - -| -4 101     *---->x
        |  /      |  /
        |/        | /
        0---------1/
       000       100       
	*/

	video::IVideoDriver* driver = SceneManager->getVideoDriver();

	driver->setMaterial(Material);

	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
	
	  driver->drawIndexedTriangleList(&Vertices[0], 12, &Indices[0], 12);
}


In the indices list (u[36]) , 0,1,2 and 0,3,2 represent two triangles that make up the front face of the cube. You see how that works? Each face of the cube is made up of two triangles. With 6 sides to a cube you end up with 12 triangles.

Each number in the list of indices is an index into the vertex array. 0,3,2 tells irrlicht to use Vertices[0], Vertices[3], and Vertices[2] to represent each point of that triangle.

I'm kind of a 3d n00b myself so someone correct me if I'm wrong :)
-------------------------------------
IrrLua - a Lua binding for Irrlicht
http://irrlua.sourceforge.net/
Post Reply