I'm used to WinForms graphics, but I've been dabbling in XNA, and one thing I've noticed is that the Point
object isn't very useful, and doesn't seem to be used very much. For positioning, the various SpriteBatch
Draw methods use either a Rectangle
or a Vector2
. And Vector2
has a lot of useful static and instance methods, whereas Point
has basically nothing except the X and Y properties.
Why does XNA use a Vector2
to represent position instead of a Point
? I realize they both have an X and a Y, but semantically and logically, using a Vector2
instead of a Point
to represent location makes no sense to me. (For instance, if you normalize the Vector2
, suddenly you have a different location!)
Is this as strange as it seems, or am I missing something?
Even assuming Point
were using float values, what meaning would you give to "adding 2 points together"? Now adding vectors to update positions is a well understood and widely used concept, so vectors map better to describing positions and speeds in a virtual world.
Semantically there's little difference between a vector and a point; they both represent a displacement from an origin in some Cartesian coordinate system. The advantage of vectors is that they have more structure (scaling, addition, etc.) than points.
For example, you might want to find the displacement of one entity from another: this is simply the vector difference between their respective position vectors. They're also more versatile in representing other quantities, such as velocity. For example, you might want to calculate the position of an entity with position r
and velocity v
after a time interval t
; using vectors, this could be calculated simply by r + t * v
.
Your example of normalization could be useful if you want the direction to the entity from the origin (or some other point).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With