OpenGL (SDL) - Rotating camera rotates everything else instead.

Basically, when I hold pageup, or pagedown, I want to more or less, look up or down respectively, yet this code seems to just rotate all the cubes around some central axis point, which doesn't seem to be the camera. How do I make it look as if the camera is being pointed upwards?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    while(!done)
    {
        ticks++;

        while(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
            {
                done = true;
                break;
            }

            if(event.type == SDL_KEYDOWN)
            {
                if(event.key.keysym.sym == SDLK_ESCAPE)
                {
                    done = true;
                    break;
                }

                if(event.key.keysym.sym == SDLK_DOWN)
                    skup = true;
                if(event.key.keysym.sym == SDLK_UP)
                    skdown = true;
                if(event.key.keysym.sym == SDLK_LEFT)
                    skleft = true;
                if(event.key.keysym.sym == SDLK_RIGHT)
                    skright = true;
                if(event.key.keysym.sym == SDLK_PAGEUP)
                    skpu = true;
                if(event.key.keysym.sym == SDLK_PAGEDOWN)
                    skpd = true;
            }

            if(event.type == SDL_KEYUP)
            {
                 if(event.key.keysym.sym == SDLK_DOWN)
                    skup = false;
                if(event.key.keysym.sym == SDLK_UP)
                    skdown = false;
                if(event.key.keysym.sym == SDLK_LEFT)
                    skleft = false;
                if(event.key.keysym.sym == SDLK_RIGHT)
                    skright = false;
                if(event.key.keysym.sym == SDLK_PAGEUP)
                    skpu = false;
                if(event.key.keysym.sym == SDLK_PAGEDOWN)
                    skpd = false;
            }

            if(event.type == SDL_MOUSEMOTION)
            {

            }
        }

        if(skup)
            camz -= 0.1f;
        if(skdown)
            camz += 0.1f;
        if(skleft)
            camx += 0.1f;
        if(skright)
            camx -= 0.1f;
        if(skpu)
            roty += 0.2f;
        if(skpd)
            roty -= 0.2f;

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear The Screen And The Depth Buffer
        glLoadIdentity();				// Reset The View

        glTranslatef(camx,camy,camz);              // move 5 units into the screen.
        glRotatef(roty, 1.0f, 0, 0);
        glRotatef(0, 0, 1.0f, 0);

        drawcube(0,0,0,0);
        drawcube(1,0,0,1);
        drawcube(2,0,0,0);
        drawcube(3,0,0,0);//draws a cube of a fixed size, first three arguments are the position of the
        drawcube(3,1,0,1);//upper left corner, the last argument is the pointer to the texture to use

        SDL_GL_SwapBuffers();

        SDL_Delay(10);

        if(firstround)
        firstround = false;
    }
Just a guess:
try glTranslatef(-camx,-camy,-camz);
Look closely:

1
2
        if(skpu)
            roty += 0.2f;  // <- roty  (not camy) 

I suppose I don't understand how either of those replies are related, the translation is my position, while it may be wrong, it's not affecting the rotation in anyway, and Disch the code already says
1
2
if(skpu)
    roty += 0.2f;

like you said.
no see

if you want skpu to move the camera, then it probably should be changing camy.

by changing roty, you're probably rotating the cube.
I want the camera to rotate upwards, as if the player is looking up.
It's supposed to rotate, not move.

Have you used OpenGL before?
oh, pfft.

I thought you meant you wanted to move the camera up/down. Not rotate it.

My mistake. Sorry about that.

Line 74 looks like it should be doing the trick. I don't see anything wrong with it. What effect does it have if not the desired effect?
It's rotating the bricks themselves in some odd way, like around a central point.
Another guess:
swap line 74 with line 73
I was thinking those might be backwards too, but I don't they are. If that works I'd be very surprised.

The only other thing I can think of would be that you're messing with the projection matrix and not the model view matrix (as I don't see any glMatrixMode calls there). That would cause weird things to happen, but I'm not sure if it would cause what you're describing.
Topic archived. No new replies allowed.