2

I am experimenting with creating a voxel based game and am rendering millions of cubes.

In order to speed up the rendering, I am grouping up the cubes into chunks that group 32x32x32 cubes into one mesh. This is to reduce the number of render calls to the GPU and increase the framerate.

I am using a ManualObject to build up blocks and it works perfectly. However, the problem now is that since the individual blocks are not entities that are tied to individual scenenodes, I cannot find a way to do collision detection.

Does ogre have a way to separately work with submeshes of a ManualObject?

// Build a face with triangles if the face is visible. Don't bother building faces for hidden faces.
void Chunk::createMesh()
{
    begin("BoxColor");

    int iVertex = 0;
    Block *block;
    Block *testingBlock;

    for (int x = 0; x < CHUNK_SIZE.x; ++x)
    {
        for (int y = 0; y < CHUNK_SIZE.y; ++y)
        {
            for (int z = 0; z < CHUNK_SIZE.z; ++z)
            {
                block = m_pBlocks[x][y][z];
                if (block == NULL) 
                {
                    continue;
                }

                    //x-1
                testingBlock = 0;
                if (x > 0) testingBlock = m_pBlocks[x-1][y][z];

                if (testingBlock == 0)
                {
                    position(x, y,   z+1);  normal(-1,0,0); textureCoord(0, 1);
                    position(x, y+1, z+1);  normal(-1,0,0); textureCoord(1, 1);
                    position(x, y+1, z);    normal(-1,0,0); textureCoord(1, 0);
                    position(x, y,   z);    normal(-1,0,0); textureCoord(0, 0);

                    triangle(iVertex, iVertex+1, iVertex+2);
                    triangle(iVertex+2, iVertex+3, iVertex);

                    iVertex += 4;
                }

                    //x+1
                testingBlock = 0;
                if (x < 0 + CHUNK_SIZE.x - 1) testingBlock = m_pBlocks[x+1][y][z];

                if (testingBlock == 0)
                {
                    position(x+1, y,   z);      normal(1,0,0); textureCoord(0, 1);
                    position(x+1, y+1, z);      normal(1,0,0); textureCoord(1, 1);
                    position(x+1, y+1, z+1);    normal(1,0,0); textureCoord(1, 0);
                    position(x+1, y,   z+1);    normal(1,0,0); textureCoord(0, 0);

                    triangle(iVertex, iVertex+1, iVertex+2);
                    triangle(iVertex+2, iVertex+3, iVertex);

                    iVertex += 4;
                }

                    //y-1
                testingBlock = 0;
                if (y > 0) testingBlock = m_pBlocks[x][y-1][z];

                if (testingBlock == 0)
                {
                    position(x,   y, z);        normal(0,-1,0);     textureCoord(0, 1);
                    position(x+1, y, z);        normal(0,-1,0);     textureCoord(1, 1);
                    position(x+1, y, z+1);      normal(0,-1,0);     textureCoord(1, 0);
                    position(x,   y, z+1);      normal(0,-1,0);     textureCoord(0, 0);

                    triangle(iVertex, iVertex+1, iVertex+2);
                    triangle(iVertex+2, iVertex+3, iVertex);

                    iVertex += 4;
                }


                    //y+1
                testingBlock = 0;
                if (y < 0 + CHUNK_SIZE.y - 1) testingBlock = m_pBlocks[x][y+1][z];

                if (testingBlock == 0)
                {
                    position(x,   y+1, z+1);        normal(0,1,0);  textureCoord(0, 1);
                    position(x+1, y+1, z+1);        normal(0,1,0);  textureCoord(1, 1);
                    position(x+1, y+1, z);          normal(0,1,0);  textureCoord(1, 0);
                    position(x,   y+1, z);          normal(0,1,0);  textureCoord(0, 0);

                    triangle(iVertex, iVertex+1, iVertex+2);
                    triangle(iVertex+2, iVertex+3, iVertex);

                    iVertex += 4;
                }

                    //z-1
                testingBlock = 0;
                if (z > 0) testingBlock = m_pBlocks[x][y][z-1];

                if (testingBlock == 0)
                {
                    position(x,   y+1, z);      normal(0,0,-1);     textureCoord(0, 1);
                    position(x+1, y+1, z);      normal(0,0,-1);     textureCoord(1, 1);
                    position(x+1, y,   z);      normal(0,0,-1);     textureCoord(1, 0);
                    position(x,   y,   z);      normal(0,0,-1);     textureCoord(0, 0);

                    triangle(iVertex, iVertex+1, iVertex+2);
                    triangle(iVertex+2, iVertex+3, iVertex);

                    iVertex += 4;
                }


                    //z+1
                testingBlock = 0;
                if (z < 0 + CHUNK_SIZE.z - 1) testingBlock = m_pBlocks[x][y][z+1];

                if (testingBlock == 0)
                {
                    position(x,   y,   z+1);    normal(0,0,1);      textureCoord(0, 1);
                    position(x+1, y,   z+1);    normal(0,0,1);      textureCoord(1, 1);
                    position(x+1, y+1, z+1);    normal(0,0,1);      textureCoord(1, 0);
                    position(x,   y+1, z+1);    normal(0,0,1);      textureCoord(0, 0);

                    triangle(iVertex, iVertex+1, iVertex+2);
                    triangle(iVertex+2, iVertex+3, iVertex);

                    iVertex += 4;
                }
            }
        }
    }

    end();
}
Razor Storm
  • 12,167
  • 20
  • 88
  • 148
  • 1
    Ogre3D is a rendering engine; it doesn't do collision detection. – Nicol Bolas Feb 04 '13 at 21:39
  • Ogre have their own forums that i have personally used and they are very good. off hand i would say yes to your question – Sellorio Feb 04 '13 at 21:40
  • Oh right, I'll post this in the Ogre forums as well. @NicolBolas, that's true. I was just basing this off some of the Ogre tutorials they have on their wiki which had collision detection for individual entities. I thought since they could do that for entities then maybe they would have something similar for what I'm doing as well. – Razor Storm Feb 04 '13 at 21:43

2 Answers2

0

I'm using the bullet physics library. It has what looks like a pretty good collision detection system.

There's a wrapper and since it was originally written for use with Ogre it integrates nicely with Ogre.

Jay
  • 13,803
  • 4
  • 42
  • 69
0

In the case of using blocks (i guess it is similar to how it is done in Minecraft) you most likely have a 3d array where your block data is stored in. What about using the data from that 3d array to determine if something collided with a block or not? It would be fairly easy and fast.