Moving around a sphere

April 23, 2009

I said I would come back to the maths so here is a quick overview…

Moving an object around a sphere sounded very simple. However when I came to do it I wanted to be able to turn objects, left or right, relative to their current heading. It then became a bit more complicated. I started off using angles, theta and phi, to represent position but this has problems with Gimbal lock when converting to Cartesian Coordinates. Trying to move was also difficult, determining which angle to change is dependent on current position. i.e. When travelling North (decreasing phi) and you cross the North Poll you are now heading South (increasing phi) and theta has increased by 180 degrees. The result of which was to go to Quaternion maths.

There is a lot of stuff out there about the use of Quaternions in 3D games, and whether they are necessary, so I won’t try and repeat any of it here. I found that I could use this method of storing position and heading very efficiently. So now, all objects have their position held as a quaternion, with their current heading held as two further quaternions. Simple multiplication of these quaternions moves the object along its current heading. Changing heading simply means recalculating the two heading quaternions. There is no Gimbal lock and all objects can move relative to their position and not the underlying coordinate system.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: