Maker Pro
Maker Pro

Describing Yaw, pitch and roll changes?

This question is not so much electronics, but is related to an electronics project, more of a programming and maths question.

This question is vital to the continuation of the flight simulator competition that I am now expected to deliver in, and is what I suspect the last difficult part. I have posted the question to a C++ forum, that is completely useless and have answered few of my previous questions. I am therefore left with this site for help.

Below is a section of my program that concerns my problem:

Code:
    switch (key){
        case GLUT_KEY_RIGHT:
            virtualx--;
            break;
        case GLUT_KEY_LEFT:
            virtualx++;
            break;
        case GLUT_KEY_UP:
            virtualy++;
            break;
        case GLUT_KEY_DOWN:
            virtualy--;
            break;
    }

...
    /**
    ROLL = virtualx 
    PITCH += virtualy * cos(ROLL * (PI/180));
    YAW += virtualy * sin(ROLL * (PI/180));
    **/

    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;
    force_y = thrusty;
    force_z = thrustz;

...

    
    glRotated(ROLL,0,0,1); ///The opengl code that puts the rotations into view,
    glRotated(PITCH,1,0,0); ///these are known to work as yaw, pitch and roll have been
    glRotated(YAW,0,1,0); ///tested independently of the virtual control system.

Key presses change virtualx and virtauly, which are effectively where a controll column would point. The variables virtualx and virtualy must then control the YAW PITCH and ROLL (these are absolute yaw and pitch, tait byran angles). The yaw and pitch then tell the plane how to move in thrust. The key press system is fine, and the xyz movement also works perfectly.

The lines that I have block commented are what is causing the problem, the lines that describe how YAW and PITCH are changed. The code I have should, according to what I can picture of rotations, produce a mimicry of yaw and pitch, as the turning circles would be concentric, rather than intersecting from any given point. The can not even do this, the direction of viewing behaves perfectly when ROLL = 0, 90, 180 or 270, a perfect circle is traced. As the ROLL approaches 45, 135, 225, and 315, the movement oscillates in a meaningless swing.

What would the algorithm look like that will actually describe YAW and PITCH? Do I need the change of yaw and pitch to refer to themselves in the calculations? I do not even know where to go from here, I have exhausted my options and can not find help anywhere, which is rather worrying when everyone is expecting this from me.

Please help
 
Top