我正在嘗試創建一個基於體素的遊戲,並且渲染了數百萬個立方體。分組網格上的食人魔碰撞檢測?
爲了加快渲染速度,我將多維數據集分組爲多個塊,將32x32x32多維數據集分組爲一個網格。這是爲了減少對GPU的渲染調用次數並提高幀速率。
我正在使用ManualObject來建立塊,它的工作原理完美。但是,現在的問題是,由於各個塊不是與個別場景節點相關的實體,所以我找不到一種方法來執行碰撞檢測。
食人魔是否有辦法單獨使用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();
}
Ogre3D是一個渲染引擎;它不會進行碰撞檢測。 –
食人魔有他們自己的論壇,我親自使用,他們非常好。我會對你的問題表示贊成 –
哦,對,我也會在Ogre論壇上發表。 @NicolBolas,的確如此。我只是根據他們在他們的維基上的一些Ogre教程來制定個別實體的碰撞檢測。我認爲,因爲他們可以爲實體做這件事,那麼也許他們會爲我正在做的事情做出類似的事情。 –