Get turn / pitch / roll of rotation

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
torleif
Posts: 188
Joined: Mon Jun 30, 2008 4:53 am

Get turn / pitch / roll of rotation

Post by torleif »

I used the free space flight functions to make a player object. This player object is a airplane. Airplanes in real live level out horizontally along the plane of the earth.

I want my plane to do the same. I was thinking about getting the rotation of the plane, getting its roll and roll it back using the rotation functions.

I can't figure out how to do this. Does anyone know enough matrix/ vector math to help me?
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Get turn / pitch / roll of rotation

Post by smso »

There is no way of getting ALL the yaw, roll and pitch values from the single rotation vector of the airplane scene node.
I used a hierarchy of empty scene nodes to control the yaw, roll and pitch of the airplane, like this:
root node (for translation)-> yaw node -> roll node -> pitch node -> airplane

Just do some bookkeeping (and clamping of angles) whenever the airplane yaws, rolls and pitches.
torleif
Posts: 188
Joined: Mon Jun 30, 2008 4:53 am

Re: Get turn / pitch / roll of rotation

Post by torleif »

I found the solution by changing the rotation to a direction vector then taking the cross product of up.

I could then work out if the airship was banking left or right then rotate it accordingly.

Code: Select all

                core::vector3df rotdir = spacecraft->getRotation().rotationToDirection();
                core::vector3df cdiff = rotdir.crossProduct(core::vector3df(0, 0, 1));
                if(cdiff.X > 0){
                        spacecraft->setRotation(pitch(spacecraft->getRotation(), .2));
                }
                if(cdiff.X < 0){
                        spacecraft->setRotation(pitch(spacecraft->getRotation(), -.2));
                }
Post Reply