PDA

View Full Version : Zooming problem



Fallen_Angel
03-29-2002, 09:10 PM
I'm basically trying to zoom in and out on my object using the mouse. However, when i zoom out as far as possible my object gets rotated upside down and starts zooming back in. Any help would be appreciated.

static void display()
{
glRotatef(Spin, SpinX, SpinY, SpinZ);
}

static void spinDisplay(void)
{
if (bRotating)
{
Spin += 1.0;
if (Spin > 360.0)
Spin -= 360.0;
}
else if (bZooming)
{
if (Spin > 360.0)
Spin = 360.0;
}
glutPostRedisplay();
}

//Mouse button is pressed.
static void mouseClick(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON)
{
if (state == GLUT_DOWN)
bRotate = true;
if (state == GLUT_UP)
bRotate = false;
}
if (button == GLUT_MIDDLE_BUTTON)
{
if (state == GLUT_DOWN)
bZoom = true;
if (state == GLUT_UP)
bZoom = false;
}
}

//Mouse is moved.
static void mouseMotion(int x, int y)
{
if (bRotate)
{
bRotating = true;
SpinY = 1;
Spin = x;
}
if (bZoom)
{
bZooming = true;
SpinY = 0;
Spin = y;
}
}

ThinIce
03-29-2002, 10:42 PM
It could be a few things, Are you usung glFrustum, or gluLookAt? another thing I think may be wrong is that you have the Z rotation enabled. Instead of doing so, add Take out the SpinZ in the glRotate and add this line:

glTranslatef(0.0f,0.0f,spinz);

so you have:


glRotatef(Spin, SpinX, SpinY, 0);
glTranslatef(0.0f,0.0f,SpinZ);


I think that might be it, not sure though.

[This message has been edited by ThinIce (edited 03-29-2002).]

Fallen_Angel
03-29-2002, 11:22 PM
I'm using gluLookAt() and no that didn't help my problem unfortunately.

ThinIce
03-30-2002, 11:00 AM
Ok, thats your problem then. GluLookAt() specifies a spot to look at all the time, you'll need to take that out, then add what I put in.

Fallen_Angel
03-30-2002, 04:38 PM
Umm no, I still can't get it working. Getting rid of the gluLookAt() sticks me right in the middle of my main object. Maybe this bug is elsewhere in my code, or I haven't had enough coffee yet this morning. Chances are I'll have just one line of code somewhere in the wrong place screwing the whole thing up. Thanks for trying though.

Furrage
04-03-2002, 08:10 AM
I have seen something like that with a program called Mark Morley's OpenGL Frustrum Culling Tutorial. I did not check but it seemed like his zoom played with different FOV's in creating his perspective view. Are you by any chance zooming by calling gluPerspective and adjusting your field of view. If so, you're FOV might be passing a limit that causes it to flip.