Hi,
Once getting my model positioned on the surface and moving with the standard
manipulators, I wanted to use a NodeTrackerManipulator to fly behind my model
wherever it was going. I had limited success in that the camera seemed to be
moving along with something, but could not see the model and a side effect was
that moving the mouse resulted in super exagerated zoom and pan effects.
I wondered what I have missed in taking a basic example "oceanExample" that
originally used a MatrixTransform, and modifying it to use the
positionAttitudeTransform. For the person who always asks... I wanted that to
be able "fly" my object through the scene eventually.
First... It is possible to use a PositionAttitudeTransform with a nodeTracker
Manipulator?
Second... What have I done to lose so much control?
Third... have I followed all the steps necessary?
My setup
Code:
osg::ref_ptr<osg::PositionAttitudeTransform> boatTransform = new
osg::PositionAttitudeTransform;
boatTransform->setName("BOAT");
boatTransform->addChild(boat.get());
//My model needed its body center established
const osg::BoundingSphere& bs = boat->getBound();
boatTransform->setPivotPoint(bs.center());
osg::Vec3 boatPosit(0,100,1.5);
boatTransform->setPosition( boatPosit );
boatTransform->setAttitude(osg::Quat( osg::DegreesToRadians(90.0) ,
osg::Vec3(0,0,1) ));
boatTransform->setUpdateCallback( new
BoatPositionCallback(scene->getOceanScene()) );
//Seems to be some discussion about wether to add the transform or the
//model when dealing with a positionAttitudeTransform...
scene->getOceanScene()->addChild(boatTransform.get());
In my modified Callback...
Code:
if(nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR )
{
osg::PositionAttitudeTransform* pat =
dynamic_cast<osg::PositionAttitudeTransform*>(node);
if (!pat || !_oceanScene.valid())
return;
// Get the ocean surface height at the object's position
osg::Vec3f normal;
float height = _oceanScene->getOceanSurfaceHeightAt(pos.x(), pos.y(), &normal);
pat->setPosition(osg::Vec3d(pos.x(), pos.y() += 0.2, height+1)); osg::Quat att(
normal.y(), osg::Vec3(0,1,0), // roll normal.x(), osg::Vec3(1,0,0),
// pitch osg::DegreesToRadians(90.0f), osg::Vec3(0,0,1)
);// heading
pat->setAttitude(att);
}
In the keyboard check for which manipulator to use...
Code:
else if (_currentCameraMode == TRACKBALL)
{
osgGA::NodeTrackerManipulator* nt = new osgGA::NodeTrackerManipulator();
//Find that NODE!
osg::Node* trackedNode = _scene->findNamedNode("BOAT",_scene->getScene());
if(!trackedNode)
return false; //and it is found...
nt->setNode(trackedNode);
nt->setTrackNode(trackedNode);
nt->setTrackerMode(osgGA::NodeTrackerManipulator::NODE_CENTER_AND_AZIM);
nt->setAutoComputeHomePosition(true);
nt->setMinimumDistance(100);
nt->setDistance(100);
nt->setElevation(100);
_currentCameraMode = FOLLOW_ME;
// What do I need to do here? The matrixTransform version used this
//_viewer.getCamera()->setViewMatrixAsLookAt( osg::Vec3f(0.f,0.f,20.f),
// osg::Vec3f(0.f,0.f,20.f)+osg::Vec3f(0.f,1.f,0.f),
osg::Vec3f(0,0,1) );
_viewer.setCameraManipulator(nt);
_textHUD->setCameraText("FOLLOW_ME");
}
Thank you!
Cheers,
tim
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=37751#37751
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org