Sign in to follow this  

Camera Rotation around Arbitrary Points

Recommended Posts

Hi all, Apologies for the pretty generic title -- I've spent the past hour or so searching the forum for help, but most camera class threads end up talking about matrices, which isn't quite my problem. I got my camera class working with some help from [url=]taby's code[/url], and I'm able to rotate a camera around the y-axis to my heart's delight. The code in question:
	oldPos = target->position - position;

	position.x = ((oldPos.x * cos(hRadians)) + (oldPos.z * -sin(hRadians)));
	position.z = ((oldPos.x * sin(hRadians)) + (oldPos.z * cos(hRadians)));
Obviously there's nothing in there to account for any changes in the origin, and I'm trying (and failing) to add that functionality now. I threw in this line: position = target->position - position; at the end, and it works to a point, but I get awful glitches, as you can see [url=]in this image[/url]. Does anybody have any idea how to tackle either problem? I'm not even sure adding that troubling line does fix my problem (graphical glitches aside). I'd really appreciate any help you could offer. Cheers!

Share this post

Link to post
Share on other sites
the simplest method would be to use
gluLookAt(cam.x,cam.y,cam.z, camtarget.x, camtarget.y, camtarget.z, 0,1,0 )

off the top of my head (so mightnt be correct)

cam.x = camtarget.x + ( sin(rot) * cos(roty) ) * dist;
cam.z = camtarget.z + ( cos(rot) * cos(roty) ) * dist;
cam.y = camtarget.y + sin(roty) * dist;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this