• Create Account

gluLookAt with same parameters rotates the camera

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

#1rejak  Members   -  Reputation: 114

Like
0Likes
Like

Posted 22 August 2013 - 05:52 AM

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


#2Brother Bob  Moderators   -  Reputation: 6470

Like
2Likes
Like

Posted 22 August 2013 - 06:11 AM

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.

#3rejak  Members   -  Reputation: 114

Like
0Likes
Like

Posted 22 August 2013 - 06:19 AM

thanks, one question: Is UP a direction vector relative to the position-target vector, or is it absolutley?

Edited by rejak, 22 August 2013 - 06:22 AM.

#4Brother Bob  Moderators   -  Reputation: 6470

Like
1Likes
Like

Posted 22 August 2013 - 06:56 AM

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.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS