OpenGL:モデルは正しく表示されません。 (描画距離を修正する必要がありますか?)
質問
私はOpenGLに初めてです。私はジョグルと遊んでいます。
ポリゴンとして描画している.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();
}
}
より多くの情報が必要な場合は、スクリーンショットを投稿できます。
何かアドバイス?ありがとう。
解決
モデルにはクリッピングプレーンの外に頂点があるようです。これにはいくつかの解決策があります。
1)すべての頂点がクリップ座標内に収まるようにモデルをスケールダウンします(使用 glScale()
)
2)Gluperspectiveを使用して、より深いクリッピングプレーンを備えた「カメラ」をセットアップします。これを試してみましたが、この呼び出しを使用しているときに投影マトリックスを変更していないため、不要な結果はそうだと思います。試す:
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 60, 1, 0.1, 1000.0 );
3)使用します glFrustrum()
クリッピングプレーンを変更します。これはGluperspectiveに似ていますが、複雑さを高める高価な柔軟性を提供します。
参考までに、ModelView Matrixモードの場合でもGluperspectiveまたはGLFrustrumを使用できますが、それらの呼び出しや他のマトリックス変換呼び出し(Glscale、Gltranslate、Glrotateなど)を作成する順序が重要であることに留意してください。
他のヒント
代わりにこれを試してください:Gluperspective(60、1、0.1、1000);