2013-05-14 2 views
-2

У меня возникли проблемы с созданием плоскости (с использованием GL_TRIANGLE) с использованием массивов вершин.Проблемы с моей плоскостью OpenGL

Heres мой код:

float halfW = (getPlaneWidth()/2); 
float halfD = (getPlaneDepth()/2); 

//Generate vertices 
for(int z = halfD; z >= -halfD; z--) 
{ 
    for(int x = -halfW; x <= halfW; x++) 
    { 
     float xV = x * cellWidth; 
     float yV = 0; 
     float zV = z * cellDepth; 

     Vertices.push_back(xV); 
     Vertices.push_back(yV); 
     Vertices.push_back(zV); 

     float xN = xV - getX(); 
     float yN = yV - getY(); 
     float zN = zV - getZ(); 

     setNormals(&xN, &yN, &zN); //Calculate normals 
     Normals.push_back(xN); 
     Normals.push_back(yN); 
     Normals.push_back(zN); 
    } 
} 
//Generate indices 
for(int y = 0; y < getPlaneDepth(); y++) 
{ 
    for(int x = 0; x < getPlaneWidth(); x++) 
    { 
     int curVertex = (x + (y * (getPlaneDepth() + 1))); //Bottom left vertex ID 

     if(curVertex%2 == 0) 
     { 
      Indices.push_back((x) + (y) * (getPlaneDepth()+1)); //Bottom Left 
      Indices.push_back((x+1) + (y) * (getPlaneDepth()+1)); //Bottom Right 
      Indices.push_back((x+1) + (y+1) * (getPlaneDepth()+1)); //Top Right 

      Indices.push_back((x+1) + (y+1) * (getPlaneDepth()+1)); //Top Right 
      Indices.push_back((x) + (y+1) * (getPlaneDepth()+1)); //Top Left 
      Indices.push_back((x) + (y) * (getPlaneDepth()+1)); //Bottom Left 
     } 
     else //reverse triangle 
     { 
      Indices.push_back((x+1) + (y) * (getPlaneDepth()+1)); //Bottom Right 
      Indices.push_back((x) + (y) * (getPlaneDepth()+1)); //Bottom Left 
      Indices.push_back((x) + (y+1) * (getPlaneDepth()+1)); //Top Left 

      Indices.push_back((x) + (y+1) * (getPlaneDepth()+1)); //Top Left 
      Indices.push_back((x+1) + (y+1) * (getPlaneDepth()+1)); //Top Right 
      Indices.push_back((x+1) + (y) * (getPlaneDepth()+1)); //Bottom Right 
     } 
    } 
} 

код прекрасно работает, если ширина и глубина одинаковы, но если они различны, это щурит.

Может ли кто-нибудь увидеть проблему?

Я закодировал это так, чтобы точка поворота находилась посредине плоскости.

+0

«Это завинчивается» как? Какие размеры вы пробовали? Что произойдет, если ширина или глубина нечетного числа? Помогает быть более конкретным. – Grimmy

ответ

1
int curVertex = (x + (y * (getPlaneWidth() + 1))); //Bottom left vertex ID 

    if(curVertex%2 == 0) 
    { 
     Indices.push_back((x) + (y) * (getPlaneWidth()+1)); //Bottom Left 
     Indices.push_back((x+1) + (y) * (getPlaneWidth()+1)); //Bottom Right 
     Indices.push_back((x+1) + (y+1) * (getPlaneWidth()+1)); //Top Right 

     Indices.push_back((x+1) + (y+1) * (getPlaneWidth()+1)); //Top Right 
     Indices.push_back((x) + (y+1) * (getPlaneWidth()+1)); //Top Left 
     Indices.push_back((x) + (y) * (getPlaneWidth()+1)); //Bottom Left 
    } 
    else //reverse triangle 
    { 
     Indices.push_back((x+1) + (y) * (getPlaneWidth()+1)); //Bottom Right 
     Indices.push_back((x) + (y) * (getPlaneWidth()+1)); //Bottom Left 
     Indices.push_back((x) + (y+1) * (getPlaneWidth()+1)); //Top Left 

     Indices.push_back((x) + (y+1) * (getPlaneWidth()+1)); //Top Left 
     Indices.push_back((x+1) + (y+1) * (getPlaneWidth()+1)); //Top Right 
     Indices.push_back((x+1) + (y) * (getPlaneWidth()+1)); //Bottom Right 
    } 

?

+0

Только что увидел это сам, когда я делал некоторые надписи, рад, что вы пришли к такому же выводу – Split

Смежные вопросы