Unexpected Camera Movement in Y axis

I’m trying to learn camera movement…but here when i go up in y-axis it dose’t move further after 90 degree and moves back down and then same till -90 degree…

Here i use this
gluLookAt(3 * cos(angle), 3*sin(angleY), 3 * sin(angle), 0, 0, 0, 0, 1,0);
i have doubt in above line, is that good or something is wrong?..

Here is my Inputs-

void KeyIn(int key, int x, int y)
{ 
	
    switch (key)
	
	case GLUT_KEY_RIGHT:
		angle += 0.1;
		Display();
		break;

	case GLUT_KEY_LEFT:
		angle -= 0.1;
		Display();
		break;

	case GLUT_KEY_UP:
		angleY += 0.1;
		Display();
		break;
	}
    }

to view full code Click here

If you’re controlling the angles directly, use glRotate and glTranslate rather than gluLookAt.

Assuming that you’re trying to specify yaw and pitch directly, the first three parameters should probably be:
gluLookAt(3*cos(angleY)*cos(angle), 3*sin(angleY), 3*cos(angleY)*sin(angle), ...);

If you try to “go over the top”, it will spin 180° around the Y axis, as the “up” direction is fixed.

woow…that’s working but how to avoid that 180 degree spin around the Y axis. Because i want to make it like same as 3D modeling softwares. :wink: :blush:

For an orbital camera, replace the gluLookAt with something like:

glTranslatef(0, 0, -3);
glRotatef(angleY, 1, 0, 0);
glRotatef(angle, 0, 1, 0);
1 Like

This post was flagged by the community and is temporarily hidden.

How to provide mouse input to above logic in glutMousefunc()?

Modify angle and angleY based upon the mouse position (either the current position or the difference between the current position and the previous position) then call glutPostRedisplay to force a redraw.

The matrix operations remain in the draw function; the input callbacks should only modify variables.

This post was flagged by the community and is temporarily hidden.

but now problem is that after clicking & moving, camera view always get sets to original view from where it started and then starts moving…below are inputs given to:

Here is my Camera View:

glTranslatef(0, 0, -5);
glRotatef(changeAngleY, 1, 0, 0);
glRotatef(changeAngleX, 0, 1, 0);
glTranslatef(-1, -1, 0);    

Here is my input given to glutMousefunc()

void MouseInput(int button, int state, int MouseX, int MouseY)
{
	if (button == GLUT_LEFT_BUTTON)
	{
		if (state == GLUT_UP)
		{
			angle += changeAngleX;
			angleY += changeAngleY;
			xOrigin = MouseX;
			yOrigin = MouseY;
		}
		else
		{
			xOrigin = MouseX;
			yOrigin = MouseY;
		}
	}
}

Here is my input given to glutMotionfunc()

void MouseMove(int MouseX, int MouseY)
{
	changeAngleX = (MouseX - xOrigin);
	changeAngleY = (MouseY - yOrigin);
	Display();
}

to view full code: Click here