1 (edited by Slenkar 2009-04-03 13:54:45)

Topic: Cockpit camera

here is the code in C++

//--- set camera to behave as cockpit camera of ship ---
void makeCockpit(irr::scene::ICameraSceneNode *camera, //camera
                irr::scene::ISceneNode *node, //scene node (ship)
                irr::core::vector3df offset) //relative position of camera to node (ship)
{
    //get rotation matrix of node - Zeuss must be getRotation not getRelativeTransformation
   irr::core::matrix4 m;
   m.setRotationDegrees(m_node->getRotation());
   
    // transform forward vector of camera
    irr::core::vector3df frv = irr::core::vector3df (0.0f, 0.0f, 1.0f);
    m.transformVect(frv);
   
    // transform upvector of camera
    irr::core::vector3df upv = irr::core::vector3df (0.0f, 1.0f, 0.0f);
    m.transformVect(upv);

    // transform camera offset (thanks to Zeuss for finding it was missing)
    m.transformVect(offset);
   
    // set camera
    camera->setPosition(node->getPosition() + offset); //position camera in front of the ship
    camera->setUpVector(upv); //set up vector of camera >> Zeuss - tested with +node->getPostion() and it didnt work, but this works fine.
    camera->setTarget(node->getPosition() + frv); //set target of camera (look at point) >> Zeuss - Dont forget to add the node positiob
}

I tried to convert it to blitzmax :

Function makeCockpit(camera:Icamerascenenode,node:ISceneNode,offset:vector3df)

    Local m:matrix4=matrix4.create()
    m.setRotationDegrees(node.GetRotation())

   Local frv:vector3df  = _vector3df (0.0, 0.0, 1.0)
    m.transformVect(frv)

    Local upv:vector3df = _vector3df (0.0, 1.0, 0.0)
    m.transformVect(upv)
    m.transformVect(offset)
   
    
    'offset:+node.getPosition()
    camera.setPosition(offset)
   
    camera.setUpVector(upv)
   
    offset = offset.plus(frv)
    camera.setTarget(offset)
   
    camera.updateAbsolutePosition()
EndFunction

but the camera doesnt turn with the spaceship


EDIT its matrix4.create instead of new matrix!

IT WORKS FINALLY!

thanks for the irrlicht mod