0

for this project i am working on, i am having a bit of difficulty with calculating the yaw alongside a camera using the gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ) function, having the camera follow the helicopter with the yaw just wont work

gluLookAt(cameraPosition[0], cameraPosition[1], cameraPosition[2],
        heliLocation[0], heliLocation[1], heliLocation[2],
        0, 1.0, 0.0);`
if (keyboardMotion.Yaw != MOTION_NONE) {
        /* TEMPLATE: Turn your object right (clockwise) if .Yaw < 0, or left (anticlockwise) if .Yaw > 0 */
        heliYaw += keyboardMotion.Yaw * heliYawSpeed * FRAME_TIME_SEC;
        cameraPosition[0] = heliYaw;
        if (heliYaw > 360) {
            heliYaw = 0;
        }
        else if (heliYaw < -360) {
            heliYaw = 0;
        }
    }

I also have trouble with the camera following forward movement especially if the yaw has been changed as im unsure as to how to calculate the direction of the helicopter, i have tried but cant seem to understand what im doing, so i dont understand what im doing wrong could anyone please explain

if (keyboardMotion.Surge != MOTION_NONE) {
        float Rotation = heliYaw * (PI / 180);
        /* TEMPLATE: Move your object backward if .Surge < 0, or forward if .Surge > 0 */
        heliLocation[2] += keyboardMotion.Surge * moveSpeed * FRAME_TIME_SEC * -1;
        
        //heliLocation[2] += (float)cos(Rotation);
        //heliLocation[0] += (float)sin(Rotation);
        //heliLocation[0] += (float)cos(heliYaw / (PI * 180.0f)) *keyboardMotion.Surge *  moveSpeed * FRAME_TIME_SEC;
        //cameraPosition[2] += keyboardMotion.Surge * moveSpeed * FRAME_TIME_SEC;

the commented out areas are just what i thought would work.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
SweetLaw
  • 3
  • 4
  • "_having the camera follow the helicopter with the yaw just wont work_", "_I also have trouble with the camera_", and "_i dont understand what im doing wrong_" don't actually describe what's happening. I'm sure _won't work_ describes it for you, in your mind, because you're familiar with it, but for the rest of us, you'll have to describe what is actually happening vs what you expect it should be doing. Taking the time to fully describe the problem, your expectations, and your understanding of the situation is more than half the work of fixing it. – Wyck May 14 '21 at 14:59
  • Okay so i'll try to explain it in enough detail, i thought describing yaw and a helicopter would be enough. But for the Yaw im Rotating the helicopter object with the global variable heliYaw, i am updating the heliYaw in a think() function and the glRotate(-heliYaw, 0, 1.0f, 0) function is inside a function containing the shapes making up the helicopter called Helicopter(), hoiwever in think() i am trying to have the camera turn as if you would turn your head left and right when the yaw goes left or right, the code at the top for the yaw camera however does not work like this – SweetLaw May 14 '21 at 15:45
  • see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) especially last sublinks where are examples on how to do thing like this the easy way instead of using Euler angles which cause only problems ... – Spektre May 15 '21 at 06:19

0 Answers0