Rotating around a pivot point

Started by Meanz, August 18, 2011, 12:05:50

Previous topic - Next topic

Meanz

Hey hey, I know this is fairly basic stuff, but as smart as I am, I was unable to find any topics about this manner. I know I could resolve this with some easy logic and thinking, but for some reason my head ain't working today.

Here is my issue.



I have a camera that I wan't to rotate around a pivot point (My character)
The camera rotation box is marked in red, and the character is the black square.

Would anyone mind lending me a hand here, I am currently using GLU.lookAt

Fool Running

Yes, GLU.gluLookAt() would be the easiest way to accomplish what you are looking for. Basically you just give it the camera location and the location where you want it to point (your character) and tell it which direction is up and you should have what you want. ;D
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Meanz

Yeah that much I figured, but I can't seem to connect theese things in my head.
So I am unable to produce the result



I am only able to pivot the camera as the green circle shows.

Quote
GLU.gluLookAt(position.x, position.y, position.z, target.x, target.y, target.z, 0.0f, 1.0f, 0.0f);
glRotatef(yaw, 0f, 1f, 0f);

I never did understand the x,y,z parameters for glRotatef so if you could explain them it would also be nice ;)

Quote((ChaseCamera) gameScreen.getCamera()).setTarget(human.getPosition());
        gameScreen.getCamera().setPosition(new Vector3f(
                human.getPosition().x + (3f * (float) Math.sin(Math.toRadians(human.yaw))),
                human.getPosition().y + 4f,
                human.getPosition().z - (3f * (float) Math.cos(Math.toRadians(human.yaw)))));

Chuck

The x,y,z parameters to glRotate* describe a unit vector from the origin (it'll be normalized if it isn't already) that describes an axis to rotate around.  In other words, if you have a vector of (1,0,0), it'll rotate around the X axis.  If you use (0,1,0) it'll rotate around the y axis, and so on for the z axis.  A vector of (1,1,1) will rotate around an axis that's 45-degree angle from all of the axes.

The rotation follows the right-hand rule, meaning as you look down the vector to the origin, the direction of rotation is counterclockwise.  It's called the right handed rule because if you hold out your right hand and point your thumb in the direction of the vector, the rotation will follow the direction in which your fingers curl.

Meanz

I see, but I still have to figure out how to rotate around a pivot point, I can somehow rotate a object around another object by using glTranslate and glRotate

But When I try to do this with the camera, I am unable to rotate it right. There is some key I am missing.. But.. Again that is why I posted here ;)

Thanks for the info Chuck.

Fool Running

The easiest way to do this is to calculate the location of the camera relative to your player (i.e. use your old sine and cosine functions to determine the location of the camera). Then you can use that location in the gluLookAt() function.
I'm not sure, but I don't think you can use glTranslate and glRotate to "move" your camera around your player, OpenGL works the opposite way. (i.e. the world moves relative to the camera).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Chuck

You can use glTranslate and glRotate to orbit the camera -- you just have to reverse the directions to transform the object instead of the camera.   Moving a FPS camera this way is super-simple, but for an orbiting camera it's just a whole lot easier to use gluLookAt.

Meanz

I will try my best and post the results. Thanks for the information. I still have a lot to learn and I love it when the community is helping.