PDA

View Full Version : A problem of Frustom



Poma
04-03-2005, 12:27 AM
There is a question about Frustom as follows

Ex. There is a flat ground and the coordinate of its 4 corner are
(4, 0, 4),(-4, 0, 4),(4, 0, -4),(-4, 0, -4),
I want to use glFrustom and set the
near = 1, far = 4,
top = 2, bottom = -2
right= 2, left = -2

after matrix calculation, the 4 points becomes
(2,0,-28/3,-4) (-2,0,-28/3,-4)
(2,0,4,4) (-2,0,4,4)

after homogenizaion :
(-0.5, 0, 7/3, 1) (0.5, 0, 7/3, 1)
(0.5, 0, 1, 1) (-0.5, 0, 1, 1)
I don't understand that can i use this 4 points to raster a correct ground?

dorbie
04-03-2005, 06:35 PM
You have not moved the eye using the modelview matrix.

The eye position will still be at 0,0,0, i.e. exactly in the middle of your floor touching the surface. You will not see anything, all the transformed vertices share y = 0 coords, i.e. the transformed screenspace primitive is degenerate.

After placing your frustum on the projection matric you need to translate teh eye up off the floor using the modelview matrix.

glMatrixMode(GL_MODELVIEW);
glTranslatef(0.0, -1.5, 0.0);

(note the translate is negative because it's the eye you are moving up therefore the model must move down as the inverse equivalent operation)

Either this or move the floor down by setting the y coordinate to something negative, say -1.5.

Poma
04-03-2005, 06:56 PM
Thank you
Maybe this example is not perfect.
What i want to ask is : if the there is a line, one point is in the frustom, and another point is before near plane (EX: its z value is 0), how OpenGL raster this line?
1. multiply the projection matrix then raster the line in 2D mode?
or
2. raster the line in 3D mode then multiply the projection matrix?

(point with z = 0 will be error when multiply projection matrix, right?)