# gluLookAt with same parameters rotates the camera

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

## 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 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 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 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.

• 9
• 13
• 40
• 15
• 11