Game object maths

Started by
1 comment, last by apatriarca 14 years, 4 months ago
Hi guys, I'm just wondering whether you can help advise on the maths for managing my objects in the scene. The game is 2d / top down game. My objects are defined by a position vector, direction vector and a polygon bounding box for collisions. This is my thoughts on the problem: - Use position and direction vectors for the object's position and rotation in world space - Move the objects though world space using matrixes (ie move forward, turn etc) - Define the polygon bounding box in model space (instead of world) - For each frame, calculate Model to World matrix based on world position and direction - For each frame, transform model space polygon with model to view matrix. The world space polygon will be used for collision detection. Is this sound? I want to store the polygon in model space because i figure if i keep transforming it in world space it will lose shape over time because of limits in float point accuracy. Transforming the model space with a matrix on each frame will give better results. Should I be using Quaternion instead of matrixes? I don't really understand what they are. I've got a customer built matrix library but feel behind the times lol. Thanks for the tips guys!
Advertisement
That sounds pretty good. In my set-up I actually store angle and angular velocity rather than a direction vector because it's easier to deal with spinning objects and angular acceleration from physical forces, but if your game isn't physics based a direction vector should work fine. If you're not sure if you should use quaternions than you probably shouldn't. Quaternions are good for chaining lots of rotations together and interpolation between orientations(slerp).
If you are working in 2D, not 3D, then quaternions can't be used. They can be used in fact to represent orientations and rotations in 3D. Since in a 2D world everything is much easier, the rotations are for example commutative, there is no need to use something like that. But in 2D you can use the complex numbers. They are 2D vectors with an additional operation, the multiplication, which represent a rotation. So you can simply use complex numbers, instead of simple 2D vectors, and you obtains a lot of advantages: rotations and orientations can be naturally represented without using angles and trigonometry directly, there are a lot of useful functions...

This topic is closed to new replies.

Advertisement