[osg-users] Third-Person Camera Manipulator

Michael Chapman 08kabbotta80 at gmail.com
Tue Oct 13 17:29:30 PDT 2015


Hi,

I'm trying to write a simple third-person camera manipulator, and I seem to be confused about something to do with how it handles the coordinate system. I am inheriting from the osgGA::StandardManipulator.


Code:

ThirdPersonManipulator::ThirdPersonManipulator()
  : osgGA::StandardManipulator(),
    distance(100),
    eye(0, -distance, 0),
    center(0, 0, 0),
    up(0, 0, 1)
{
  setHomePosition(eye, center, up);
}

void ThirdPersonManipulator::setByMatrix(const osg::Matrixd& matrix_)
{
  matrix = matrix_;
}

void ThirdPersonManipulator::setByInverseMatrix(const osg::Matrixd& matrix_)
{
  setByMatrix(osg::Matrixd::inverse(matrix_));
}

osg::Matrixd ThirdPersonManipulator::getMatrix() const { return matrix; }

osg::Matrixd ThirdPersonManipulator::getInverseMatrix() const 
{ 
  return osg::Matrixd::inverse(matrix);
}

bool ThirdPersonManipulator::handleFrame(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&)
{
  osg::Vec3d pos = GameManager::instance().player.pos;

  matrix =
    osg::Matrixd::translate(pos);

  return false;
}




This kind of produces the results I wanted, but what I expect to be "forwards" is actually "up". 

Here is a screenshot showing that it affects the models and the placement of the camera: http://imgur.com/ZUsRYvU

I'm exporting the models from blender using the built-in fbx exporter. And I export them with a coordinate system that is "Y Forwards / Z Up". I believe that is the same coordinate system that osg uses by default.

Thank you!

Cheers,
Michael

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








More information about the osg-users mailing list