diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/NeighbourFinder.java b/engine/src/terrain/com/jme3/terrain/geomipmap/NeighbourFinder.java new file mode 100644 index 000000000..a6cc2c864 --- /dev/null +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/NeighbourFinder.java @@ -0,0 +1,42 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.terrain.geomipmap; + +/** + * Used for TerrainQuad to find neighbours that are not part of the + * same quad tree. Normally TerrainQuads function in a quad tree and + * use the neighbour methods getRightQuad, getLeftQuad etc. to update + * LOD values of the terrain (and for some other routines). + * + * With this you can have a parent, control or spatial, that manages a group of + * TerrainQuads by linking them together through these four methods. + * + * The general orientation of TerrainQuads and their sun-quads is as such: + * + * + * +-- x+ ----> + * | + * | 1 | 3 (quadrants) + * z+ --+-- + * | 2 | 4 + * | + * \/ + * + * Your implementation will still have to manage getHeight, getNormal, and + * most other Terrain.java interface methods; often by offsetting the XZ + * coordinate parameters. + * + * @author sploreg + */ +public interface NeighbourFinder { + + public TerrainQuad getRightQuad(TerrainQuad center); + + public TerrainQuad getLeftQuad(TerrainQuad center); + + public TerrainQuad getTopQuad(TerrainQuad center); + + public TerrainQuad getDownQuad(TerrainQuad center); +} diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java index e071a0e76..fc0e15772 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainQuad.java @@ -106,6 +106,8 @@ public class TerrainQuad extends Node implements Terrain { private TerrainPicker picker; private Vector3f lastScale = Vector3f.UNIT_XYZ; + protected NeighbourFinder neighbourFinder; + public TerrainQuad() { super("Terrain"); } @@ -197,6 +199,10 @@ public class TerrainQuad extends Node implements Terrain { split(patchSize, heightMap); } + public void setNeighbourFinder(NeighbourFinder neighbourFinder) { + this.neighbourFinder = neighbourFinder; + } + /** * Forces the recalculation of all normals on the terrain. */ @@ -824,6 +830,8 @@ public class TerrainQuad extends Node implements Terrain { int x = Math.round((xz.x / getWorldScale().x) + halfSize); int z = Math.round((xz.y / getWorldScale().z) + halfSize); + if (!isInside(x, z)) + return Float.NaN; return getHeightmapHeight(x, z); } @@ -921,6 +929,17 @@ public class TerrainQuad extends Node implements Terrain { return null; } + /** + * is the 2d point inside the terrain? + * @param x local coordinate + * @param z local coordinate + */ + private boolean isInside(int x, int z) { + if (x < 0 || z < 0 || x > totalSize || z > totalSize) + return false; + return true; + } + /** * Used for searching for a child and keeping * track of its quadrant @@ -984,6 +1003,8 @@ public class TerrainQuad extends Node implements Terrain { // offset float x = (float)(((xz.x - getWorldTranslation().x) / getWorldScale().x) + (float)(totalSize-1) / 2f); float z = (float)(((xz.y - getWorldTranslation().z) / getWorldScale().z) + (float)(totalSize-1) / 2f); + if (!isInside((int)x, (int)z)) + return Float.NaN; float height = getHeight((int)x, (int)z, (x%1f), (z%1f)); height *= getWorldScale().y; return height; @@ -1075,6 +1096,8 @@ public class TerrainQuad extends Node implements Terrain { for (int i=0; i xz, List height) { + // you will have to offset the coordinate for each terrain, to center on it + throw new UnsupportedOperationException("Not supported yet."); + } + + public void adjustHeight(Vector2f xzCoordinate, float delta) { + // you will have to offset the coordinate for each terrain, to center on it + throw new UnsupportedOperationException("Not supported yet."); + } + + public void adjustHeight(List xz, List height) { + // you will have to offset the coordinate for each terrain, to center on it + throw new UnsupportedOperationException("Not supported yet."); + } + + public float[] getHeightMap() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int getMaxLod() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void setLocked(boolean locked) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void generateEntropy(ProgressMonitor monitor) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Material getMaterial() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public Material getMaterial(Vector3f worldLocation) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int getTerrainSize() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public int getNumMajorSubdivisions() { + throw new UnsupportedOperationException("Not supported yet."); + } + + + + } +}