• Create Account

# Extracting OpenGL's matrices

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1illuzion  Members   -  Reputation: 122

Like
Likes
Like

Posted 20 September 2001 - 01:34 AM

Hi I have called glScalef(), gl Rotatef() etc. Now what I want to do is both pass a vertex to opengl (which I know how to do, of course) AND (and this is the difficult bit) find out what the transformed vertex coordinates are / would be after passing them through OpenGL - ie, as they are when drawn on the screen. Am I making sense? Other than that, I suppose I could calculate it myself with my own matrix methods. Would it slow down the rendering speed if I did this? - ie, does gl use the video hardware for its maths? And then, of course, there is the little problem of actually writing the functions... like I said, I know very little about matrices. They aren''t in the curriculum for maths where I live at school at all - you don''t do them until uni anyway, thanks. - dave.

### #2davidko  Members   -  Reputation: 122

Like
Likes
Like

Posted 20 September 2001 - 05:25 AM

So you want to the windows coordinates of the vertex? or do want the world coordinates of the transformed vertex?

If you want the windows coordinates, you can use the function gluProject, but you''ll have to supply the various matricies, which you can get by using the glGet functions...

### #3TC  Members   -  Reputation: 122

Like
Likes
Like

Posted 20 September 2001 - 06:26 AM

How OpenGL transforms your vertex into screen space depends on what type of projection transform you set OpenGL to do. You specify OpenGL's project transform by the following:

.
.
glMatrixMode (GL_PROJECTION);
// call to glFrustum(), gluPerspective(), or glOrtho()
.
.

The OpenGL Programer's guide (the "Red Book") describes some of the Matrices that the rotation and project functions use in Appendex F. GameDev has a link to an older online version of the "red book" here http://ask.ii.uib.no/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/

The way OpenGL does the entire transformation from the vertex's local space to screen space is by:

Projection Matrix * Model View Matrix * vertex
where your vertex (x, y, z) is treated as a vector:
|x|
|y|
|z|
|1|

The fourth field of the vector is known as the 'w' field. When your vertex goes through the transformation, OpenGL computes the screen coordinates by the divided x, y and z by w. But before it computes the screen coordinates it must clip the vertex to the view volume you specified by your projection matrix. The clipping boundaries for homogenous coordinates that have been transformed by a projection matrix in OpenGL is
-w <= z >= w
-w <= y >= w
0 <= z >= w

As you can see, trying to trace what OpenGL is going to do to your vertex is a little complicated. I'm guessing you are trying this because you want to be able to identify objects that have been projected on the screen so you can pick objects with your mouse or do something similar to that. If that is what you are trying to do you might want to look at the "Selection and Feedback" chapter of the "red book" to look at a possible alternative.

Edited by - TC on September 20, 2001 8:12:22 PM

Edited by - TC on September 21, 2001 12:53:57 PM

### #4illuzion  Members   -  Reputation: 122

Like
Likes
Like

Posted 20 September 2001 - 05:46 PM

Thanks for the replies.
What I''m actually doing is writing my own lighting routines, so I want to be able to find out where, if I plugged my normal through OpenGL, it would end up being.
Can I get the current state of gl''s matrices somehow? Ie, make a gl call with a paramter of my own matrix structure, and then plug everything through that matrix?

### #5Null and Void  Members   -  Reputation: 1087

Like
Likes
Like

Posted 20 September 2001 - 06:21 PM

You can use glGet to retreive a matrix and glLoadMatrix to put a matrix. But remember that OpenGL will do the matrix math on the GPU if possible, so it''s faster there.

[Resist Windows XP''s Invasive Production Activation Technology!]

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS