Jump to content
  • Advertisement
Sign in to follow this  
rejak

gluLookAt with same parameters rotates the camera

This topic is 1823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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
thanks, one question: Is UP a direction vector relative to the position-target vector, or is it absolutley? Edited by rejak

Share this post


Link to post
Share on other sites

The up-vector is in the same coordinate space as the position and target points, although a vector and not a point. The point (position+up) is always a point up from the view point.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!