Replies: 1 comment
-
I would suggest reimplement your code in osgGA::OrbitManipulator. It should have enough virtual methods for setting zooming/rotation separately. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I implemented the mouse-centered zoom function using the following code, and it works fine under normal circumstances:
osgViewer::View* view = dynamic_castosgViewer::View*(&us);
if (!view) return false;
osg::Camera* camera = view->getCamera();
osg::Matrix VPW = camera->getViewMatrix() * camera->getProjectionMatrix() * camera->getViewport()->computeWindowMatrix();
osg::Matrix invVPW;
invVPW.invert(VPW);
osg::Vec3d mouse_world = osg::Vec3d(ea.getX(), ea.getY(), 0.5) * invVPW;
float scale = ea.getScrollingMotion() == osgGA::GUIEventAdapter::SCROLL_UP ? 0.9f : 1.1f;
osg::Vec3d eye, center, up;
getTransformation(eye, center, up);
osg::Vec3d look_vector = center - eye;
look_vector.normalize();
osg::Vec3d new_eye = eye + (mouse_world - eye) * (1.0 - scale);
osg::Vec3d new_center = new_eye + look_vector * (center - eye).length() * scale;
qDebug() << "new_eye" << QString("%1,%2,%3").arg(new_eye.x()).arg(new_eye.y()).arg(new_eye.z());
auto new_distance = (new_eye - new_center).length();
if (new_distance < _minimumDistance) {
return true;
}
_center = new_center;
_distance = new_distance;
However, after rotation, for instance when the quaternion values become rotation "0.167307,-0.237759,0.667011,0.685984", it leads to ineffective zooming where the distance becomes several thousand units, making it impossible to change the current view. After investigation, I found that changes in the center and distance cancel each other out, resulting in no change in the eye position.
Here is the getTransformation method:
void ViewerManipulator::getTransformation(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up) const
{
osg::Vec3d offset(0.0, 0.0, _distance);
osg::Vec3d rotated = _rotation * offset;
eye = _center + rotated;
center = _center;
up = _rotation * osg::Vec3d(0., 1., 0.);
}
Beta Was this translation helpful? Give feedback.
All reactions