# Facing problems with rotation

Hi All,

I have a doubt with rotation maths. Obviously the doubt is coz of my poor maths :((.

I am trying to learn how to add a Pitch i.e. rotation around x axis in the TestHoveringTank.java which comes as example with jME3 Beta SDK.

So lets say I create a Quaternion for 45D around X axis. Now the tutorial says if I want to rotate a vector 45D around X axis, I should multiply the above Quaternion with such a vector. The resultant vector is rotated 45D around X axis.

But the setPhysicsRotation API expects a Quaternion as a parameter. Do I need to convert such a Vector back to Quarternion? I tried several things but none of them seem to be working.

Any help would be welcome.

Cheers,

Softice

1 Like

Thanks mifth, but it still doesnâ€™t work for me.

I really donâ€™t understand why canâ€™t the library have a class like FlyingControl on the lines of VehicleControl.

I am so exited to start work on my game but I am stuck with getting the rotation correct.

Cheers,

Softice

If you have one quaternion of a certain rotation and multiply it by another quaternion of a certain rotation then you end up with a quaternion that is a combination of both rotations.

â€¦maybe that helps you.

Are you trying to make a fully free-flying vehicle that can yaw, pitch, or roll into any orientation?

This is what I am trying to do,

Say an airplane is flying in certain direction, then with 4 arrow keys I want to control the rotation and turning. i.e. Up and Down(Pitch) using Up/Down arrow and turning left/right using left/right arrow keys. Now when I try to do what you have mentioned above, the vehilce rotates around axis of my choice but it comes to its original position.

What I guess is pitch, yaw and roll are so standard operations that instead of everybody trying to do it themselves, it would help if the API provides it. I havenâ€™t tried it myself but I have seen such a FlyingVehicle(or something like that) class in Delta3D. The reason why I donâ€™t like it is coz of its dependency on Microsoft which doesnâ€™t make it truely open source.

Also I tried learning this from another open source project called aircarrier. But there are 2 problems.

The code that I download doesnâ€™t build coz few of the JME2 libs are misssing which I am not able to find anywhere. Another is, it seems JME2 had some classes to handle key up/down etc. So even if it works, I may have to look at SDK code to find out how those API classes handle these.

Now in doing all this, my original task of creating the game is gone for toss.

If you cannot get rotations right its probably not the time to write games yet ^^ https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

So, creating a true â€śFlying cameraâ€ť is not possible for all games because a real flying camera will require physics simulation of some kind. If itâ€™s an airplane than you need a flight model. If itâ€™s space then you need inertia, etcâ€¦ Without all of that, a fully orientation independent rotation controllable camera would rarely be used. And a straight orientation independent rotation control is trivial to write for anyone with enough math to even attempt that other stuff.

So the fly camera in JME implements a quake-style â€śno rollâ€ť model. No matter where you move or rotate, you will always be a few moves from a right side up straight view. This style camera covers 95% of games that have a first person view.

In your case, you want to â€śaddâ€ť a rotation to the existing orientation based on key input. If the left arrow is pressed you want to add a fixed left rotation to the existing orientation. You do this by taking the current Quaternion and multiplying it by the â€śaddedâ€ť quaternionâ€¦ and using that new Quaternion (the two multiplied together) as your new orientation. You probably want to scale this added rotations by the current tpf and you might be able to see how to do that by looking in FlyByCamera.

1 Like