max-mapper / voxel-engine

3D HTML5 voxel game engine
http://maxogden.github.com/voxel-engine
BSD 3-Clause "New" or "Revised" License
1.29k stars 220 forks source link

Handling a globe #91

Open greenlion opened 10 years ago

greenlion commented 10 years ago

I would like to model large3d bodies seamlessly. The world coordinates seem to be able to go infintely in all directions. I'd like to be able to define a boundary where the world "wraps around".

Is there a relatively easy way to do this?

shama commented 10 years ago

You could write a generator that calculates using modular arithmetic. See this section of the docs: https://github.com/maxogden/voxel-engine#generating-voxel-worlds

Something like var partX = Math.floor(x % boundary); although to handle negative numbers, I recommend a library like this: https://github.com/hughsk/mod-loop

greenlion commented 10 years ago

I'm actually using SRTM data, so a simple generator function won't do. The data is mapped into tiles which make up the globe. I can coordinate positions using latitude and longitude so I basically need to see the other side of Greenwich when you approach the prime meridian.

Which means it is easy to just stream the area I need and it will just work, and I'm a dummy :)

Thanks :)

Is the mindflayer bot still the best example for streaming input?

rachel-carvalho commented 10 years ago

I'm actually trying to implement the exact same thing in voxel-mars (except with MOLA data). I also have tiles with chunks of world data (I've generated PNGs from raw .img files) and what I'm doing is using game.voxels.on('missingChunk') to generate each chunk based on pixel data from those images. And then I load each PNG tile as needed.

I have just started working (on a local branch) on world wrapping and what I'm doing is translate x -1, for instance, to the same latitude/longitude values as x MAX. I had started actually writing code to teleport the player to the correct x when he stepped into this zone, but it had a major impact on performance, so I'm considering just have the world repeat itself as many times as needed and not having only one X,Z coords mapped to one latitude/longitude. I wonder if that's going to be a problem for me in the future when I have multiple players and world interaction.

shama commented 10 years ago

Wow that is impressive @rachel-carvalho!

I was also building a voxel-mars but never finished it based on the MOLA data: https://gist.github.com/shama/92c94b257518dd9a5f63

It uses https://github.com/shama/voxel-tile to load the color/heightmap tiles. It tries to load the tiles at different Z based on how high up the player is. The goal being to render the entire planet when you're far enough away. Here is a screenshot: https://twitter.com/shamakry/status/348290172644892672 and https://twitter.com/shamakry/status/348283103908880384

Not sure if any of that code would be any use to you. Glad to see someone making a way more awesome voxel-mars! :D

shama commented 10 years ago

Oh and here is the part that infinitely repeats chunks, just a simple modulo: https://github.com/shama/voxel-tile/blob/master/index.js#L83

rachel-carvalho commented 10 years ago

It's a shame I didn't find it before, I'll definitely take a look at it and see what I learn from it.

I guess I'll just keep infinitely repeating the world and when I have multiple players and world interaction, I'll probably just work with those absolute coords, because each player will potentially have their own local offset from the starting point.

greenlion commented 10 years ago

I guess you could keep two sets of coordinates, one relative to each meridian. All you have to keep track of is which hemisphere the user is standing in. As they approach a meridian, you can determine if the chunk is on the other side and grab it appropriately. Then all you do is switch the hemisphere flag when you cross the meridian. All players then use game coordinates.

rachel-carvalho commented 10 years ago

Yeah, that's basically what I'm going to do, except I'll be able to use the modulo approach @shama mentioned, since my in-game coords are never negative (my 0,0 is at the top left of the map, instead of in the middle like latitude and longitude).

kumavis commented 10 years ago

Great discussion! - As mentioned above, I feel like this is an issue for implementation and not for the engine. Maybe we could start a Implementation FAQ on the wiki and add this to it.

greenlion commented 10 years ago

Hi,

I think an implementation FAQ is a good idea on working toward getting the API document. It should be easy to look up exactly what options can be passed into the game.

Also, would it make sense to document the core modules with JSDoc? If someone did that (it would be a good way to learn the API) would people mind keeping the JSDocs up to date when they make changes?

On Mon, Dec 30, 2013 at 11:19 AM, aaron notifications@github.com wrote:

Great discussion! - As mentioned above, I feel like this is an issue for implementation and not for the engine. Maybe we could start a Implementation FAQ on the wiki and add this to it.

— Reply to this email directly or view it on GitHubhttps://github.com/maxogden/voxel-engine/issues/91#issuecomment-31362773 .

shama commented 10 years ago

Oh yeah, btw @rachel-carvalho and @greenlion, feel free to jump into #voxel.js on irc.freenode.net. Where a lot of the voxel chat happens :)