Creating a cube (12 verts?)

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
[DEF]
Posts: 17
Joined: Thu Jul 29, 2010 8:30 am

Creating a cube (12 verts?)

Post by [DEF] »

So I see many cube meshes using 12 verts:

buffer->Vertices.set_used(12);
buffer->Vertices[0] = video::S3DVertex(0,0,0, -1,-1,-1, cubeColour, 0, 1);
buffer->Vertices[1] = video::S3DVertex(1,0,0, 1,-1,-1, cubeColour, 1, 1);
buffer->Vertices[2] = video::S3DVertex(1,1,0, 1, 1,-1, cubeColour, 1, 0);
buffer->Vertices[3] = video::S3DVertex(0,1,0, -1, 1,-1, cubeColour, 0, 0);
buffer->Vertices[4] = video::S3DVertex(1,0,1, 1,-1, 1, cubeColour, 0, 1);
buffer->Vertices[5] = video::S3DVertex(1,1,1, 1, 1, 1, cubeColour, 0, 0);
buffer->Vertices[6] = video::S3DVertex(0,1,1, -1, 1, 1, cubeColour, 1, 0);
buffer->Vertices[7] = video::S3DVertex(0,0,1, -1,-1, 1, cubeColour, 1, 1);
buffer->Vertices[8] = video::S3DVertex(0,1,1, -1, 1, 1, cubeColour, 0, 1);
buffer->Vertices[9] = video::S3DVertex(0,1,0, -1, 1,-1, cubeColour, 1, 1);
buffer->Vertices[10] = video::S3DVertex(1,0,1, 1,-1, 1, cubeColour, 1, 0);
buffer->Vertices[11] = video::S3DVertex(1,0,0, 1,-1,-1, cubeColour, 0, 0);

Why are there 12? When a cube has 8 points :S what are these last 4 points used for?
buffer->Vertices[8] = video::S3DVertex(0,1,1, -1, 1, 1, cubeColour, 0, 1);
buffer->Vertices[9] = video::S3DVertex(0,1,0, -1, 1,-1, cubeColour, 1, 1);
buffer->Vertices[10] = video::S3DVertex(1,0,1, 1,-1, 1, cubeColour, 1, 0);
buffer->Vertices[11] = video::S3DVertex(1,0,0, 1,-1,-1, cubeColour, 0, 0);
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Redundant vertices are needed for the texture to be interpolated across each face properly. Otherwise you'd see the texture mirrored when it shouldn't be.
[DEF]
Posts: 17
Joined: Thu Jul 29, 2010 8:30 am

Post by [DEF] »

OH this makes sense! xD thanks :D
Post Reply