且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用opengl显示3D点

更新时间:2023-11-09 22:46:46

reshape 函数中,您将***面和远平面分别设置为 1.0 和 20.0:

In the reshape function you set a near and far plane of 1.0, respectively 20.0:

gluPerspective(65.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);

所有不在***面和远平面之间的几何体都被剪裁.

All the geometry which is not in between the near and the far plane is clipped.

这意味着从点到视点(眼睛坐标)的 z 距离必须在 1.0 到 20.0 的范围内.

This means that z distance from the point to the point of view (eye coordinate) has to be in the range from 1.0 to 20.0.

点的z坐标为0.0:

glVertex3f(-120.0, 25.0, 0.0);

视点(相机)的 z 坐标也是 0.0(gluLookAt):

The z coordinate of the point of view (camera) is 0.0 too (3rd parameter of gluLookAt):

gluLookAt(-120, 25, 0.0, -120, 25, 150, 0, 1, 0);

这会导致视点(眼睛)与点之间的距离为0-0 = 0 并且该点被裁剪.

This causes that the distance between the point of view (eye) and the point is 0-0 = 0 and the point is clipped.

要解决这个问题,要么你必须改变点的z坐标:

To solve the issue, either you have to change the z coordinate of the point:

glVertex3f(-120.0, 25.0, 5.0);

或观点:

gluLookAt(-120, 25, -5.0, -120, 25, 150, 0, 1, 0);