Hey,
many people seem to struggle with the concept of “infinite” galaxies and zoom stages. With naive and direct approaches the limits of processing are quickly met and thus frustration sets in quickly. Actually the code to do “partitioning” etc. isn’t all that complicated or long, the following video is this single java file
What the app does:
- Creates a galaxy with “POIs” that you can move to and then proceed to move into it to be in a new galaxy with new POIs, this can be done infinitely
- Displays spheres in each galaxy that move by physics and also collide with the POIs and each other
- Coordinates look like x,y,z / x,y,z / x,y,z etc. where each tuple defines one level of accuracy (100 unit radius)
What the code does:
- The camera stays at 0/0/0
- Each “inception level” is an AppState that is only attached when the level is the current level or a displayed child
- The rootNode of the AppState is moved around the camera based on player movement
- Close POIs are attached instead of POI sphere and the current as well as the child node is scaled gradually
- Physics is applied locally
- Only data of current galaxy and visible child is kept
- For “zooming in”, only very few data about the current parents is kept, all other data and the physics space are discarded, so you can really pretty much zoom in all your lifetime
- Its single-threaded and performs fine
Extending and using the code:
- Galaxies are based on a seed that is the hash of their position, this hash could already be used to pull a full world out of a database and do persistence (or network sync? ;)). However for having every world be unique you’d have to change to something else than int (double also won’t cut, use UUIDs)
- The code actually works with free coordinates without having to define any POIs but there is no tracking of contiguous space built in. That should be relatively easy though. Then you can move sideways between galaxies as well as have the option to zoom in at any point.
- You can use the rootNode of each space like any normal rootNode and do things with “normal” local coordinates
- You could use skyboxes or particles for displaying the parent POIs in a child
- As the other POIs actually move very far away and scale up when you zoom in (despite the fact that it looks like they’re quite static) you can use fog and/or LOD to smoothly make the outer galaxies disapper (into a sky :))
- To extend to multi-player / multi-view you can simply use one set of InceptionLevels per character or you can extend the tracking of positions in the InceptionLevel
- You can in theory leave as many galaxies active as you want
TODO/Issues:
- Add picking through galaxies. This is actually pretty simple now. The physics space for any child only has to be instantiated if a ray test successfully hit a poi, this would be done down to the last child that yields a raytest result (which will probably due to monitor resolution seldom be more than one or two levels ;))
- Small issue with detaching stuff when you are close to two POIs, lazyness
- Code churns through math objects like candy, should be optimized for mobile VMs without proper JIT (multLocal, TempVars etc.), no problem on desktop
- Rotation. Basically you just have to rotate the rootNode
I’ll document the code a bit more and add some features maybe, hit me with any questions that might pop up
Cheers,
Normen