It sounds like you are trying to draw a 2D element at the same window
position as a 3D object. Is this correct?

If you are going to project all the way to window coordinates, then you'll
need to configure your projection matrix to render in window coordinates.
You'd need two Camera nodes for this, one with your 3D projection and one
for 2D.

Another approach would be to just project down to eye coordinates (instead
of all the way to window coordinates) and continue to use the same
projection matrix. The disadvantage of this approach is that your 2D
rendering would not be in Window coordinates.

To code tasks like these proficiently, you would be well-advised to
familiarize yourself with the OpenGL transformation pipeline. From your
posts, it seems apparent that you don't have a good mastery of this topic.
Get the OpenGL red book.

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Hagen
Sent: Tuesday, April 21, 2009 2:56 AM
To: [email protected]
Subject: Re: [osg-users] 3D Point to ScreenSpace Coordinates

Thank you for those  two answers.

I forgot to say the point is in world coordinates so the first
transformation should be obsolete for me.

Then I did the following very simple where POSITION is the vector of the
point and ssc is the result.



Code:

osg::Camera* cam = this->viewer->getCamera();
                                osg::Matrix viewMatrix =
cam->getViewMatrix();
                                osg::Matrix projectionMatrix =
cam->getProjectionMatrix();
                                osg::Matrix windowMatrix =
cam->getViewport()->computeWindowMatrix();
                                osg::Matrix cameraMatrix = viewMatrix *
projectionMatrix * windowMatrix; 
                                osg::Vec3 ssc = POSITION*cameraMatrix;
        
pos->setPosition(osg::Vec3(ssc.x(),ssc.y(),0));




As you can see I give the the result to PositionAttitudeTransform.
This PAT is attached to a slave cam with ABSOLUTE_RF This way I can have HUD
(2D) elements following nodes in 3d.

Problem: The accuracy is not very well.
Moving th camera my HUD element is never exactly where it i supposed to be
but just somwhere around the  supposed area.

Could that be float and double problems?
If so: How can I make OSG do eighter everything or just the above
calculation in double) Or do you have another idea why this problem appears?

Greetings
 Hagen

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10496#10496





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to