Eigen library yaw and pitch

Sep 3, 2016 at 6:53pm
Hello, I need some help with my flight simulator, I have encountered the first problem which I know I will not be able to do myself.

I need to be able to take user input to alter the yaw, pitch and roll aspects of an aircraft's rotation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    YAW += virtualy * sin(ROLL * (PI/180));
    PITCH += virtualy * cos(ROLL * (PI/180)); ///problem line...
    ROLL += virtualx;

    ///virtualx and virtualy are altered by key presses,
    ///left key -> virtualx-- | right key -> virtualx++ 
    ///down key -> virtualy-- | up key -> virtualy++ 

    thrustx = sin(YAW * (PI/180)) * cos(PITCH * (PI/180));
    thrusty = sin(PITCH * (PI/180));
    thrustz = cos(YAW * (PI/180)) * cos(PITCH * (PI/180));

    force_x = thrustx;// + form_dragx;// /*+ gravity*/ + liftx; //would be += 
    // in reality, but for testing just =
    force_y = thrusty;// + form_dragy;// /*+ gravity*/ + lifty;
    force_z = thrustz;// + form_dragz;// /*+ gravity*/ + liftz;

    x += 0.01 * force_x;
    y += 0.01 * force_y;
    z += 0.01 * force_z;


From this code snippet, you can see that the first three lines are useless. I have been playing around with being able to control the yaw, pitch and roll angles, but have not gotten anywhere. The thrust vectors take the YAW and PITCH variables and work very nicely. So my problem extends from taking user input, as shown by the virtualy and virtualx variables, which then must alter the YAW< PITCH and ROLL variables.

I need help this time. Please can I have a reply, I am under a lot of pressure, and I have no previous experience with anything on this level, but once I have the small code snippet it is a closed operation and I do not have to be concerned with it any more.

It looks as though eigen might be the solution, as referenced here: http://stackoverflow.com/questions/21412169/creating-a-rotation-matrix-with-pitch-yaw-roll-using-eigen. Please can somebody explain, it is such a small thing to do, but would make my life a lot easier.
Sep 3, 2016 at 9:09pm
You can't perform interactive rotations my modifying a yaw-pitch-roll tuple. For example, imagine you implement a yaw as a rotation about the vertical axis. That works fine when the pitch is zero, but when the pitch is 90°, modifying the yaw variable produces a roll instead. See https://en.wikipedia.org/wiki/Gimbal_lock
The minimum state you need is a pair of forward and hat vectors, which you will transform using appropriate operations.

The last time you were advised to use quaternions. If you don't want to use them, this can also be done with rotated rotation matrices (i.e. apply a rotation matrix to another rotation matrix and apply the result to the vector of interest); you would have to rotate them so that they perform rotations around non-aligned axes. In particular, around axes relative to the body you want to rotate.
If none of what I'm saying makes sense, I recommend you grab a book on linear algebra. Eigen is a linear algebra library, so you still need to understand what it is you're doing to be able to use it.
Last edited on Sep 3, 2016 at 9:12pm
Sep 4, 2016 at 3:20pm
Thank you for the reply, the problem is I don't know how to do either of these things. I have not done my GCSE's yet, I really need to do this and I don't even know how to try to solve it. How does a quaternion work? How does a rotation matrix work? I am so close to the end, but I just need someone to help.
Sep 4, 2016 at 8:33pm
closed account (48T7M4Gy)
Your equations are simply wrong.

thrust (from the engine) is independent of yaw, roll and pitch etc. For equilibrium you need to sum the x,y and z forces which include thrust, lift, drag and weight of/on the plane and convert that to x ,y and z accelerations.

I suggest you check out some basic physics and get that right first.

As far as transforms are concerned you need to understand the difference between local and global coordinates and when to use them. There is no special rule on that. It's whatever is the man set convenient and appropriate at the time.
Sep 5, 2016 at 4:05pm
Actually, those are implemented, I cut down the code significantly to just send how the relevant parts.

If no one can offer an example, tutorial, explanation I will have to go somewhere else.
Sep 5, 2016 at 4:58pm
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/196619/
Topic archived. No new replies allowed.