Hey guys, so I feel stuck here.

Lets forget the movable HUD for a second.  I just want to put a model in the 
center of a plane that covers 25% of the screen:

---------------------+++++++
---------------------+++M+++
---------------------+++++++   (M is the model)
---------------------+++++++   (+ is the Plane)
---------------------+++M+++
---------------------+++++++

So if width of my screen is 1280 then the middle of a plane that covers 25% of 
the screen is at 1120.  (1280 - (1280*0.25)/2)

Using this method which I took from: 

http://forum.openscenegraph.org/viewtopic.php?t=9172 


Code:
osg::Vec3d screenToWorld(const osg::Vec2d& screenPosition, const osg::Camera* 
pCamera)
{
        osg::Vec3d worldPosition;



        if (pCamera != NULL)
        {
                osg::Vec4 screenPositionNear(screenPosition.x(), 
pCamera->getViewport()->height() - screenPosition.y(), 0.0, 1.0);
                osg::Vec4 screenPositionFar(screenPosition.x(), 
pCamera->getViewport()->height() - screenPosition.y(), 1.0, 1.0);


                
                osg::Matrixd iMVPW = 
osg::Matrixd::inverse(pCamera->getViewMatrix() * pCamera->getProjectionMatrix() 
* pCamera->getViewport()->computeWindowMatrix());
                osg::Vec4 worldPositionNear = screenPositionNear * iMVPW;
                osg::Vec4 worldPositionFar = screenPositionFar * iMVPW;

                worldPositionNear = worldPositionNear / worldPositionNear.w();
                worldPositionFar = worldPositionFar / worldPositionFar.w();

                worldPosition.set((worldPositionNear.x() + 
worldPositionFar.x()) / 2.0, (worldPositionNear.y() + worldPositionFar.y()) / 
2.0, (worldPositionNear.z() + worldPositionFar.z()) / 2.0);

        
        }

        return worldPosition;
}



I get the worldPosition.  But the world position when I give 
screenToWorld(Vec2D(1120, 1024), hudCam) I get an output I don't understand:   

worldPosition[0] = 0.75000
worldPosition[1] = -0.5000
worldPosition[2] = 0.0000

How is this world position? It makes sense in a Cartesian coordinate system but 
how do I translate that into positioning my model correctly? The method looks 
good, I've googled and read other threads on screen to world position and they 
seem to follow this way of doing things.  What is going on here?   If I use my 
positionAttitudeTransform to setPosition on the model, it barely moves, because 
at the 1280 x 1024 resolution, that I need about 36 "units" to the right to hit 
the edge of the screen.  So a translation of 0.75, doesn't do much.  


[/code]

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





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

Reply via email to