Sign in to follow this  
rejak

gluLookAt with same parameters rotates the camera

Recommended Posts

I don't understand how glulookat works. I thought gluLookAt is a funtion you can tell, where the camera is, where the camera looks at and whats the upper side of the camera. So if you call gluLookAt multiple times with the same parameters nothing should change, but in my program the camera starts to rotate.

void Graphics_Engine::render(Hex_Board::hex_tile const * const * const tiles_list, uint16_t tiles_count)
{
    double x, y, x_i, y_i;
    double angle;

    glColor3f( 0.0f, 1.0f, 0.0f);
    //glRotatef(0.25, 1, 0.5, 0.1);
    gluLookAt(0.0f,0.0f,-5.0f,0.0f,0.0f,1.0f,1.0f,0.0f,0.0f);

    for (uint16_t i = 0; i < tiles_count; i++)
    {
        glBegin(GL_LINE_LOOP);
        x = sqrt(3.) * (tiles_list[i]->q + tiles_list[i]->r/2.);
        y = 3./2. * tiles_list[i]->r;

        for (uint8_t i = 0; i < 6; i++)
        {
            angle = 2. * M_PI / 6. * (i + 0.5);
            x_i = x + cos(angle);
            y_i = y + sin(angle);
            glVertex3f(x_i, y_i, 0);
        }
        glEnd();
    }

    SDL_RenderPresent(renderer);
    glClear(GL_COLOR_BUFFER_BIT);
}

Share this post


Link to post
Share on other sites

gluLookAt accumulates the transformations, so every call to gluLookAt will accumulate the rotations and translations from the previous calls, unless you reset the transformation matrix in between. You probably want to call glLoadIdentity somewhere before gluLookAt.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this