简体   繁体   中英

gluLookAt issues - how to make a curve like movement?

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM