Topic: rotations dont always work correctly?

Hi I am turning a mesh with the mouse:

        If x<640 And y<480 
            Local v:vector3df=node.GetRotation()
            v.sety(v.gety()+(prev_mouse_x-x))
            v.setx(v.getx()+(prev_mouse_y-y))
            node.SetRotation(v)
            prev_mouse_x=x
            prev_mouse_y=y
            EndIf

it works ok but if the mesh is facing upwards and i move the mouse to the side the mesh rotates on its local Z axis. (instead of Y axis)

adjusting the pitch of the mesh always works correctly though

Re: rotations dont always work correctly?

ok so I was using global rotation co-ords
I had  alook through the irrlicht forums and found this:

void rotate(irr::scene::ISceneNode *node, irr::core::vector3df rot)
{
    irr::core::matrix4 m;
    m.setRotationDegrees(node->getRotation());
    irr::core::matrix4 n;
    n.setRotationDegrees(rot);
    m *= n;
    node->setRotation( m.getRotationDegrees() );
    node->updateAbsolutePosition();
}

//--- turn ship left or right ---
void turn(irr::scene::ISceneNode *node, irr::f32 rot)
{
    rotate(node, irr::core::vector3df(0.0f, rot, 0.0f) );
}

//--- pitch ship up or down ---
void pitch(irr::scene::ISceneNode *node, irr::f32 rot)
{
    rotate(node, irr::core::vector3df(rot, 0.0f, 0.0f) );
}

//--- roll ship left or right ---
void roll(irr::scene::ISceneNode *node, irr::f32 rot)
{
    rotate(node, irr::core::vector3df(0.0f, 0.0f, rot) );
}

but in blitz you cannot use * to multiply vectors

Re: rotations dont always work correctly?

I tried to convert it to blitzmax but m.getrotationdegrees returns null

Function TurnEntity(node:iscenenode,vec:vector3df)
    Local m:matrix4=New matrix4
    m.setRotationDegrees(node.GetRotation())
    Local n:matrix4=New matrix4
    n.setRotationDegrees(vec);
    M.Mult(n )
    node.SetRotation( m.getRotationDegrees() )
    node.updateAbsolutePosition()
EndFunction

Re: rotations dont always work correctly?

greetings smile  try these:

Function NodeMove(node:ISceneNode,x:Float,y:Float,z:Float)    
    ' from: http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=4680            
    Local dest:Vector3df=Vector3df.createFromVals(x,y,z)
    node.getRelativeTransformation().transformVect(dest)
    node.setPosition(dest)
EndFunction

Function NodeTurn(node:ISceneNode,pitch:Float,yaw:Float,roll:Float)
    ' from: http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=4680
    Local m:Matrix4=Matrix4.Create()
    Local n:Matrix4=Matrix4.Create()
    Local t:Matrix4=Matrix4.Create()
    
    m.setRotationDegrees(node.GetRotation())
    
    n.setRotationDegrees(_VECTOR3DF(0,0,roll))
    t.setRotationDegrees(_VECTOR3DF(pitch,0,0))
    n.MultEq(t)
    t.setRotationDegrees(_VECTOR3DF(0,yaw,0))
    n.MultEq(t)
        
    m.MultEq(n)
    node.SetRotation(m.getRotationDegrees())
EndFunction

Function NodePointTo:Vector3df(node:ISceneNode, x:Float, y:Float, z:Float)
    Local direction:Vector3df = _VECTOR3DF(x,y,z).Minus(node.getPosition())
    node.SetRotation(direction.getHorizontalAngle())
EndFunction

there will still be a rotation problem since its not using quaternions.  i have not been able to have a good quaternion rotation routine.

5 (edited by Slenkar 2009-03-12 08:42:09)

Re: rotations dont always work correctly?

thanks for the functions and the modules!

Ill try them out

EDIT
they work great thanks