Hi,

I have a moving model located in a CoordinateSystemNode with a default 
EllipsoidModel. The goal is that the model is rotated into the direction which 
it is moving. My current code looks like this:


Code:
osg::Matrixd ModelPositionCallback::calculatePositionMatrix(
   const osg::EllipsoidModel* ellipsoid,
   const osg::Vec3d &newPosition, 
   const osg::Vec3d &oldPosition)
{
   osg::Vec3d up = ellipsoid->computeLocalUpVector(newPosition.x(), 
newPosition.y(), newPosition.z());
   osg::Vec3d forward = newPosition - oldPosition;
   forward.normalize();

   osg::Quat rotation;
   rotation.makeRotate(up, forward);

   osg::Matrixd matrix;
   matrix.makeTranslate(newPosition);
   matrix.preMultRotate(rotation);

   return matrix;
}



The problem is, that the rotation obviously depends on the model's position 
within the CoordinateSystemNode / EllipsoidModel, hence the model doesn't head 
in the right direction right now. It is probably pretty simple to do -- but 
I've searched the forum and googled for this but I still have no clue on how to 
solve this... any ideas?

Thank you!

Cheers,
Michael

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





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to