Hi,
This should be a simple answer, hopefully this hasn't been asked. I have some buttons for switching to the views between top, right,... and bottom. my code is all in the following function:
Code:
void M_OSG_viewer::setViewpoint(Viewpoint new_viewpoint, double distance)
{
switch (new_viewpoint)
{
case MINUS_X:
manipulator->home(0);
manipulator->setCenter(osg::Vec3d(0.0, 0.0, 0.0));
manipulator->setRotation(osg::Quat(-90.0f, osg::Vec3f(0.0f, 1.0f, 0.0f)));
manipulator->setCenter(osg::Vec3d(0.0, 0.0, 1800.0));
manipulator->setElevation(0.0f);
manipulator->setDistance(distance);
break;
case PLUS_X:
manipulator->home(0);
manipulator->setCenter(osg::Vec3d(0.0, 0.0, 0.0));
manipulator->setRotation(osg::Quat(90.0f, osg::Vec3f(0.0f, 1.0f, 0.0f)));
manipulator->setCenter(osg::Vec3d(0.0, 0.0, 1800.0));
manipulator->setElevation(0.0f);
manipulator->setDistance(distance);
break;
case MINUS_Y:
manipulator->home(0);
manipulator->setCenter(osg::Vec3d(0.0,0.0,0.0));
manipulator->setRotation(osg::Quat(90.0f, osg::Vec3f(1.0f,0.0f,0.0f)));
manipulator->setCenter(osg::Vec3d(0.0,0.0,1800.0));
manipulator->setElevation(0.0f);
manipulator->setDistance(distance);
break;
case PLUS_Y:
manipulator->home(0);
manipulator->setCenter(osg::Vec3d(0.0,0.0,0.0));
manipulator->setRotation(osg::Quat(-90.0f, osg::Vec3f(1.0f,0.0f,0.0f)));
manipulator->setCenter(osg::Vec3d(0.0,0.0,1800.0));
manipulator->setElevation(0.0f);
manipulator->setDistance(distance);
break;
case MINUS_Z:
manipulator->home(0);
manipulator->setCenter(osg::Vec3d(0.0, 0.0, 0.0));
manipulator->setRotation(osg::Quat(179.0f, osg::Vec3f(1.0f, 0.0f, 0.0f))); // looking at the bottom exactly is NAN i guess todo
manipulator->setCenter(osg::Vec3d(0.0, 0.0, 1000.0));
manipulator->setDistance(distance);
break;
case PLUS_Z:
manipulator->home(0);
manipulator->setCenter(osg::Vec3d(0.0f, 0.0f, 0.0f));
manipulator->setRotation(osg::Quat(0.0f, osg::Vec3f(0.0f, 0.0f, 1.0f)));
manipulator->setCenter(osg::Vec3d(0.0, 0.0, 1000.0));
manipulator->setDistance(distance);
break;
case ISOMETRIC:
// Isometric view
manipulator->home(0);
manipulator->setCenter(osg::Vec3d(0.0, 0.0, 1000.0));
manipulator->setDistance(distance);
manipulator->setElevation(775.0f);
manipulator->setHeading(0.6f);
break;
default:
// do nothing
break;
}
}
but that bottom view is always wacky if I try to change that 179 deg to 180 deg. Is there some easy way to look directly up from -Z? The home(0) trick took me a while to figure out, it is a good way to stop any rotation that's going on which I have seen people have issues with in other posts. I think I have tried every permutation of arguments for osg::Quat.
Thanks
Patrick
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54054#54054
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org