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タイプは、ファイル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 に答える