Hi! I am trying to create a C++ class that allow me to move the camera 
following a path determined by some points read from a file . As i want too to 
give the option to 'fly' with the camera using the mouse, i found in one of the 
examples (osgHandGliding) a nice way to do that, so i start from that point and 
add new code to allow the path movement, but now i have had a problem, because 
the original code uses the mouse events to make rotations, translations... but 
now, as the points are determined, there are not mouse events.
I tried to use osg::Matrixd::makeLookAt() function, but the camera seems to 
face to another point, not the one i said.

This is the code i am using (only write the parts i am working with):

bool ManipuladorVuelo::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
    switch(ea.getEventType())
    {
...
        case(GUIEventAdapter::FRAME):
        if (tipoVuelo == VUELO_LIBRE){  //control if we want to fly with the 
mouse, or to follow a path
                    addMouseEvent(ea);
                    if (calcMovement()) us.requestRedraw();
        } else {  //we follow a path

    osg::Matrixd rotation_matrix;
    rotation_matrix.makeRotate(_rotation);

    osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * rotation_matrix;
    osg::Vec3 vx = osg::Vec3(1.0f,0.0f,0.0) * rotation_matrix;
    osg::Vec3 lv = osg::Vec3(0.0f,.0f,-1.0f) * rotation_matrix;

    osg::Vec3 sv = vx;
    sv.normalize();

    _velocity*=-1.0f;
    pitch = inDegrees(22.5f);

    osg::Quat pitch_rotate;

    pitch_rotate.makeRotate(pitch,osg::X_AXIS);

    _rotation = _rotation*pitch_rotate;
//////// doing that i can rotate the camera to look 22.5 degrees up, but not to 
face to look at a point

    lv *= (_velocity);

    _eye += lv;  //_eye is the actual position of the camera
    us.requestRedraw();

    rotationMatrix.makeRotate(_rotation);
    rotationMatrix.makeLookAt(_eye, osg::Vec3(0.0,1.0, 0.0),-osg::Z_AXIS); //It 
should make the camera look at (0,1,0)
    _rotation = rotationMatrix.getRotate();
    us.requestRedraw();
        }
        return true;
  .....

As i said, i think i can make the camera to move from a point to another, but 
not sure how to make the camera to face that point, any help or comments will 
be very helpful.

Thanks in advance.

_________________________________________________________________
¡El Mundo Messenger te espera! Entra ya en "I love Messenger" y descubre las 
últimas novedades, trucos, emoticonos…
http://www.vivelive.com/ilovemessenger/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to