Infinite zoom galaxy with physics (Example Code)

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 :wink:
  • Its single-threaded and performs fine :smiley:

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 :wink:
  • 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 :slight_smile:

Cheers,
Normen

12 Likes

Nicely done! :smiley:

A little hint for anyone who wants to make a visually more impressive app with this… :wink:
When zooming into a POI the parent gets scaled and the other POIs move very far away, they only look like they’re relatively static then cause they are also getting larger. This makes using fog to hide the outer POIs pretty effective, note the outer two POIs fade away gradually in the video below, I just added a normal FogFilter with black color. I updated the post with this and a few other hints for usage of this code.

@normen This is so cool =)

Nicely done!!

EDIT: I almost left this thread without referring to balls in my face… but… eh… yeah

1 Like

hey, I like the video, but when I try testing it in my pc, has a error “Package com.jme3.bullet.debug.DebugTools does not exist”, can you help me? i need test it, because i was loving so much the video!

@galaxiadegames, I think you need to use the jME nightly build.

1 Like

I like this, thanks for the example. I have been quite lucky with your posts lately @normen, every time I have an issue, you post a somewhat related solution. :slight_smile:

I have been dealing with z-fighting, during large translations, on my 32-bit machine. Initially I just scaled the world down by a factor of 1000, which solved my numeric issues, but made my life hell, when calculating relative distances and directions. I had just decided to try to translate the terrain instead of translating my avatar. I’ll def. be having a look at this for a few hints on that. Cheers!

1 Like
@kwando said: @galaxiadegames, I think you need to use the jME nightly build.

@kwando, “use jME nightly build”, I no understand how use it, can explain with more details?

The nightly build is the most resent build, if you are unfamiliar with this, it is probably easiest for you to use the direct download, instead of SVN. http://www.jmonkeyengine.com/nightly/

However, if you just want to make this example run, you can just comment out the use of the DebugTools, they are not really required to make the example run, it’s just a visualization of the underlying logic.

1 Like
@nihal said: The nightly build is the most resent build, if you are unfamiliar with this, it is probably easiest for you to use the direct download, instead of SVN. http://www.jmonkeyengine.com/nightly/

However, if you just want to make this example run, you can just comment out the use of the DebugTools, they are not really required to make the example run, it’s just a visualization of the underlying logic.

thanks