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

发布于 2024-10-30 09:40:56 字数 1569 浏览 5 评论 0原文

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

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();
}

I have put all the necessary files[temp link removed] if you need to have a look.

mavStar.exe is my program.

The function currently I‘m trying to debug is :

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();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半城柳色半声笛 2024-11-06 09:40:56

有一种更简单的方法可以使用以下方法绘制您想要的面:

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< /代码>等出于通用目的而命名它们,应该很容易确定它们的坐标。


如果你想给它一点灵活性,你可以创建一个 Cube 类,并只渲染你设置了标志的女巫的面。通过使用类,您可以对可渲染对象的显示方式(颜色、位置、比例等)进行大量控制。

There is a much easier way to draw the faces you want by using:

glPushMatrix();

glBegin(GL_QUADS);

//Draw the 16 vertices with their normals.

glEnd();

glPopMatrix();

For example if you want the front:

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();

Draw the faces on a piece of paper to figure out what values you need for position,position1,position2,position3,etc. Named them so for general purpose, it should be fairly easy to determine their coordinates.


If you want to give it a touch of flexibility you can create a Cube class and render only the faces for witch you have set a flag to be on. By using a class you gain lots of control on how you want your render-able object to be displayed (color,position,scale, etc).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文