0

我是 OpenGL 的新手。我在玩 JOGL。

我有一个 .obj 模型,我将其绘制为多边形。看起来不错,只是大部分都被剪掉了。所以我认为我需要增加绘制距离。

我不确定该怎么做。这是我的渲染代码:

private void render(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
        GLUgl2 glu = new GLUgl2();

        gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

        gl.glMatrixMode(GL2.GL_MODELVIEW);
        gl.glLoadIdentity();

        // Position the camera
        glu.gluLookAt(cameraPos.x, cameraPos.y, cameraPos.z, cameraPos.x
                + cameraForward.x, cameraPos.y + cameraForward.y, cameraPos.z
                + cameraForward.z, cameraUp.x, cameraUp.y, cameraUp.z);

            // uncommenting out this line will make everything disappear.
        // glu.gluPerspective(2, 1, 10, 1000);

        // ****** Start of example code ******
        gl.glCallList(axes); // Show X, Y, Z axes

        gl.glCallList(secondLines);

        gl.glCallList(triangle);

        gazebo.render(gl);

                // ...

我的问题可能完全是另外一回事。gazebo是 type ObjModel,一个读取和表示.obj文件的类。以下是它的渲染和构建绘制列表方法:

private int drawID = 0;

public ObjModel(String fn, GL2 gl) {

            // ...

    readFile(fn);

    drawID = buildDrawList(gl);
}

public void render(GL2 gl) {
    gl.glCallList(drawID);
}

private int buildDrawList(GL2 gl) {
    int result = gl.glGenLists(1);

    gl.glNewList(result, GL2.GL_COMPILE);
    gl.glPushMatrix();
    gl.glBegin(GL2.GL_POLYGON);

    for (Point3f vert : vertices) {
        gl.glVertex3f(vert.x, vert.y, vert.z);
    }

    gl.glEnd();
    gl.glPopMatrix();
    gl.glEndList();

    return result;
}

private void readFile(String filename) {
    try {
        BufferedReader input = new BufferedReader(new FileReader(fileName));
        try {
            String newLine = null;
            while ((newLine = input.readLine()) != null) {

                int indVn = newLine.indexOf("vn ");
                if (indVn != -1) {
                    readNormal(newLine);
                    continue;
                }

                int indV = newLine.indexOf("v ");
                if (indV != -1) {
                    readVertex(newLine);
                    continue;
                }

                int indF = newLine.indexOf("f ");
                if (indF != -1) {
                    readPolygon(newLine);
                    continue;
                }

                int indVt = newLine.indexOf("vt ");
                if (indVt != -1) {
                    readTexture(newLine);
                    continue;
                }
            }
        } finally {
            input.close();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

如果需要更多信息,我可以发布屏幕截图。

有什么建议吗?谢谢。

4

2 回答 2

3

听起来您的模型在剪裁平面之外有顶点。有一些解决方案。

1)缩小模型,使所有顶点都适合剪辑坐标(使用glScale()

2) 使用 gluPerspective 设置一个具有更深剪切平面的“相机”。尽管您已经尝试过,但我怀疑您不需要的结果是因为您在使用此调用时没有修改投影矩阵。尝试:

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 60, 1, 0.1, 1000.0 );

3)glFrustrum()用于修改剪裁平面。这类似于 gluPerspective,但提供了更大的灵活性,但代价是增加了一些复杂性。

仅供参考,您仍然可以在模型视图矩阵模式下使用 gluPerspective 或 glFrustrum,但请记住,您进行这些调用和其他矩阵转换调用(例如 glScale、glTranslate、glRotate)的顺序很重要。

于 2010-09-18T23:40:52.070 回答
0

试试这个:gluPerspective(60, 1, 0.1, 1000);

于 2010-09-13T12:29:08.017 回答