views:

703

answers:

4

I have a question on taking a viewer and their projection plane and how exactly to calculate the projected point that should be created.

EX. Viewer at the origin, looking in the negative Z direction. Projection plane at z = -2. Point (-6,1,-4).

I have seen some websites talking about using similar triangles and some that have a matrix to multiply it by. The problem for me is I don't know how to set either one up.

I would guess that my viewer's point seeing as it is at origin (0, 0, 0, 1). When I search for the perspective projection matrix I find a site that sets up a matrix like this.

1 0 0 0
0 1 0 0
0 0 0 0
0 0 1 0

But seeing as my viewer's point as far as I can tell is at (0, 0, 0, 1) then the projection makes no sense as to how it factors into the equation. That matrix also needs to be adjusted as according to the formula to set it up on this site:
http://www.cs.nps.navy.mil/people/faculty/capps/iap/class2/viewing/projection.html

I just need a little help in figuring this out and what we discussed in class was only using similar triangles which does not make sense to me...

A: 

Consider reading out OpenGL's matrixes, using glGet...() functions, and running the vertex through the relevant matrices yourself. First read up on the details of the transformation pipeline of course, so you know how to apply the matrices, ordering matters a great deal as always.

unwind
A: 

It's not an issue for me to do this in openGL due to the fact that most of the methods I need to use are built in, it's just trying to figure out how and where I need to use the information in my problem. I've been looking into this for a couple of hours now and have a little bit more insight but I still don't understand how I account for the viewer's position. If he is at the origin what assumptions can I make about setting up the transformation matrix?

+1  A: 

The viewer's position is usually not handled through the projection matrix, but the modelview matrix. The projection matrix only handles the transformation from eye-space to clip-space.

Camera transformation is achieved by applying the camera's inverse transformation as the first Matrix on the modelview stack.

Advanced graphics programming using openGL

OpenGL Transformation

heeen
A: 

I talk about the derivation of the (opengl) projection matrix in detail on my site. You can have a look here

http://divineabomination.blogspot.com/2009/12/derivation-of-perspective-matrix-part-1.html

and the second part is available there too from the menu on the right.

Montdidier