Hello,
I am helping to develop a 3DViewer to view pcbdesigns in 3D we are using
OSG 0.9.9. I am having some troubles getting new x and y coordinates to
translate my view with.
Basically I am trying to set up a zoom and when you click on a part in
the design you zoom in by 25% of the distance. Then you click it again
and you zoom another 25% of the distance.
I am not having troubles with the zooming but I am having troubles with
where it zooms and the mouse input.
This is what I am doing:
osg::ref_ptr<Producer::trackball> _trackBall;
osf::ref_ptr<osg::Group> _root;
mx = getTheMouseXScreenCoordinate;
my = getTheMouseYScreenCoordinate;
button = getthePressedButton;
if(buttom == 2)
{
float distance = _trackBall->getDistance();
float distancePercentage = distance*.25;
float newDistance = distance -distancePercentage;
float newScale = _trackBall->getScale();
const osg::BoundingSphere& bs = _root->getBound();
double radius = bs.radius();
double totalSize = radius*newScale;
double xInfo = totalSize*mx;
double yInfo = totalSize*my;
double x = xInfo/newScale;
double y = yInfo/newScale;
_trackBall->reset();
_trackBall->setDistance(newDistance);
_trackBall->translate(-x,-y,0);
}
So on my first click I zoom into the correct place that I want to zoom
into. But on my second click on trying to zoom, I zoom into the
incorrect area and so on and so forth.
So basically I am trying to take the mouse coordinates and convert them
to the design coordinates. To total size of the design or the bounding
sphere around the desing is 3000, the center of the design is roughly
1500. The units don't really matter to me at this point. The mouse
coordinates that I am getting are in decimals, if I click on the lower
left of the design x comes back as roughly .18 and y comes back at
roughly .24. The scale at this intial point is roughly 1100. We zoom
in 25% of our distance in the correct area. No the view is currently a
little more zoomed in and the view is now different. But I am still
able to click on the same spot I was before. So I click on it and it
zooms in but in the incorrect spot. The same stop that was .18 earlier
is not .30 which is the x mouse screen coordinate. The y mouse
coordinate comes back at roughly .36 and was .24 before. The scale at
this point is now .748. So I click again and the design gets more
zoomed in and the coordinates change again.
My question is how do I take the mouse coordinates and get the
coordinates I need to correctly translate them? Any ideas or suggestion
would be wonderful.
Thanks,
Shane
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/