
Vectors are also the native representation for position, geometry, and motion used by nearly all graphics libraries-and certainly OpenGL and DirectX. When the planet moves, you change its transform, and the ship and drone automatically get positioned "for free". The planet uses its transform, the ship uses its transform and the planet's transform, and the drone uses its transform and the ship's transform and the planet's transform. With vector math, we represent each as having a point and a 3x3 transform matrix. The calculation for this without using vector math is really, really ugly. A planet has an orbiting ship, the ship has an orbiting drone.

If you are in 2D, perhaps the best way of achieving complex effects and motions (spinning, scaling, etc.) is to use a scene graph.
Coords meaning code#
This is very handy, and also now lets you easily have radars that point in different directions (just change the forward vector) and have different widths (just change the radar width angle)-and you can reuse the same code for those cases too!

Suppose you have a radar system in a top-down style game. However, the advantage to using vectors is that they neatly represent things such as direction and position, and also have several mathematical operations defined on them that make your life easier.įor a simple example of these, consider the dot product. As long as you are keeping track of x and y, or whatever coordinates you care about, in some way you are fine. While you will commonly find vectors being used for geometry in games, there is no reason you can't do something else with them.įirst, you never have to use vectors. Note that in all cases, we've assigned meaning to the vectors for our problem. Each coordinate in a vector represents some absolute position in that direction of the space the vector is in. Vectors are sets of coordinates of varying dimension.
