PDA

View Full Version : gluLookAt



Raiden
04-11-2005, 09:37 AM
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();
}

MMMovania
04-11-2005, 06:47 PM
Originally posted by Raiden:
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();
}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

Raiden
04-12-2005, 05:34 AM
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
MMMovaniathe 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. :(

charliejay
04-12-2005, 06:34 AM
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

Raiden
04-12-2005, 09:14 AM
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?

Raiden
04-12-2005, 10:11 AM
nm, i solved my problem