Anyway, the more pressing issue now is... well my math is clearly wrong.
Code: Select all
SMesh * cubeSpawner(unsigned int typeID, bool artificial)
{
cout<<"time to make a cube\n";
f32 cubeSize = 5.0f;
video::SColor cubeColour(255,255,255,255);
SMeshBuffer * buffer = new SMeshBuffer();
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};
int vertcount = 0;
int indicescount = 0;
cout<<"starting cube creating loop\n";
for (int x = 0; x < 10; x ++ ){
for (int y = 0; y < 10; y ++ ){
buffer->Vertices.set_used(vertcount + 12);
buffer->Vertices[vertcount++] = video::S3DVertex(0,0,0, -1,-1,-1, cubeColour, 0, 1);
buffer->Vertices[vertcount++] = video::S3DVertex(1,0,0, 1,-1,-1, cubeColour, 1, 1);
buffer->Vertices[vertcount++] = video::S3DVertex(1,1,0, 1, 1,-1, cubeColour, 1, 0);
buffer->Vertices[vertcount++] = video::S3DVertex(0,1,0, -1, 1,-1, cubeColour, 0, 0);
buffer->Vertices[vertcount++] = video::S3DVertex(1,0,1, 1,-1, 1, cubeColour, 0, 1);
buffer->Vertices[vertcount++] = video::S3DVertex(1,1,1, 1, 1, 1, cubeColour, 0, 0);
buffer->Vertices[vertcount++] = video::S3DVertex(0,1,1, -1, 1, 1, cubeColour, 1, 0);
buffer->Vertices[vertcount++] = video::S3DVertex(0,0,1, -1,-1, 1, cubeColour, 1, 1);
buffer->Vertices[vertcount++] = video::S3DVertex(0,1,1, -1, 1, 1, cubeColour, 0, 1);
buffer->Vertices[vertcount++] = video::S3DVertex(0,1,0, -1, 1,-1, cubeColour, 1, 1);
buffer->Vertices[vertcount++] = video::S3DVertex(1,0,1, 1,-1, 1, cubeColour, 1, 0);
buffer->Vertices[vertcount++] = video::S3DVertex(1,0,0, 1,-1,-1, cubeColour, 0, 0);
//buffer->BoundingBox.reset(0,0,0);
for (int i = vertcount - 12; i < vertcount; ++i) {
buffer->Vertices[i].Pos -= vector3df(0.5f, 0.5f, 0.5f);
buffer->Vertices[i].Pos *= cubeSize;
buffer->Vertices[i].Pos += vector3df(x * cubeSize, 0, y * cubeSize);
// buffer->BoundingBox.addInternalPoint(buffer->Vertices[i].Pos);
}
indicescount += 36;
buffer->Indices.set_used(indicescount);
for (s32 i = indicescount - 36; i < indicescount; i+=3) {
buffer->Indices[i] = u[(i) % 36] += x * cubeSize;
buffer->Indices[i + 1] = u[(i + 1) % 36] = 0; //cubeSize;
buffer->Indices[i + 2] = u[(i + 2) % 36] += y * cubeSize;
}
}
}
cout<<"Creating mesh\n";
SMesh * cubeMesh = new SMesh();
cubeMesh->addMeshBuffer(buffer);
cout<<"sending mesh to main function\n";
return cubeMesh;
Or perhaps I just don't understand how Irrlicht handles vertices (I ussually create my meshes by hand, this is more or less my first serious dip into procedural generation as my previous attempts have used the built in cubemesh type which is fine for some things but I intend to have more than cubes so having a solid mesh generator is something I'll have to do)
Now since I only know one cure for incompetence, namely education I would humbly ask for someone to explain why this is happening (and I suspect this is all the code you need as all that happens on the other side is that it dereferences the pointer returned to get the mesh data (the function type is SMesh) and assigns it to a scenenode)