[osg-users] Calculating Up Vector
Cysneros, Nelson SPAWAR
nelson.cysneros at navy.mil
Thu Feb 28 10:35:15 PST 2008
I'm having a problem trying to calculate the UP vector of a node as it
makes a 360 roll.
I'm setting the camera viewpoint like this:
//Update View
osg::Vec3 eye( cameraX, cameraY, cameraZ);
osg::Vec3 center(nodeX,nodeY,nodeZ);
osg::Vec3 up(nodeX,nodeY,nodeZ);
viewer->getCamera()->setViewMatrixAsLookAt(eye,center,up);
Which works great in a geoCentric system. I can place a node anywhere on
the earth and it will be right side up.
Now the node wants to make a 360 roll and we want the camera to roll
with it. Not sure how to calculate the UP vector in this case.
I tried something like this:
osg::Matrix rotX, rotY, rotZ, transXYZ;
rotX.makeRotate(myNode->getXRotation(), osg::Vec3(1,0,0));
rotY.makeRotate(myNode->getYRotation(), osg::Vec3(0,1,0));
rotZ.makeRotate(myNode->getZRotation(), osg::Vec3(0,0,1));
up = eye ^ center;//cross product
osg::Vec3 up2;
up2 = up * rotZ * rotY * rotX;
viewer->getCamera()->setViewMatrixAsLookAt(eye,center,up2);
Does not work... Any suggestions?
Thanks
More information about the osg-users
mailing list