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();
}
}
如果需要更多信息,我可以发布屏幕截图。
有建议吗?谢谢。
解决方案
听起来您的模型在剪裁平面外面有顶点。有一些解决方案。
1)缩小模型的规模,使所有顶点都适合夹子坐标(使用 glScale()
)
2)使用Gluperspective设置具有更深层面平面的“相机”。尽管您已经尝试过,但我怀疑您的不需要结果是因为您在使用此调用时不会修改投影矩阵。尝试:
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 60, 1, 0.1, 1000.0 );
3)使用 glFrustrum()
修改剪裁飞机。这类似于gluperspective,但在昂贵的一些复杂性方面提供了更大的灵活性。
仅在模型视图矩阵模式下,您仍然可以使用gluperspective或glfrustrum,但请记住,您进行这些调用和其他矩阵转换呼叫的顺序(例如,Glscale,Glscale,Gltranslate,Glrotate)很重要。
其他提示
反而尝试:gluperspective(60、1、0.1、1000);
不隶属于 StackOverflow