定义我的视锥体的代码:
glFrustum(0.0, 50.0, 0.0, 50.0, 5.0, 35.0);
生成多边形和曲线的代码
glBegin(GL_POLYGON); // a rectangle
glVertex3f(20.0, 20.0, -6.0);
glVertex3f(20.0, 20.0, -10.0);
glVertex3f(20.0, 60.0, -10.0); // point A
glVertex3f(20.0, 60.0, -6.0); // point B
glEnd();
glBegin(GL_LINE_STRIP);
for (float i = -PI; i < -PI/3; i += 2 * PI / numSides) {
glVertex3f(X+14*i, Y + sin(i)*R, -6.0);
}
正如您所看到的,即使B点被定义为更接近投影屏幕,它在Oxz平面上的投影也比A点的投影短。这几乎就好像这两个点已经以某种方式切换将相机位置放在它们后面而不是(0,0,0)。谁可以给我解释一下这个?
答案 0 :(得分:0)
你的假设是错误的。点 A 为(20.0,60.0, -6.0 ),点 B 为(20.0,60.0, -10.0 强>)。
使用glFrustum(-60.0, 60.0, -60.0, 60.0, 5.0, 35.0);
获得更好的场景视图,因为平截头体的原点位于窗口的中间,并通过添加前侧和底侧将四边形扩展到立方体,使场景更具空间性:
glFrustum(-60.0, 60.0, -60.0, 60.0, 5.0, 35.0);
glLineWidth( 3.0f );
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
glBegin(GL_POLYGON);
glVertex3f(20.0, 20.0, -6.0);
glVertex3f(60.0, 20.0, -6.0);
glVertex3f(60.0, 60.0, -6.0);
glVertex3f(20.0, 60.0, -6.0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(20.0, 20.0, -6.0);
glVertex3f(60.0, 20.0, -6.0);
glVertex3f(60.0, 20.0, -10.0);
glVertex3f(20.0, 20.0, -10.0);
glEnd();
glColor4f( 0.0f, 0.0f, 0.0f, 1.0f );
glBegin(GL_POLYGON);
glVertex3f(20.0, 20.0, -6.0);
glVertex3f(20.0, 20.0, -10.0);
glVertex3f(20.0, 60.0, -10.0);
glVertex3f(20.0, 60.0, -6.0);
glEnd();
const float PI = 3.1415917f;
static float X = 20.0f + PI *14;
static float Y = 60.0f;
static float R = 20.0f;
int numSides = 30;
glBegin(GL_LINE_STRIP);
for (float i = -PI; i < -PI/3; i += 2 * PI / numSides) {
glVertex3f(X+14*i, Y + sin(i)*R, -6.0);
}
glEnd();
参见图像,洋红色十字标记视点: