Reputation: 3057
Let's say I have a cube, and the cube's dimensions are 16 * 16 * 16, where each dimension starts at index 0, and ends at index 15. Every unit of that cube has to be stored separately; no two units can collide. If I'm trying to store the data in an array such as:
Unit[] units = new Unit[4096];
How would I go about correctly indexing objects? I can't seem to come up with a formula to do it correctly.
Upvotes: 1
Views: 137
Reputation: 285405
Just use modular math and think base 16
16 * 16 * z + 16 * y + x.
Upvotes: 4