whoopsie, sorry TerrainGrid

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9327 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 13 years ago
parent 5dbde4ad06
commit a0af5de41e
  1. 101
      engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java

@ -43,7 +43,6 @@ import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.control.UpdateControl; import com.jme3.scene.control.UpdateControl;
import com.jme3.terrain.Terrain; import com.jme3.terrain.Terrain;
import com.jme3.terrain.geomipmap.lodcalc.LodCalculator;
import com.jme3.terrain.heightmap.HeightMap; import com.jme3.terrain.heightmap.HeightMap;
import com.jme3.terrain.heightmap.HeightMapGrid; import com.jme3.terrain.heightmap.HeightMapGrid;
import java.io.IOException; import java.io.IOException;
@ -55,57 +54,57 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* <p> * <p>
* TerrainGrid itself is an actual TerrainQuad. Its four children are the visible four tiles.</p> * TerrainGrid itself is an actual TerrainQuad. Its four children are the visible four tiles.</p>
* </p><p> * </p><p>
* The grid is indexed by cells. Each cell has an integer XZ coordinate originating at 0,0. * The grid is indexed by cells. Each cell has an integer XZ coordinate originating at 0,0.
* TerrainGrid will piggyback on the TerrainLodControl so it can use the camera for its * TerrainGrid will piggyback on the TerrainLodControl so it can use the camera for its
* updates as well. It does this in the overwritten update() method. * updates as well. It does this in the overwritten update() method.
* </p><p> * </p><p>
* It uses an LRU (Least Recently Used) cache of 16 terrain tiles (full TerrainQuadTrees). The * It uses an LRU (Least Recently Used) cache of 16 terrain tiles (full TerrainQuadTrees). The
* center 4 are the ones that are visible. As the camera moves, it checks what camera cell it is in * center 4 are the ones that are visible. As the camera moves, it checks what camera cell it is in
* and will attach the now visible tiles. * and will attach the now visible tiles.
* </p><p> * </p><p>
* The 'quadIndex' variable is a 4x4 array that represents the tiles. The center * The 'quadIndex' variable is a 4x4 array that represents the tiles. The center
* four (index numbers: 5, 6, 9, 10) are what is visible. Each quadIndex value is an * four (index numbers: 5, 6, 9, 10) are what is visible. Each quadIndex value is an
* offset vector. The vector contains whole numbers and represents how many tiles in offset * offset vector. The vector contains whole numbers and represents how many tiles in offset
* this location is from the center of the map. So for example the index 11 [Vector3f(2, 0, 1)] * this location is from the center of the map. So for example the index 11 [Vector3f(2, 0, 1)]
* is located 2*terrainSize in X axis and 1*terrainSize in Z axis. * is located 2*terrainSize in X axis and 1*terrainSize in Z axis.
* </p><p> * </p><p>
* As the camera moves, it tests what cameraCell it is in. Each camera cell covers four quad tiles * As the camera moves, it tests what cameraCell it is in. Each camera cell covers four quad tiles
* and is half way inside each one. * and is half way inside each one.
* </p><pre> * </p><pre>
* +-------+-------+ * +-------+-------+
* | 1 | 4 | Four terrainQuads that make up the grid * | 1 | 4 | Four terrainQuads that make up the grid
* | *..|..* | with the cameraCell in the middle, covering * | *..|..* | with the cameraCell in the middle, covering
* |----|--|--|----| all four quads. * |----|--|--|----| all four quads.
* | *..|..* | * | *..|..* |
* | 2 | 3 | * | 2 | 3 |
* +-------+-------+ * +-------+-------+
* </pre><p> * </pre><p>
* This results in the effect of when the camera gets half way across one of the sides of a quad to * This results in the effect of when the camera gets half way across one of the sides of a quad to
* an empty (non-loaded) area, it will trigger the system to load in the next tiles. * an empty (non-loaded) area, it will trigger the system to load in the next tiles.
* </p><p> * </p><p>
* The tile loading is done on a background thread, and once the tile is loaded, then it is * The tile loading is done on a background thread, and once the tile is loaded, then it is
* attached to the qrid quad tree, back on the OGL thread. It will grab the terrain quad from * attached to the qrid quad tree, back on the OGL thread. It will grab the terrain quad from
* the LRU cache if it exists. If it does not exist, it will load in the new TerrainQuad tile. * the LRU cache if it exists. If it does not exist, it will load in the new TerrainQuad tile.
* </p><p> * </p><p>
* The loading of new tiles triggers events for any TerrainGridListeners. The events are: * The loading of new tiles triggers events for any TerrainGridListeners. The events are:
* <ul> * <ul>
* <li>tile Attached * <li>tile Attached
* <li>tile Detached * <li>tile Detached
* <li>grid moved. * <li>grid moved.
* </ul> * </ul>
* <p> * <p>
* These allow physics to update, and other operation (often needed for loading the terrain) to occur * These allow physics to update, and other operation (often needed for loading the terrain) to occur
* at the right time. * at the right time.
* </p> * </p>
* @author Anthyon * @author Anthyon
*/ */
public class TerrainGrid extends TerrainQuad {
protected static final Logger log = Logger.getLogger(TerrainGrid.class.getCanonicalName()); protected static final Logger log = Logger.getLogger(TerrainGrid.class.getCanonicalName());
protected Vector3f currentCamCell = Vector3f.ZERO; protected Vector3f currentCamCell = Vector3f.ZERO;
protected int quarterSize; // half of quadSize protected int quarterSize; // half of quadSize

Loading…
Cancel
Save