[osg-users] ease motion with viewer camera

Stephane Dumon dumon.stephane at gmail.com
Fri Apr 15 06:52:01 PDT 2011


Hi,

ok, just a few words to tell you what i am trying to do.

 have a 3D scene, to this point nothing special. On this 3D scene I draw (like we can do in Paint) a rectangle. I add a camera which has as child node this Geode.
My greatest wishes, for now, is to make an ease motion from my viewer camera(V) to this geode camera(C).
I had already take a look to the osgeasemotion example and try to do the same but the movement is not the one i expect.

For the moment, before the movement, i creat one quaterion to precise the rotation my viewer camera should do to get the geode camera's one. I get the eye, center and up axes of each camera, and make the quat like this:


Code:
osg::Vec3 from = eyeV - centerC;
osg::Vec3 to = eyeC - centerC;
rot.makeRotate_original(from, to);



Then i attach a nodeCallBack to my viewer camera which suppose to do the job, like this:


Code:

void operator()(osg::Node* node, osg::NodeVisitor* nv)
	{
		if(!_motion.valid()) return;
		if(isDone) return;
		else
		{
			osg::Camera* cam = dynamic_cast<osg::Camera*>(node);
			if(!cam)
			{
				std::cout << "!cam" << std::endl;
				return;
			}
			double t = nv->getFrameStamp()->getSimulationTime();
			if(_previous == 0.0f) 
				_previous = t;
			
			_motion->update(t - _previous);
			
			_previous = t;
			
			float pas = _motion->getValue();
			
			cam->setViewMatrix(osg::Matrix::inverse(osg::Matrix::rotate(rot*pas)*osg::Matrix::translate(trans*pas)));
			cam->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
			if(_motion->getTime() == 2.0)
			{
				std::cout << "fini" << std::endl;
				_motion->reset();
				_previous = 0.0;
				isDone = true;
			}
			traverse(node,nv);
		}
	}




I am about to reach the good position but my camera don't look the good center.

Is there anyone who could help me? 

Thank you!

Regards,
Stephane

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38502#38502








More information about the osg-users mailing list