0

So basically, by using left, right, up and down keys I need to achieve this animation probably using gluLookAt.

I have tried everything but I can't get it to move exactly like this. Do you have any tips? Here is my current function for camera movement.

void specialKeys(int key, int x, int y) {
    switch (key) {
        case GLUT_KEY_DOWN:
            ex -= 0.04;
            break;
        case GLUT_KEY_UP:
            ex += 0.04;
            break;
        case GLUT_KEY_LEFT:
            ey += 0.05;
            cy -= 0.05;
            std::cout << ex << " " << cx << " " << uy << std::endl;
            break;
        case GLUT_KEY_RIGHT:
            ey -= 0.05;
            cy += 0.05;
            std::cout << ex << " " << cx << " " << uy << std::endl;
            break;
        default:
            break;
        }
    glutPostRedisplay();
}

The rest of the code can be found in the previous questions Why does my wired sphere turn into ellipsoid when translating and changing camera angle? and Issues with animation - translation, projection OpenGL/C++.

my gluLookAt is:

gluLookAt(ex + 0.0, ey + 0.0, ez*ex - 5.5, cx, cy, -1.0 + cz, -1.0, 0.0, 0.0);

Somehow my up and down keys are not doing what they should be doing when elements get translated to the right. I think I'm on the right path but I've been working on this for two days and can't manage to solve it.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
me995
  • 59
  • 1
  • 6

1 Answers1

1

The target of the view doesn't seem to be in the center of the torus. It seems to be on the axis of symmetry, but in front of the torus. Hence the argument centerZ of gluLookAt depends on ez. For instance:

gluLookAt(ex, ey, ez, 0.0, 0.0, ez-1.0, 0.0, 1.0, 0.0);
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 1
    It kind of looks like the example, but I still couldn't manage to make it move exactly like it does on the gif. I give up, no matter what I did, it didn't help. It just doesn't make those tiny movements the animation has on the gif. Thank you for your help anyways, it is much appreciated, I learned some new stuff. – me995 May 17 '20 at 10:49