0

Ok, I'm done with forward and backward movement with gluLookAt() function.
I subtract eyeX from atX, and eyeZ from atZ. Names of each variables are xVector and zVector. And I add it with some multiplication with constant.

From now on, I have to calculate side movement vector. But how can I get that one? Is there any way to move a camera from side to side with z and x vectors?

I use C, so there's no vector class or some kinds of high-level class/functions.
I need you guys' help now.

This is my function for camera movement processing,

void cameraProc() {
    int xInc, zInc;

    at[0] += xTheta;
    at[1] += yTheta;

    if (keys['w']) {
        eye[0] += xInc*SPD;
        at[0] += xInc*SPD;

        eye[2] += zInc*SPD;
        at[2] += zInc*SPD;
    }
    if (keys['a']) {
        //How?
    }
    if (keys['s']) {
        eye[0] -= xInc*SPD;
        at[0] -= xInc*SPD;

        eye[2] -= zInc*SPD;
        at[2] -= zInc*SPD;
    }
    if (keys['d']) {
        //And how?
    }
    printf("\nEye : %f %f %f\n", eye[0], eye[1], eye[2]);
    printf("At : %f %f %f\n", at[0], at[1], at[2]);

    gluLookAt(eye[0], eye[1], eye[2], at[0], at[1], at[2], up[0], up[1], up[2]);
    at[0] -= xTheta;
    at[1] -= yTheta;
}

P.s. xTheta and yTheta is variables to spin the camera.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Do "xInc" and "zInc" have values? They initially are 0 and are never set. If you were to set "xInc" to 1, for example, your camera would move right when you press 'w'. – CMilby Apr 19 '17 at 15:41
  • Your 'w' and 's' keys are moving the camera in both X/Z **world** axis (not camera space) at once. It would be better to move only in one axis. Another matter is if you want to move the camera following world or camera axis. – Ripi2 Apr 19 '17 at 15:45
  • take a look at [Understanding 4x4 homogenous transform matrices](http://stackoverflow.com/a/28084380/2521214) especially the links at the end (edit3) there are examples of keyboard camera and player control in local coordinates of each ... – Spektre Apr 20 '17 at 05:41
  • Thanks guys. I really appreciate your answers. xInc and yInc was variables that represent the vector of each x and y coordinate, but with my mistake, i just forgot to type it in to my codes. I'm sorry. I'll changed the moving coordinates as Said, and i'll watch the article about [Understanding 4x4 homogenous transform matrices](http://stackoverflow.com/questions/28075743/how-do-i-compose-a-rotation-matrix-with-human-readable-angles-from-scratch/28084380#28084380). Thank you :) – DevFallingstar Apr 20 '17 at 08:25

0 Answers0