Graphics: Why floats for coordinates?
In many graphics libraries I've seen coordinates stored as floats
or doubles
. My question is, why should they not be stored as simple integers? What more precision can you get, the double is still going to have to be converted to an integer at some point (you can't blit an image on the screen starting from pixel 45.8, for examp开发者_StackOverflow中文版le :P ).
In theory, you can blit an image from 45.8. It's more about the coordinate system, in which the graphics library utilises, and how they manage translation and transformation of graphics etc. Moving an image via, Vectors is a good example...
i.e. Polar Coordinates, or the Cartesian coordinate system in relation with a 2D coordinate systems...
An example, you want a ball graphic to randomly bounce around a windows form. An intuitive way to accomplish this is:
first, bounce back the canonical way (dx = -dx or dy = -dy depending on the collision)
then convert the dx and dy to polar coordinates (theta and r)
jitter theta by a small amount (+ or - a few degrees, according to your taste)
make sure theta isn't heading into a wall that you just bounced off
convert theta and r back to dx (x) and dy (y) coordinates (which are of an integer data type)...
Get the drift?
May find this useful.
精彩评论