c++ - opengl c++ 代码中的错误,可能与 cood 系统有关

标签 c++ opengl glut coordinate-systems

如果您需要查看,我已经把所有必要的文件[临时链接已删除]。

mavStar.exe 是我的程序。

目前我正在尝试调试的函数是:

void drawOG() 
{
    int curr,right,back,bottom;
    //Does NOT draw the right most,back most,bottom most layer at the moment
    //Does NOT draw face between state 1 & 2
    for(int z=0;z+1 < occupancyGrid->Nz; z++){
        glPushMatrix();
        for(int y=0;y+1 < occupancyGrid->Ny; y++){
            glPushMatrix();
            for(int x=0;x+1 < occupancyGrid->Nx; x++){
                curr = occupancyGrid->M[x][y][z];
                right = occupancyGrid->M[x+1][y][z];
                back = occupancyGrid->M[x][y][z+1];
                bottom = occupancyGrid->M[x][y+1][z];
                drawCube(RIGHT_FACE,colorBetween(curr,right));
                drawCube(BACK_FACE,colorBetween(curr,back));
                drawCube(BOTTOM_FACE,colorBetween(curr,bottom));
                glTranslatef (HALF_VOXEL_SIZE*2, 0.0, 0.0);
            }
            glPopMatrix();
            glTranslatef (0.0, -HALF_VOXEL_SIZE*2, 0.0);
        }
        glPopMatrix();
        glTranslatef (0.0, 0.0, -HALF_VOXEL_SIZE*2);
    }

}

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    //mouse tracking
    glRotatef(fYDiff, 1,0,0);
    glRotatef(fXDiff, 0,1,0);
    glRotatef(fZDiff, 0,0,1);

    glScalef(fScale, fScale, fScale);

    //draw model
    glMatrixMode(GL_MODELVIEW);
    drawOG();
    printOpenGLError();  // Check for OpenGL errors

    glutSwapBuffers();
}

最佳答案

有一种更简单的方法来绘制你想要的面孔​​:

glPushMatrix();

glBegin(GL_QUADS);

//Draw the 16 vertices with their normals.

glEnd();

glPopMatrix();

例如,如果你想要正面:

glPushMatrix();

glBegin(GL_QUADS);

glColor3f(1.0f,1.0f,1.0f);
glNormal3f(0.0,0.0,1.0);
glVertex3f( position[0],  position[1], position[2]);


glNormal3f(0.0,0.0,1.0);
glVertex3f( position1[0], position1[1], position1[2]);


glNormal3f(0.0,0.0,1.0);
glVertex3f(position2[0], position2[1], position2[2]);


glNormal3f(0.0,0.0,1.0);
glVertex3f(position3[0],  position3[1], position3[2]);

glEnd();

glPopMatrix();

在一张纸上画出这些面孔,找出您需要的 position、position1、position2、position3 等值。为一般用途命名它们,确定它们的坐标应该相当容易。


如果你想给它一点灵 active ,你可以创建一个立方体类,只渲染你设置了标志的女巫的脸。通过使用一个类,您可以控制可渲染对象的显示方式(颜色、位置、比例等)。

关于c++ - opengl c++ 代码中的错误,可能与 cood 系统有关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5537808/

相关文章:

c++ - 递归函数以反向字符串C++

opengl - GLSL 中的顶点着色器属性映射

c++ - 使用现有的 2D 纹理和 glTextureView 初始化立方体贴图

c++ - 鼠标移动opengl

C++ 可变多类型数组

c++ - 从文件中读取多个字节并存储它们以便在 C++ 中进行比较

java - 模型- View - Controller 如何适应 OpenGL 依赖性?

c++ - 使用 C++ 在 OpenGL 中移动自动旋转 3D 多边形

C++加载外部类exe

c++ - 将 SDL 用于 Web 应用程序