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.