Calculating the Output for a Motion Simulator [SOLVED]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
haku2510
Posts: 12
Joined: Thu Apr 09, 2015 5:46 pm

Calculating the Output for a Motion Simulator [SOLVED]

Post by haku2510 »

Hi again.
I've come into a bit of a problem, I'm trying to make my game move a Motion Simulator, however I'm finding that I can't make my velocity rotate so that if my craft is going forward that it would equal vector3df(0,0,1) for example.

What I seem to be getting out is the raw direction value when it's used on the mini simulator I made. However when I rotate but don't change my velocity (so i'm still moving in the same direction) the motion simulator is rotating too. This leads me to believe that it is rotating the vector just not by what I would like.
I've tried this a few different ways but haven't found a winner, any thoughts?

Code: Select all

void Player_suit::MotionSim()
{
    static char Outbytes[] = {0,0,0};
    static float F=0,S=0,U=0;   //Forward,Side,Up
 
        vector3df dif = velocity.direction;
        vector3df rot = rotation;
 
        matrix4 m;
        m.setRotationDegrees(rot.invert()); //Rotate the velocity so its relitive to the node rotation
        //This should make the direction of acceleration face (0,0,1) if it was forward of the node.
        m.rotateVect(dif);
 
        if(dif.getLength()>5)
        {
            dif.setLength(5);
        }
 
        F = dif.Z;
        U = dif.Y;
        S = dif.X;
 
 
 
            core::stringw tmp = L"Balance board";
            tmp += " ( ";
            tmp += F;
            tmp += ",  ";
            tmp += S;
            tmp += ", ";
            tmp += U;
            tmp += " )";
            device->setWindowCaption(tmp.c_str());
 
 
    if(motionSimEn && arduino->IsConnected())
    {
        Outbytes[0] = (char)((F)+100);
        Outbytes[1] = (char)((S)+100);
        Outbytes[2] = (char)((U)+100);
 
            core::stringw tmp = L"Balance board";
            tmp += " ( ";
            tmp += Outbytes[0]-100;
            tmp += ",  ";
            tmp += Outbytes[1]-100;
            tmp += ", ";
            tmp += Outbytes[2]-100;
            tmp += " )";
            device->setWindowCaption(tmp.c_str());
 
        arduino->WriteData(Outbytes,3);
    }
    else if(!motionSimEn && arduino->IsConnected())
    {
 
        Outbytes[0] = (char)((0)+100);
        Outbytes[1] = (char)((0)+100);
        Outbytes[2] = (char)((0)+100);
 
        arduino->WriteData(Outbytes,3);
 
    }
}
Last edited by haku2510 on Fri May 01, 2015 10:33 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Calculating the Output for a Motion Simulator

Post by CuteAlien »

Sorry, I don't understand the explanation. Maybe you can make a simple drawing about your vectors and what you expect of them.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
haku2510
Posts: 12
Joined: Thu Apr 09, 2015 5:46 pm

Re: Calculating the Output for a Motion Simulator

Post by haku2510 »

Edit, sorry the images are so large.
Image
Image
I'm trying to find the angle of velocity.direction (which holds my current movement speed and direction) in relation to my current rotation.

So if I accelerate forward(0,0,1), I use a matrix to rotate that direction by my rotation so that I move forward in the direction I'm facing rather than along the Z axis.

I'm trying to reverse that process so that I can find what direction I'm moving in based on my current forward direction.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Calculating the Output for a Motion Simulator

Post by REDDemon »

Trajectory of a object is independent of its orientation.. You can have a bullet moving (you just update its position). And then have the camera moving around the bullet. You can also make the bullet rotation so it have the back always faced to the camera (wich seems what you want). You just need a orientation vector and a position vector. You can add another value to the orientation vector (angle) to make a rotation around the direction axis (call it quaternion, irrlicht have that class).

However when ship moves you update position, when ships rotate you update rotation, and when ship thrust engines you update velocity according to direction

Sorry for saying basics things, but at least I hope we can met in middle and find what you need: )
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
haku2510
Posts: 12
Joined: Thu Apr 09, 2015 5:46 pm

Re: Calculating the Output for a Motion Simulator

Post by haku2510 »

I'm aware of Quaternians, but with this due up in 2 days I didn't want to have to use them without properly learning them.
I figured this would be a simple part of the project, however it seems that the velocity isn't being rotated constantly by this function.
It seems like my Y axis is acting up and not updating when I'm moving vertically perpendicular to the direction I'm looking in.
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Calculating the Output for a Motion Simulator

Post by thanhle »

That looks similar to this below. But don't set the y direction to 0.

http://irrlicht.sourceforge.net/forum/v ... =4&t=50692

The method assume you have an initial facing direction.

I'm not sure we need to invert the parent node matrix or not.
If we do then dig into my snippet code for for inverse kinematic for that bit of the code.
Basically we just inverse the parent node matrix and multiple with the deltarotation and abstransform of the child. Look for that in the snippet forum.

Regards,
thanh
haku2510
Posts: 12
Joined: Thu Apr 09, 2015 5:46 pm

Re: Calculating the Output for a Motion Simulator

Post by haku2510 »

Thanks, I'll give that a go later, in college at the moment trying to do a write up.
Thought I had this working till Saturday evening and then I noticed the Simulator going in weird directions.
What you have looks like what I think I need, have a similar implementation for the camera just wasn't sure how to apply it to this.
haku2510
Posts: 12
Joined: Thu Apr 09, 2015 5:46 pm

Re: Calculating the Output for a Motion Simulator

Post by haku2510 »

No luck I'm afraid,
Can't understand why this isn't working.
If I build a matrix with the inverse of my rotation and rotate my velocity with it, it should move the velocity so that it's equal to (velocity's rotation)-(rotation).

That should be the same as what it is to My character at that rotation as (rotation)-(rotation) should have the craft point forward at (0,0,0).
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Calculating the Output for a Motion Simulator

Post by thanhle »

Example to make character facing perpendicular to a target.

I think you need at least 3 points for correct representation of the platform.
p1 is the previous facing direction. You would initialise it to something.
You need to put some effort into these stuff.

Code: Select all

void faceTargetObject(vector3df target,vector3df &p1, irr::scene::ISceneNode *node)
{
    
    core::vector3df  pos = node->getAbsolutePosition();
    core::vector3df p2 = (target - pos).normalize();   // Face-to direction vector
 
    vector3df axis = p1.crossProduct(p2);
    axis.normalize();
 
    float dot = p1.dotProduct(p2);
    float angle = acosf(dot);
 
    if (abs(angle) > 0.0001)
    {
 
        ////Quaternion
        //  irr::core::quaternion ch;
        //ch.makeIdentity();
        //ch = ch.fromAngleAxis(angle, axis);  
        //ch.normalize();
 
        //matrix4 ivtran;
        //node->getParent()-> getAbsoluteTransformation().getInverse(ivtran);
 
        //quaternion qinv = quaternion(ivtran);
        //qinv.normalize();
 
        //vector3df rot;
 
        //quaternion qa = quaternion(node->getAbsoluteTransformation());
        //qa.normalize();
 
        //ch = qa*ch*qinv;
 
        //ch.toEuler(rot);
        //rot *= RADTODEG;
 
        //node->setRotation(rot);
        //((irr::scene::IBoneSceneNode *) node)->updateAbsolutePositionOfAllChildren();
        //p1 = p2;
 
    
 
        //Matrix method.
        matrix4 qa, ch, ivtran;
        node->getAbsoluteTransformation().getInverse(ivtran);
        
        ch = ch.setRotationAxisRadians(angle, axis);
        qa = node->getAbsoluteTransformation();
        node->getParent()->getAbsoluteTransformation().getInverse(ivtran);
 
        ch = ivtran*ch*qa;
 
        vector3df rot = ch.getRotationDegrees();
    
        node->setRotation(rot);
        ((irr::scene::IBoneSceneNode *) node)->updateAbsolutePositionOfAllChildren();   //Try other node update method.
        p1 = p2;
 
    }
}
 
Maybe use a physic engine. It might be easier.
Regards
thanh
haku2510
Posts: 12
Joined: Thu Apr 09, 2015 5:46 pm

Re: Calculating the Output for a Motion Simulator

Post by haku2510 »

Thanks, ended up getting it working. I got the difference between the angles and just rotated a forward vector by that. It's not perfect but it got me through the presentation!
I'm going to keep the project going regardless, having fun with it and want to see how far I can go with it.
Thanks again for all the help!
Post Reply