2013-02-04 6 views
2

저는 복셀 기반 게임을 만들고 수백만 큐브를 렌더링하는 실험을하고 있습니다.그룹화 된 메쉬에서 오우거 충돌 감지?

렌더링 속도를 높이기 위해 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(); 
} 
+1

Ogre3D는 렌더링 엔진입니다. 그것은 충돌 탐지를하지 않습니다. –

+0

오우거에는 개인적으로 사용했던 포럼이 있으며 아주 좋습니다. 당신의 질문에 예스라고 대답 할 것입니다. –

+0

오, 오우거 포럼에서도이 글을 올리겠습니다. @ NicolBolas 사실입니다. 나는 그들이 위키에 가지고있는 Ogre 튜토리얼의 일부를 벗어나서 개별 개체에 대한 충돌 탐지를 수행했다. 나는 그들이 엔티티에 대해 그렇게 할 수 있었기 때문에 생각했다. 아마 내가하고있는 것에 대해서도 비슷한 것을 가질 수있을 것이다. –

답변

0

저는 총알 물리학 라이브러리를 사용하고 있습니다. 그것은 꽤 좋은 충돌 탐지 시스템처럼 보입니다.

래퍼가 있으며 원래 오우거와 함께 사용하기 위해 작성 되었기 때문에 오우거와 잘 어울립니다.

0

블록을 사용하는 경우 (나는 Minecraft에서와 비슷한 방법으로 생각합니다) 블록 데이터가 저장된 3D 배열을 가질 가능성이 큽니다. 해당 3d 배열의 데이터를 사용하여 무언가가 블록과 충돌했는지 아닌지? 그것은 매우 쉽고 빠를 것입니다.