[osg-users] OSG world coordinates to 2D screen coordinates

400 views
Skip to first unread message

Luke Rice

unread,
Jul 22, 2010, 12:25:11 PM7/22/10
to osg-...@lists.openscenegraph.org
Hi, I'm using OSG as part of a VR software package and I'm trying to implement picking with a 6DOF tracking system.

I'm having trouble finding a way to convert the position of my tracking object (right now just a sphere) from its world coordinates to screen coordinates so I can use the xy coordinates to pick with.

I'm porting my environment over from a normal monitor setup (where I can use a mouse for picking and already have all the code written) to a 3 sided cave setup where a mouse does not work.

Im thinking of a hacky way to do it that I think would work if I knew how osg normalized mouse coordinates with osg::GUIEventAdapter::getXnormalized(), but I cannot for the life of me find the code for that function.

If anyone knows of a method to convert world coordinates back to screen coordinates without having to totally reimplement my picking system, that would be great. If anyone can point me to the code for getXnormalized or the method used (I've found some - but they don't lead to the exact same result), that would be great as well.

Thanks!

Luke

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

_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Jean-Sébastien Guay

unread,
Jul 23, 2010, 8:46:05 AM7/23/10
to osg-...@lists.openscenegraph.org
Hi Luke,

> [...] osg::GUIEventAdapter::getXnormalized(), but I cannot for the life of me find the code for that function.

It's directly in the header (include/osgGA/GUIEventAdapter):

inline float getXnormalized() const { return
2.0f*(getX()-getXmin())/(getXmax()-getXmin())-1.0f; }

> If anyone knows of a method to convert world coordinates back to screen coordinates without having to totally reimplement my picking system, that would be great. If anyone can point me to the code for getXnormalized or the method used (I've found some - but they don't lead to the exact same result), that would be great as well.

Search the archives, I answered the opposite of this question not long
ago (how to convert a screen position to a world space position), which
should be easy to reverse to find out what you want to.

I'll even make it real easy for you:

http://thread.gmane.org/gmane.comp.graphics.openscenegraph.user/59941/focus=59966

But you'll have to do the work of taking those calculations and
reversing them to get from world space to screen space.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/

Luke Rice

unread,
Jul 23, 2010, 5:29:12 PM7/23/10
to osg-...@lists.openscenegraph.org
Thanks a lot Jean, that was exactly what I needed. I actually read this first thing this morning but was so excited to get started on it I forgot to reply and thank you.

Luke

------------------
Read this topic online here:

http://forum.openscenegraph.org/viewtopic.php?p=30225#30225

Reply all
Reply to author
Forward
0 new messages