View Full Version : How to transform a 3d-Point in a 2d-Point??
09-30-2001, 05:56 AM
I have a 3d-Vector/Point with x,y,z and itīs rendered in my 3d-space. But what are the actual 2d-coordinates for this point, after itīs rendered (where I can find it on my screen)??
You mean your 3D point projected in the viewport?
I'm not sure about this, but I think it's like this.
p = (x, y, z, 1) in other words, your 3D point/vector
mv = modelview matrix
pr = projection matrix
vp = projected point in untransformed viewport coordinates
vp = pr * mv * p.
To get real windows space coordinates, you have to scale and offset vp. This is dependand of the size of the viewport.
09-30-2001, 07:12 AM
But, how do I get the modelview matrix, how the viewport matrix and how do i multiply them with my vector??
You can get the modelview matrix with glGetFloatv(GL_MODELVIEW_MATRIX, &mv), where mv is a float mv;. The projection matrix is obtained in the same way, but with GL_PROJECTION_MATRIX.
As for multiplication, well, bah, use gluProject instead http://www.opengl.org/discussion_boards/ubb/biggrin.gif . You pass the modelview- and projectionmatrix, the viewport coordinates, the point, and it will return the projected point. Forgot about it in my first post, it will do the job for you.
10-01-2001, 02:55 AM
Ahhh! Thank you very much! Works well!!!
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.