PDA

View Full Version : map 3d point to 2d screen coordinates manually



holyburak
09-30-2003, 06:53 AM
hi!

i wrote a function to map 3d(x,y,z) points to 2d screen coordinates manually by 'glGet'ting the modelview,projection matrices (by import ing TransformVertices() in DirectX VB sample to OpenGL)but does not work correct.
Do you have one?

Thanks in advance for your interest.
Burak.

roffe
10-02-2003, 09:51 PM
// Perspective to window coords
v' = ModelViewM * v3d (eye-space transform)
v' = ProjM * v' (clip-space transform)
v'.xy = v'.xy/v'.w (perspective divide)
v'.x = (v'.x + 1)*windowWidth/2 (window transform)
v'.y = (v'.y + 1)*windowHeight/2
v2d = v'.xy