• Advertisement
Sign in to follow this  

Spherical Coordinates Problem

This topic is 3035 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

I'm trying to rotate my third-person camera about a point defined to be fwdDistance units in front of a target model. I'm using spherical coordinates to do it, but when I rotate my model about the Y-axis, my camera zooms in and sometimes flips over the top of the model. I'd like to only move my camera in the Y direction if the player decides to move the camera itself, not the model. Here's my camera movement code. the -.5f is pitch, but I haven't defined that in a variable somewhere yet. fwdDistance is a constant as well as offset.Z.

Vector3 camLookAt = target.Position;
camLookAt.X += fwdDistance * (float)Math.Cos(target.Yaw * MathHelper.PiOver2);
camLookAt.Z += fwdDistance * (float)Math.Sin(target.Yaw * MathHelper.PiOver2);

this.position.X = camLookAt.X - (float)Math.Cos(target.Yaw)*(float)Math.Cos(-.5f)*-offset.Z;
this.position.Y = camLookAt.Y + (float)Math.Sin(-.5f * MathHelper.PiOver2)* offset.Z;
this.position.Z = camLookAt.Z - (float)Math.Sin(target.Yaw * MathHelper.PiOver2) * (float)Math.Cos(-.5f) * offset.Z;

this.view = Matrix.CreateLookAt(this.position, target.Position, new Vector3(0.0f, 1.0f, 0.0f));
In target.Yaw is only being updated by adding a constant value for each timestep. If anyone can figure out what I'm doing wrong, that would be great. EDIT: I realized what I really wanted was a cylindrical coordinate system for now. Currently players can't rotate the camera about the X axis and that's fine. [Edited by - kibokun on October 30, 2009 4:57:02 PM]

Share this post

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

  • Advertisement