Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Vector2 (from XNA's library) uses float not int?

Why Vector2 (from XNA's library) uses float not int?

Position on computer screen is given in pixels so that cursor position can be defined by two integers. There is no such a thing like half a pixel. Why we use floats then?

In SpriteBatch class I've found 7 overloaded methods called Draw. Two of them:

public void Draw(Texture2D texture, Rectangle destinationRectangle, Color color);
public void Draw(Texture2D texture, Vector2 position, Color color);

So we can see that Draw accepts both int and float coordinates.

I came across this problem when I've been implementing screen coordinates of my game's objects. I assumed that Rectangle is good choice to hold object's size and screen coordinates. But now I'm not sure...

like image 652
patryk.beza Avatar asked Dec 12 '22 02:12

patryk.beza


1 Answers

Mathematically, a vector is a motion, not a position. While a position on the screen might not technically be able to be between integers, a motion definitely can. If a vector used ints then the slowest you could move would be (1, 1). With floats you can move (.1, .1), (.001, .001), and so on.

(Notice also that the XNA struct Point does actually use ints.)

like image 162
Dave Cousineau Avatar answered Dec 28 '22 14:12

Dave Cousineau