views:

123

answers:

3

What is the best mechanism for handling large scale structures and scenes?

Examples being a continent with scale cities and geography, or infinity universe style planetary transitions.

+1  A: 

Taken from http://www.gamedev.net/reference/business/features/spotlightFB/

Q:Space. It’s big. It’s REALLY big. It must be daunting to code in such huge scales – how do you go about such a thing? Do you use any special data structures or measurement units to help?

A: As you can imagine, working with a single type of unit doesn’t work. I use a hierarchical system of units. At the galactic level, light-year (LY) units are utilized. At the star system level, the kilometer is the base unit, and coordinates are represented by double-precision floating point numbers. At render time, vertices are generated as single-precision floats, but translated into camera space to minimize the loss of precision due to large numbers.

Tom J Nowell
+2  A: 

The biggest problem with working with floating point representations of positions in large scale is that you rapidly lose precision as you get further and further away from the origin.

To remedy this you need to express all positions as relative to something else than the origin. The easiest way to do this is to partition the world into a grid and store the positions of all entities something like this:

struct Position {
    int kilometers[3]; // x, y and z offset in kilometers
    float offset[3]; //x, y and z offset in meters
};

The position of the camera is also stored like this, and when it's time to render you do something like this:

void
getRelativePosition(float& x, float& y, float& z, const Position& origin, const Position& object) {
    x = (object.kilometers[0] - origin.kilometers[0]) * 1000.0f +
        (object.offset[0] - origin.offset[0]);
    //Ditto for y and z
}

//Somewhere later
float x, y, z;
getRelativePosition(x, y, z, camera.position(), object.position());
renderMesh(x, y, z, object.mesh());

(For simplicity I ignored the orientation of camera and objects in this example, since there are no special problems associated with this).

If you're working with a continuous world on a galactic scale you can replace the kilometers parameter with a long long (64 bits) giving you an effective range of 1.8 million lightyears.

EDIT: To use this for continuous geometry such as terrain etc, you have to split the terrain into chunks of size one square kilometers, the coordinates of the vertices in the terrain chunk should be in the range [0, 1000].

Also in the function getRelativePosition above you could change it so it returns a bool and return false if the difference in kilometers is larger than some threshold (say the distance to your far clip plane).

Andreas Brinck
hmmm I'm not sure how this would actually get around the floating point error, as at very large scales you would be multiplying 1000 by a very large number anyway, and your just swapping one set scale and all its problems for a new one =/
Tom J Nowell
ah I see now what your getting at, but it still leaves the problem of very very large structures, e.g. planets/mountains/moons
Tom J Nowell
@Tom You can't stora a planet as a single mesh, se my edited answer
Andreas Brinck
ah, well there's large scales and large distances, now for the kicker, drawing large objects that are far away, e.g. sitting on one planets surface and drawing the neighbouring planet in the sky
Tom J Nowell
Ill give you the question since I think youve answered the original question already!
Tom J Nowell
@Tom The problem with large view distance is that the precision of the z-buffer won't be sufficient. It's hard to cram an answer on how to handle this into a comment, but basically you'll have to partition the geometry along the z axis and render each partition separately.
Andreas Brinck
A: 

Might be worth looking into the tech behind Bing Maps Deep Zoom

Similar tech is used by Google Earth, which lets you go form Planet view all the way down to street view pretty smoothly. There is obviously a lot of resolution swapping going on as you zoom in and out.

Neil N
nifty, how would this be applied to 3D geometry outside of silverlight?
Tom J Nowell