No matter how many times I run into this kind of thing, I’m always a bit surprised…
Long story short… I am working on a little tile based thing to familiarize myself with the core XNA libraries. I’m using a long int (32-bit) to store X and Y position. Simple enough.
I want to track a position within each tile as well as which tile any specific object is on, and briefly wondered whether I should use two variables (a TileX and a subTileX, for example) instead of using the single X position to determine both. Given the situation, I figured there was no risk in just using the single variable scheme (X, Y) for both, but then I got curious… exactly how large a map could I make?
Well, I figured splitting each tile, which represents a 5 foot square in my little design here, into a 100×100 grid would be more than sufficient (maybe 128×128 to use binary masking and shifting as opposed to having to mod 100 all the time, I’ll figger that out later.) That’s fractions of a pixel when you translate to the screen, and essentially locating a person within about 1/2 scale inch. Close enough, I should think… 😉
So, a long unsigned int ranges from 0 to 4 billion and some change.
Translate to tiles: 4 billion divided by the 100 units per tile equals 40 million tiles. In each direction, both North-South and East-West… and I was momentarily worried. LOL. Okay, let’s take this a bit further…
Translate to scale feet: appx 40 million tiles times 5 feet per tile equals 200 million feet.
Translate to scale miles: appx 200 million feet divided by 5280 is approximately 38000 miles.
By comparison, the circumference of the earth at the equator is only about 25000 miles.
In other words, two simple long integers are far more than enough to define where you are on the surface of the earth to within one half-inch. Throw in a third for the Z axis, and you can be about a tenth of the way to the moon, as well.
Good enough for a little test app, I should think :boggle: