Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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. </p> <p>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:</p> <pre><code>struct Position { int kilometers[3]; // x, y and z offset in kilometers float offset[3]; //x, y and z offset in meters }; </code></pre> <p>The position of the camera is also stored like this, and when it's time to render you do something like this:</p> <pre><code>void getRelativePosition(float&amp; x, float&amp; y, float&amp; z, const Position&amp; origin, const Position&amp; 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()); </code></pre> <p>(For simplicity I ignored the orientation of camera and objects in this example, since there are no special problems associated with this).</p> <p>If you're working with a continuous world on a galactic scale you can replace the <code>kilometers</code> parameter with a <code>long long</code> (64 bits) giving you an effective range of 1.8 million lightyears.</p> <p><strong>EDIT:</strong> 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].</p> <p>Also in the function <code>getRelativePosition</code> above you could change it so it returns a <code>bool</code> and return <code>false</code> if the difference in kilometers is larger than some threshold (say the distance to your far clip plane).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload