Jump to content
  • Advertisement
Sign in to follow this  
aubergine

Camera Rotation around Arbitrary Points

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

If you intended to correct an error in the post then please contact us.

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 taby's code, 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 in this image. 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
Advertisement
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
Perfect, thanks for that.

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!