Building the universe

Started by
3 comments, last by Ripiz 12 years, 6 months ago
[color="#4A4A4A"]Hello,
I want to make some sort of 3D space game with very large universe. After a little research I realized, that floats (vector3) are pretty inaquarate with large numbers and I already tested rendering the sphere with size of sun from distance of earth - nothing rendered, only with really smalled scale and closer view. I already found some solutions, but not sure how to implement them.

Many people just say "Make your own coordinate system" ...but what does it mean? Im not sure how to divide my space into sectors and if so, how should I save these coords? array of doubles, ints? And how to calculate the final position for render, because i need floats to graphics...

Another solutions I found was:
to move the origin with camera Does it mean to calculate renderings like camera is (0, 0, 0)? But then I'm still not sure how should i save the positions and translate it to screen. This solution solves the problem with fast movement of player I presume.
to draw large distance obejcts in closer position not so far from the camera, but scale them down.

I'm really confused about how to implement or combine these solutions together. I want for start to just render our solar system as a pure spheres with acording size and play/tweak some future speeds of traveling.

Best regards BadMad

PS.: English is far away from my native language. I hope you understand my thoughts.
Advertisement
I think what people mean by [color="#4A4A4A"]"Make your own coordinate system" is, opengl/directx/whatever system you're using, doesn't know or care about scale. 1.0f doesn't have to mean inches or millimeters. You can make it mean whatever you want. If you're doing very large distances, you could make 1.0f mean 1,000,000 miles or kilometers, for example.
Thanks for reply,
I already using 1unit as 1Km in real. I just rewrited and striped my code and the issue just got away, but i will see, when i re-implement my camera and other thigns.

My problem was, that objects were dissapearing or doesnt draw correctly, when i try to draw them in long distance from the origin of space. And when using some high speed movement, like speed of light, my movement was shaky more and more i was far away from the origin. I found that its because of float numbers, they are inaquarate as they get bigger. So i have to get rid of them, but be still able to get some relative position to the camera in float number, because of drawing.
Also the float numbers for storing positions of stars and planets are even too small for some galaxy-size thing...
You may have to make use of more than one coordinate system for different objects in the game.

For very far away things (like a pterry skybox of the universe with galaxies etc.. ) it may be just something drawn without scale
as a default background.

Next would be far objects that lose detail and arent interacted with -- using a larger increment system
(at a fixed ratio with the 'near coordinate system) When the players viewpoint moves closer than the far
objects will be converted to near coordinates and drawn under that system.

A near system of coordinates would contain all objects immediately interactable and have enough digits
of accuracy to eliminate rounding and other math sideeffects.

IF you game includes human scale interactions with/on the surface of planets you may need an additional 'fine' coordinate
system to handle those renderings and interactions.

Usually a 3D 'moving window' system (often a cube centered on the view point) is used to decide when
objects need to use which coordinate system, and object s move in an out of that cube when the viewpoint is moved.
--------------------------------------------[size="1"]Ratings are Opinion, not Fact
Global scale
Lets say your universe is 1 light year in diameter (~9.4 x 10^12 km) you could use library, which handles big numbers (integers will be enough) where 1 = 1km. This will allow you to approximately tell position of any object in the universe.


Local space
However it's obvious you'll need way higher precision for nearby objects. Lets say each player can see ships, other players and other small objects within 500 km from player's ship. You'll need to create 'virtual space' for player, which's center coordinate is (0, 0, 0) and it's also player's location. When anyone else gets inside this 'virtual space', you create new center - middle point between players. You'll need to render only objects within this 'virtual space' and it gives plenty of accuracy with floats. However I leave it up to you to figure what should happen when 100 players decide to position them 400km from each other - you can extend space, or split it; single players position doesn't have to be (0, 0, 0) either, it's just random idea.

Rendering far objects
Using big numbers calculate distance from camera to planets and other huge space entities, based on distance scale planet by some amount to make it proper size, sort all planets from farthest to nearest and render them without using depth buffer (as it cannot handle the distance). However do not render it normally. Use big numbers to move planet nearer to camera before rendering, otherwise matrix operations will mess up everything.

Alternative Rendering of far objects
Alternatively, you could create second 'scene' where planets orbit camera within very small distance (500km or so, depending on accuracy you need), and scale planets using big numbers before rendering. However this time you can use depth buffer and render them in any order, but make sure to clear depth buffer before you render objects in 'virtual space', otherwise some objects may appear behind planets, which is false.


Possibly this isn't fully right, and most likely not best way, I kinda just came up with it, but I hope this gives you idea how it can be done.

This topic is closed to new replies.

Advertisement