Camera Rotation around Arbitrary Points

This topic is 3841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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=http://www.gamedev.net/community/forums/topic.asp?topic_id=382489]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;


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=http://img489.imageshack.us/img489/7133/glitchcamci3.jpg]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 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 on other sites
Perfect, thanks for that.

I actually was already using gluLookAt, but your lines of code following that fixed the problem.

Share on other sites
yup, spherical coordinates are the way to go for cameras

Share on other sites

This topic is 3841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628730
• Total Posts
2984427

• 25
• 11
• 10
• 16
• 14