我有这个功能,它在屏幕的左下角绘制一个小的 3D 轴坐标系,但根据我面前的东西,它可能会被剪裁。
例如,我在 Y = 0 处的 XZ 平面上绘制了地面上的平原地形。相机位于 Y = 1.75 上(模拟人的平均身高)。如果我向上看,它工作正常,如果我向下看,它会被地平面夹住。
向上看:http : //i.stack.imgur.com/Q0i6g.png
向下看:http: //i.stack.imgur.com/D5LIx.png
我调用的在拐角处绘制轴系的函数是这样的:
void Axis3D::DrawCameraAxisSystem(float radius, float height, const Vector3D rotation) {
if(vpHeight == 0) vpHeight = 1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, vpWidth, vpHeight);
gluPerspective(45.0f, 1.0 * vpWidth / vpHeight, 1.0f, 5.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f);
glRotatef(-rotation.x, 1.0f, 0.0f, 0.0f);
glRotatef(-rotation.y, 0.0f, 1.0f, 0.0f);
DrawAxisSystem(radius, height);
}
现在有几个我认为与该问题相关的主要功能:
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
void changeSize(int width, int height) {
if(height == 0) height = 1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, width, height);
gluPerspective(60.0f, 1.0 * width / height, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
}
void renderScene(void) {
glClearColor(0.7f, 0.7f, 0.7f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
changeSize(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
glLoadIdentity();
SceneCamera.Move(CameraDirection, elapsedTime);
SceneCamera.LookAt();
SceneAxis.DrawCameraAxisSystem(0.03f, 0.8f, SceneCamera.GetRotationAngles());
glutSwapBuffers();
}
建议?