Hi Stefan,

stefan nortd schrieb:
> So I found some code for intersecting a line with a plane. 
> What I am missing is how do I translate the mouse pointer 
> coordinates into a line expressed in local coordinates?
> 
> Here the intersection code if anybody is interested:


There's a class called osg::Plane which you can use to do some
plane-ray-intersections:

double dist = _dragPlane.distance(mouseloc);
double numerator = -dist;
double denominator = _dragPlane.getNormal() * normalizedMouseRay;
        
if (0.0 == denominator) { // is on Plane
        return true;
}
else
{
        pointOnDragPlane = mouseloc + (normalizedMouseRay * 
numerator/denominator);
}

the plane, mouseloc and normalizedMouseRay are in local coordinates.

To convert the mouseloc into local coordinates you'll have to
backproject the coordinates.

I do this via:

// get the coords in screen-space:
float tx =  cefix::MouseLocationProvider::instance()->getNativeX();
float ty =  cefix::MouseLocationProvider::instance()->getNativeY();
osg::Vec3 mouseloc =  osg::Vec3(tx, ty, 0) * _invMatrix;
osg::Vec3 normalizedMouseRay = (osg::Vec3(tx, ty, 1) * _invMatrix) -
mouseloc;


The last question which remains: where comes _invMatrix from:

I get the nodepath of the picked object (it's basically a list of
transforms which affects this specific node) and compute a
localToWorld-matrix. I need the current cam to get view + projection matrix.

osg::Matrix MVPW = osg::computeLocalToWorld(nodepath) *
cam->getViewMatrix() * cam->getProjectionMatrix();

// include the viewport:
if (cam->getViewport())
                        
MVPW.postMult(cam->getViewport()->computeWindowMatrix());

_inverseMat.invert(MVPW);

This code is basically the same as in osg, where picking is done.

cheers,

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

Reply via email to