tags:

views:

447

answers:

4

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?

A: 

Main reason... Vector2 uses floats and fields instead of properties. This makes it more accurate and more efficient than Point, which uses integers and properties.

Matthew Whited
But there could certainly be a PointF class, as there is in System.Drawing: http://msdn.microsoft.com/en-us/library/system.drawing.pointf.aspx
Kyralessa
Thanks downvoters... any constructive comments?
Matthew Whited
A: 

At a certain level, you just want a tuple of numbers. Higher up you may want to apply some abstractions and structure over those tuples. However, as a high performance math library, XNAMath leaves that work up to you.

MSN
I don't understand this answer.
Kyralessa
+8  A: 

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.

Blindy
I guess this makes sense. I'd forgotten, but the Point structure in System.Drawing doesn't actually add a Point to another Point; it adds a Size to a Point. And I do recall doing vector arithmetic back in high school physics.
Kyralessa
A: 

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).

Will Vousden