gluLookAt around circle

Here is image: http://img861.imageshack.us/i/camk.jpg/

I would like to circle camera around object on scene. Circle ray = 100.
I have that code but the movement camera is strange:


float rotateValueX = 0;
--------------------
if (rotateValueX >= 360) rotateValueX = 0;
else rotateValueX += 1;

	float xCircle = 100 * cos(PI * rotateValueX / 180);
	float yCircle = 100 * sin(PI * rotateValueX / 180);
	gluLookAt(xCircle, 0, 100,  0, 0, 0,  0, 1, 0);

And if I change
gluLookAt(xCircle, 0, 100, 0, 0, 0, 0, 1, 0);

to
gluLookAt(xCircle, 0, yCircle, 0, 0, 0, 0, 1, 0);

it is also bad because once object is far and another is near

you really don’t know ?

lols?

it’s not funny :stuck_out_tongue:

ok well with glulookat()
the first 3 numbers make up the coordinate where the camera sits
the next 3 numbers make up the coordinate where you want the camera to look at
or you can think of it as where the object you are trying to look at sits
the last three numbers is the camera up
so normally up is x=0, y=0, z=1
but sometimes people put y as up
you can try both and see what happens and look at the code
and see which way is up in your code
it helps to draw colored cubes or lines to help you orient yourself in the opengl world

ok so to circle around the the object you have to set the camera view which is your glulookat() numbers 4 5 6 to the coordinates of your object
then the camera position glulookat() numbers 1 2 3 would be the numbers from the formula

you cant have gluLookAt(xCircle, 0, yCircle, 0, 0, 0, 0, 1, 0);
because ur telling the camera to make 2 circles in different directions at the same time so it will probably start flashing the image

gluLookAt(xCircle, 0, 100, 0, 0, 0, 0, 1, 0);
this one cicles around the center of the world but its 100 units above the object looking down at it so i would make 100 to 0 here
and change the last 3 numbers to 0,0,1 because the way you have it the camera is laying on its side

People I am close but still need Your help ! :slight_smile:

It works great if I comment this line in below code:
glTranslatef(10, 30, -135);
but I need this translation to cube so what can I do ?


        float xCircle = rotateValueZ * cos(PI * rotateValueX / 180);
	float zCircle = rotateValueZ * sin(PI * rotateValueX / 180);
	
	gluLookAt(xCircle, 0, zCircle, 0, 0, 0, 0, 1, 0);

	glPushMatrix();
		//glTranslatef(10, 30, -135); //without this it works great
		glRotatef(90, 0, 0, 1);
		glScaled(0.2, 1, 0.2);
		glutSolidCube(30);
	glPopMatrix();

omg wut r u doing?
fine if u want to move ur weird cube to 10, 30, -135
then u need to move ur camera view to
gluLookAt(xCircle, 0, zCircle, 10, 30, -135, 0, 1, 0);
once u grasp how the lookat works you will see what your numbers should be
remember the lil kid in the matrix
be that kid!
throw the spoon in neos face lol jk

Hm… but I have more objects on scene with different coordinates:


        glPushMatrix();
		glTranslatef(10, 30, -135); 

		glRotatef(90, 0, 0, 1);
		glScaled(0.2, 1, 0.2);
		glutSolidCube(30);
	glPopMatrix();

        glPushMatrix();
		glTranslatef(40, 10, -100); 

		glRotatef(90, 0, 0, 1);
		glScaled(0.2, 1, 0.2);
		glutSolidCube(30);
	glPopMatrix();

........

so I can’t write in gluLookAt() 10, 30, -135 - what is the solution in that case ?

then maybe u would focus in the center of all the objects?
zoom out perhaps?
this is where it becomes YOUR world

camera.pos ( o-)-------------------> :smiley: :eek: :frowning: camera.view

but I have more objects on scene with different coordinates:

So, you want to have the camera looking directly at an object in your scene, yes?

Well, the first thing you need to do is figure out which object you want the camera to be looking at. A camera cannot be looking directly at two objects at once (unless the camera’s position is fixed to be collinear with the two objects. and then one of them will be obscuring your view of the other). So you need to pick one to be looking at.

gluLookAt takes 3 vectors. In order: the camera’s position in the world, a point in the world that the camera needs to be looking at, and a vector that represents the “up” direction for the camera.

The position of whatever object you’re rotating around needs to be the second of the three vectors you pass into gluLookAt.

Now, if you want to rotate the camera around this point, you must actually do that. You must define a circle centered at the target point, and rotate around that. So your computations of the camera position need to take into account the target point.

I would like to rotate all scene around Y (on which I have many objects) using camera - is it possible ?