Viewing

Hello everyone.
I am trying to define i spherical view volume.
This is what i mean:

void Passive(int x , int y)
{
	float Xnew = x, Ynew = y;

	glClearColor(0.0,0.0,0.0,0.0);
	glClear (GL_COLOR_BUFFER_BIT);
	

	Xnew = ( x / 500.0 ) * 360.0;/* Window is 500x500 */
	Ynew = ( y / 500.0 ) * 360.0;/*So converting 0-500*/ 
                                     /* to 0-360 degrees */
	
        theta = (Xnew * 3.14 / 180.0);
	phi   = (Ynew * 3.14 / 180.0);
	

	Xnew = 300 * sin(theta) * cos(phi);
	Ynew = 300 * sin(theta) * sin(phi);
	Z    = 300 * cos(theta);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity (); 
	gluLookAt (Xnew , Ynew , Z ,0.0 , 0.0 ,0.0, 0.0, 1.0, 0.0);

	glColor3f(1.0, 0.0 ,0.0);
	glutWireCube (200);

	glColor3f(1.0, 1.0 ,1.0);
	glutWireSphere(100, 20 , 20);
	
	glFlush ();
}

So i am tryiong to convert the 0-500 coordinate walues to 0-360 degrees range and using gluLookAt() to look at the rendered scene.

Now, this is working for the X axis. ie when i move my mouse on the X axis(changing X coords) , i can see the object from different angles. But this is not happening for the change in Y coordinate values!

Can anyone please explain what im doing wrong?
Thanks in advance.

Hmm…

Depends which axis is ‘up’

Let’s assume y is up.

You can test these independeintly

for xmouse you need:
x = cos(theta)
z = sin(theta)

for ymouse you need:
x = cos(phi)
y = sin(phi)

Test these independently, then

To combine them I think you need something like:

x = cos(theta) * cos(phi)
z = sin(theta) * cos(phi)
y = sin(phi)

Obviously scale them by distance from origin.

Thanks for the reply Dorbie.

I changed the program as per your advice.Again, its working along X axis. But along Y axis, it rotates for some angle and then rotate backwards.

Im afraid i have not understood the ‘UP vector’ concept properly.

Now the ‘Up vector’ and the ‘LookAt’ vector have to be perpendicular right?

In this case, when i changed my ‘Up vector’ to (0,0,1) , i must not be able to see anything right?
Because im looking at (0,0,0) and Up vector is the Z axis,

Then how am i still able to see the object?!

Can you please suggest some links that would help me understand regarding the ‘Up Vector’ .

I googled it.But could not the links find very useful.

Im new to OpenGL.It would be great if you could please help me.
Thanks a lot!