gluLookAt

With gluLookAt, am rotating the camera around my object. but at a certain angle the object flips around, so i see it upside down. what can cuase that? and how can i arrange that?

here’s the function. when the user clicks the left button, i want it to zoom where the user clicked. (that is working perfectly) and when the user clicks on the middle button i want to rotate the cam around the object.

void Viewer::mouseDrag(int x, int y)
{
	Viewer *ViewerPointer = Viewer::GetInstance ();
	ViewerPointer->FrameRate = 0;
	if (ViewerPointer->LeftMouseDown)
	{
		if (y > ViewerPointer->LastMouseY)
		{
			ViewerPointer->eyez += 2;
			ViewerPointer->Rayon += 2;
		}
		if (y < ViewerPointer->LastMouseY)
		{
			ViewerPointer->eyez -= 2;
			ViewerPointer->Rayon -= 2;
		}	
	}
	
	if (ViewerPointer->MiddleMouseDown)
	{
		if (x > ViewerPointer->LastMouseX)
		{
			ViewerPointer->eyey = ViewerPointer->Rayon * sin(ViewerPointer->RotationAngle);
			ViewerPointer->eyez = ViewerPointer->Rayon * cos(ViewerPointer->RotationAngle);
			ViewerPointer->RotationAngle -= 0.01;
		}
		if (x < ViewerPointer->LastMouseX)
		{
			ViewerPointer->eyey = ViewerPointer->Rayon * sin(ViewerPointer->RotationAngle);
			ViewerPointer->eyez = ViewerPointer->Rayon * cos(ViewerPointer->RotationAngle);
			ViewerPointer->RotationAngle += 0.01;
		}
	}
	ViewerPointer->LastMouseX = x;
	ViewerPointer->LastMouseY = y;
	glutPostRedisplay();
}

Originally posted by Raiden:
[b]With gluLookAt, am rotating the camera around my object. but at a certain angle the object flips around, so i see it upside down. what can cuase that? and how can i arrange that?

here’s the function. when the user clicks the left button, i want it to zoom where the user clicked. (that is working perfectly) and when the user clicks on the middle button i want to rotate the cam around the object.

void Viewer::mouseDrag(int x, int y)
{
	Viewer *ViewerPointer = Viewer::GetInstance ();
	ViewerPointer->FrameRate = 0;
	if (ViewerPointer->LeftMouseDown)
	{
		if (y > ViewerPointer->LastMouseY)
		{
			ViewerPointer->eyez += 2;
			ViewerPointer->Rayon += 2;
		}
		if (y < ViewerPointer->LastMouseY)
		{
			ViewerPointer->eyez -= 2;
			ViewerPointer->Rayon -= 2;
		}	
	}
	
	if (ViewerPointer->MiddleMouseDown)
	{
		if (x > ViewerPointer->LastMouseX)
		{
			ViewerPointer->eyey = ViewerPointer->Rayon * sin(ViewerPointer->RotationAngle);
			ViewerPointer->eyez = ViewerPointer->Rayon * cos(ViewerPointer->RotationAngle);
			ViewerPointer->RotationAngle -= 0.01;
		}
		if (x < ViewerPointer->LastMouseX)
		{
			ViewerPointer->eyey = ViewerPointer->Rayon * sin(ViewerPointer->RotationAngle);
			ViewerPointer->eyez = ViewerPointer->Rayon * cos(ViewerPointer->RotationAngle);
			ViewerPointer->RotationAngle += 0.01;
		}
	}
	ViewerPointer->LastMouseX = x;
	ViewerPointer->LastMouseY = y;
	glutPostRedisplay();
}

[/b]
Hello there, Hey what is the rayon variable here is it used for object picking or what? Secondly the lookAt function has the last three floats called the view up vector check it out to see if you are altering it in your code somewhere, b/c view up vector provides the upright positiojning of the camera. See if it helps tahnx
MMMovania

Originally posted by MMMovania:
Hello there, Hey what is the rayon variable here is it used for object picking or what? Secondly the lookAt function has the last three floats called the view up vector check it out to see if you are altering it in your code somewhere, b/c view up vector provides the upright positiojning of the camera. See if it helps tahnx
MMMovania
the rayon variable is for the rotation of the camera, it must rotate in a perfect circle around the object and it only to calculate the place where the camera will be when the user drags the mouse. Also the up vector isn’t changed. i tried to flip it over when the object is flipping around and it didn’t change anything. :frowning:

Which matrix stack is active when you make the glulookat call?

It should be the modelview, not the projection.

I also had seriously strange behaviour using glulookat, but I was putting it on the projection matrix.

Haven’t checked yet if putting it on the model view solves the problem, so I don’t know exactly when in the sequence of transformations it should go on the stack…

Check this link out, it’s quite interesting.
sjbaker.org/steve/omniv/projection_abuse.html

CJ

ok, now its working, but i now got another problem… i want that when the user drags the mouse going up i zoom in, but when he moves it down i zoom out.

when the application starts it works just fine, but if i rotate more than 90 degrees, its not doing what u want.

how can i solve that problem?

nm, i solved my problem