Jump to content
  • Advertisement
Sign in to follow this  
george7378

Scenes with large and small elements

This topic is 1508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

 

At the moment I'm working on a simple simulation of an Earth-orbiting spacecraft. This involves centring the camera on my spacecraft which is orbiting a few hundred kilometres above Earth and simultaneously rendering the planet itself out to a distance of around 12000km. Of course, it's unfeasible to render such a scene using metres as my base unit, as I have to specify the spacecraft's position in hundreds of thousands of metres relative to the centre of Earth, and using such massive numbers to position objects in Direct3D seems to cause problems.

 

So, my question is: how would you approach the problem of rendering small scenes embedded in much larger ones? Should I render the Earth first followed by the spacecraft using different units each time? If you know of any useful articles or tutorials, that would be great :)

 

Thanks!

Share this post


Link to post
Share on other sites
Advertisement

Simply change the scale of the objects. If you move the planet 10,000 times closer, just render it with a 10,000 times smaller radius. As long as it's rendered in the same direction, you won't notice.

 

Alternatively, you can render all large objects with one scale, clear the depth buffer, then render smaller, nearer objects at a different scale.

Share this post


Link to post
Share on other sites

Of course, it's unfeasible to render such a scene using metres as my base unit, as I have to specify the spacecraft's position in hundreds of thousands of metres relative to the centre of Earth, and using such massive numbers to position objects in Direct3D seems to cause problems.

 

Hundreds of thousands of meters doesn't sound like a whole lot, not if you are using 32-bit floats. If you were simulating the entire galaxy, I could see this being an issue, but you are only simulating Earth out to LEO.

 

Edit: Then again, now that I think about it you would only have accuracy to like 1/10th of a meter far away from the origin. If the origin is centered around the spacecraft then maybe it wouldn't be an issue. You don't need better than 1/10th of a meter accuracy for something >100,000 km away.

 

Also, it doesn't really matter if you are using meters, kilometers or millimeters as your base unit. This has no effect on the precision of the calculation when you are working with floating point numbers, as you are only changing the exponent.

Edited by Chris_F

Share this post


Link to post
Share on other sites

typically, when a scene is bigger than a float can hold accurately, objects are defined in "world coordinates" which are then converted to camera-relative floating point coordinates for drawing.  objects which are still too big/far to fit in a float get scaled down in both range and size until they fit in a float. drawing would probably be done in two passes, first a pass to draw all objects too big/far to fit in a float, then a pass to draw all closer objects. near and far planes can be reset as you go, to keep zbuffer resolution high.

 

this recent thread touches on these issues:

 

http://www.gamedev.net/topic/661933-max-size-for-level-using-floats/

Share this post


Link to post
Share on other sites
Ok, thanks for all the replies! I have solved it for the time being by calculating the actual positions using metres, and when I render I put the camera at (0, 0, 0) and render everything relative to that. For the Earth I'm using a sphere of radius 1 which I render 6378100 times closer than the actual calculated distance. Disabling the z-buffer for the planet rendering makes sure it's in the background.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!