I'm playing around with openGL and encounter a strange problem.
Code that defines my frustum:
glFrustum(0.0, 50.0, 0.0, 50.0, 5.0, 35.0);
Code that generates the polygon and the curve
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);
}
As you can see, even though point B is defined to be closer to the projection screen, its projection onto the Oxz plane is shorter than that of point A. It's almost as if the two points have somehow switched place or that the camera location is behind them and not at (0, 0, 0). Can someone explain this to me?
Your assumption is wrong. Point A is at (20.0, 60.0, -6.0) and Point B is at (20.0, 60.0, -10.0).
Use glFrustum(-60.0, 60.0, -60.0, 60.0, 5.0, 35.0);
to get a better view of the scene, because then the origin of the frustum is in the middle of the window, and extend the quad to a cube, by adding the front and bottom side, to make the scene more spatial:
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();
See the image, where the magenta cross marks the point of view: