Hi everyone,

I am working on a system to drag and drop shapes into the scenegraph in a Qt 
application. I have the ability to drag shapes from a list widget into the 
QOSGWidget and then render the shape at (0, 0, 0). What I would like to do is 
modify this to attach the shape to the mouse so the user can place the shape 
where they want instead of just plopping it at the origin. I'm using a 
GUIEventHandler to get the mouse position of the drop, then I am trying to 
covert the mouse coordinates into the scenegraph world coordinates. I've 
managed to get this working because I am right now rendering dummy spheres and 
they show up directly under the mouse. However, I would like to be able to have 
the coordinate be modified so the y-position is always at zero so the shapes 
are being drug in the xz plane. This would make a lot more sense to a user when 
the place the shape. I just can't figure out how to take my world space 
coordinate, zero out the y-position, and modify the xz values so that the sp
 heres still show up under the mouse.

Here's the code I'm using to convert the mouse position into world coordinates:


Code:

v3 mousePos(ea.getX(), _widgetHeight - ea.getY(), 0.0f);
osg::Matrix viewMatrix = viewer->getCamera()->getViewMatrix();
osg::Matrix projectionMatrix = viewer->getCamera()->getProjectionMatrix();
osg::Matrix windowMatrix = 
viewer->getCamera()->getViewport()->computeWindowMatrix();
osg::Matrix cameraMatrix = viewMatrix * projectionMatrix * windowMatrix;
osg::Matrix inverseCameraMatrix;
inverseCameraMatrix.invert(cameraMatrix);
v3 newPos = mousePos * inverseCameraMatrix;




Anyone have any insight as to how I can move the newPos down to a y-value of 
0.0f and still have it show up under the mouse?

I've used LineSegmenetIntersectors before for doing this sort of thing, but 
they only work if you are intersecting with geometry. A really hacked solution 
I can think of is to render a big xz plane and use a line segment intersector 
to find the intersection point. But this just seems like a really bad approach, 
even if I hide the plane.

Thanks for all the help!

Cheers,
Christian

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





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

Reply via email to