Need help with view matrix on aplication layer

Hello,

I’m working on code that does what the GL libraries do to the two matrices (like glRotate()), but on the application layer, plus other stuff.

I need help figuring out what I should be looking for to produce the needed function calls as well as knowing which matrix it applies to.

I need the algorithm for glLookAt(), perspective and orthographic. Also does any of those calls involve the projection matrix, or can it all be done in model view?

So far I have rotation, translation and scaling taken care of and now I’m working on view frustum culling. This thread will likely be one where I’ll be asking for pointers (links) to things and I’m hoping this thread turns into a quick reference to anything related to the two matrix for everyone to look up.

gluLookAt() is a model-view, or to be more precise only view transformation. Projection is defined by another matrix, but if you want to combine view and projection in the single matrix, that’s not the problem. Just calculate P*V, where P is a projection matrix and V is a viewing matrix (e.g. matrix generated by gluLookAt).

There are lots of examples on the net how to implement gluLookAt. Take a look, for example, at this:
http://pyopengl.sourceforge.net/documentation/manual/gluLookAt.3G.html

Thanks.

What’s the best approach to taking a mouse position and applying it to 3D space such that it’s D distance away from the plain that is normal to the camera vector of which the camera point lies on that plain? Since the camera isn’t always looking down a particular axis, I’d guess you can’t apply the same “depth” value to the mouse click position. Any suggestions on how to do that?

By unprojecting you can always find where the particular point (beneath the cursor) lies in 3D space.

If you want to move objects around, take a look at this post:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=299871#Post299871

Thanks for the link, I think I have a better idea, but I’m having trouble understanding the z value of the mouse click in relationship to the 3D space and the view frustum.

Use gluUnProject() to convert window coordinates into object coordinates. The value you can get from selection buffer is a normalized depth of minimal or maximal distance vertex. It cannot be used for the clicked fragment depth.

So that’s what I still don’t quite understand… does the value relate to the near and far plain of the view frustum. In the past I’d use the camera point and it’s looking vector and called gluProject() to get the z value and then use the mouse position to call gluUnProject(). If I just want the point z distance in front of the camera, is there a way I can calculate the z value?

Z value can be read from depth buffer by glReadPixels(…,GL_DEPTH_COMPONENT,…). It is a normalized value in the range [0…1] and can be passed to a gluUnProject() to find Z coordinate in the object space, or you can use your own math to find coordinates. Near clip plane corresponds to Z=0, and far clip plane corresponds to Z=1.