0

I am trying to recreate the Ogre code used here (in Irrlicht): http://dave.uesp.net/wiki/Block_Land_3

For this part of the code:

MeshChunk->position(x, y,   z+1);   MeshChunk->normal(-1,0,0);  MeshChunk->textureCoord(0, 1);

I did this:

SMesh* Mesh = new SMesh();

SMeshBuffer *buf = 0;
buf = new SMeshBuffer();


Mesh->addMeshBuffer(buf);

buf->drop();

block_t Block;
block_t Block1;

int iVertex = 0;

buf->Vertices.reallocate(3);
buf->Vertices.set_used(3);
....
buf->Vertices[0] = S3DVertex(vector3df(x, y, z+1), vector3df(-1,0,0), SColor(255, 0,0,0), vector2df(0, 1));

But how can this be translated:

MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
Claudiu Claw
  • 893
  • 7
  • 10

1 Answers1

0

This looks like it's adding indices, specifically a set of 3 vertex indexes;

buf->Vertices[0] = S3DVertex(vector3df(x, y, z+1), vector3df(-1,0,0), SColor(255, 0,0,0), vector2df(0, 1));
buf->Vertices[1] = S3DVertex(vector3df(x, y+1, z+1), vector3df(-1,0,0), SColor(255, 0,0,0), vector2df(0, 1));
buf->Vertices[2] = S3DVertex(vector3df(x, y+1, z), vector3df(-1,0,0), SColor(255, 0,0,0), vector2df(0, 1));
buf->Vertices[3] = S3DVertex(vector3df(x, y, z), vector3df(-1,0,0), SColor(255, 0,0,0), vector2df(0, 1));


buf->Indices.push_back(0);
buf->Indices.push_back(1);
buf->Indices.push_back(2);
//MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);

buf->Indices.push_back(2);
buf->Indices.push_back(3);
buf->Indices.push_back(0);
//MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);

Verticies is a list of positions, Indices shows the order in which to use them (based on their position in Verticies).

You can reuse indexes of Verticies if triangles share points - this will make the border between triangles soft if the triangles are not co-planar, or you can create multiple verticies at the same position, allowing for a hard-edge.

salmonmoose
  • 137
  • 2
  • 10