View Full Version : How to transform a 3d-Point in a 2d-Point??

TheBlob

09-30-2001, 04:56 AM

Hi!

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)??

thnx,

Blob

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.

TheBlob

09-30-2001, 06:12 AM

Well, Thanks.

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[16];. 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.

TheBlob

10-01-2001, 01:55 AM

Ahhh! Thank you very much! Works well!!!

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.