PDA

View Full Version : Arbitrarily positioned view planes



ThomasHarte
05-12-2001, 01:15 PM
For my program, I wish to have the viewer positioned at a point, and the view plane completely arbitrarily positioned in front of the viewer - i.e. the vector from the viewer to the point on the plane that would be mapped to the centre of a window is not necessarily perpendicular to the plane, and the effective shape of the window in world space is not necessarily rectangular.

The information I have is the location of the viewer and four vertices making up the corners of what should be mapped to the frame buffer. Can anyone help with how I should instruct OpenGL of this information? Presumably I'll want to adjust both perspective and modelview matrices?

ffish
05-13-2001, 03:05 AM
Have you got the red book? I always use glFrustum(left, right, bottom, top, zNear, zFar); to set up my viewing volume. I normally have symmetrical viewing volumes, but you don't have to. If that doesn't do what you want, from Appendix F or the red book, the matrix that glFrustum(l, r, b, t, n, f) generates looks like this:


m[0] = 2n/(r-l);
m[5] = 2n/(t-b);
m[8] = (r+l)/(r-l);
m[9] = (t+b)/(t-b);
m[10] = -(f+n)/(f-n);
m[11] = -1;
m[14] = -2fn/(f-n);
All the rest are 0's. Note that the matrix is in OpenGL column-major format. If you can be bothered deciphering the matrix, you can probably change it to suit your purposes. That's then set up as the GL_PROJECTION_MATRIX.

ThomasHarte
05-15-2001, 09:39 AM
Okay, but that still assumes that the rectangular view window is being mapped onto a rectangular shape in the 3d world, whereas I have an arbitrary planar quadrilatteral.

E.g. imagine if you drew a quad non straight on, then used the shape projected by that onto a normal view shape as the new view shape - i.e. you could achieve the same effect by drawing the scene, using the framebuffer to texture copy command, then mapping the texture to a single perpendicular polygon which doesn't have the (clockwise) texture co-ordinates set to (0, 0), (1, 0), (1, 1), (0,1). Which is a solution to my problem, but a really awful one.

john
05-15-2001, 04:25 PM
Howdy,

yep, yep. I know what you want to do, and I think I know why. <nods wisely> =)

er, I don't know how to do it off the top of my head, *BUT* the Multiple-Pipe-Utility library uses this trick, too. Find it; download the source.

Ack, i lie; it's changed it's name. http://www.sgi.com/software/multipipe/sdk/ should be it.

(for the uninitiated: I think the poster wants to project onto a plane not orthogonal to the optical axis for use in head-tracked VR stuff. If you think about someone'e head wavering in front of a monitor or wall, then the optical centre is the user's eyes, but the near plane maps to the screen....)

hope this helps,

cheers,
John