use of com.jme3.terrain.geomipmap.TerrainQuad in project jmonkeyengine by jMonkeyEngine.
the class TerrainQuad method findPick.
/**
* Gather the terrain patches that intersect the given ray (toTest).
* This only tests the bounding boxes
* @param toTest
* @param results
*/
public void findPick(Ray toTest, List<TerrainPickData> results) {
if (getWorldBound() != null) {
if (getWorldBound().intersects(toTest)) {
// further checking needed.
for (int i = 0; i < getQuantity(); i++) {
if (children.get(i) instanceof TerrainPatch) {
TerrainPatch tp = (TerrainPatch) children.get(i);
tp.ensurePositiveVolumeBBox();
if (tp.getWorldBound().intersects(toTest)) {
CollisionResults cr = new CollisionResults();
toTest.collideWith(tp.getWorldBound(), cr);
if (cr != null && cr.getClosestCollision() != null) {
cr.getClosestCollision().getDistance();
results.add(new TerrainPickData(tp, cr.getClosestCollision()));
}
}
} else if (children.get(i) instanceof TerrainQuad) {
((TerrainQuad) children.get(i)).findPick(toTest, results);
}
}
}
}
}
use of com.jme3.terrain.geomipmap.TerrainQuad in project jmonkeyengine by jMonkeyEngine.
the class TerrainQuad method findMatchingChild.
private QuadrantChild findMatchingChild(int x, int z) {
int quad = findQuadrant(x, z);
int split = (size + 1) >> 1;
if (children != null) {
for (int i = children.size(); --i >= 0; ) {
Spatial spat = children.get(i);
int col = x;
int row = z;
boolean match = false;
// get the childs quadrant
int childQuadrant = 0;
if (spat instanceof TerrainQuad) {
childQuadrant = ((TerrainQuad) spat).getQuadrant();
} else if (spat instanceof TerrainPatch) {
childQuadrant = ((TerrainPatch) spat).getQuadrant();
}
if (childQuadrant == 1 && (quad & 1) != 0) {
match = true;
} else if (childQuadrant == 2 && (quad & 2) != 0) {
row = z - split + 1;
match = true;
} else if (childQuadrant == 3 && (quad & 4) != 0) {
col = x - split + 1;
match = true;
} else if (childQuadrant == 4 && (quad & 8) != 0) {
col = x - split + 1;
row = z - split + 1;
match = true;
}
if (match)
return new QuadrantChild(col, row, spat);
}
}
return null;
}
use of com.jme3.terrain.geomipmap.TerrainQuad in project jmonkeyengine by jMonkeyEngine.
the class AssetTileLoader method getTerrainQuadAt.
public TerrainQuad getTerrainQuadAt(Vector3f location) {
String modelName = assetPath + "/" + name + "_" + Math.round(location.x) + "_" + Math.round(location.y) + "_" + Math.round(location.z) + ".j3o";
Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Load terrain grid tile: {0}", modelName);
TerrainQuad quad = null;
try {
quad = (TerrainQuad) manager.loadModel(modelName);
} catch (Exception e) {
// e.printStackTrace();
}
if (quad == null) {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Could not load terrain grid tile: {0}", modelName);
quad = createNewQuad(location);
} else {
Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Loaded terrain grid tile: {0}", modelName);
}
return quad;
}
use of com.jme3.terrain.geomipmap.TerrainQuad in project jmonkeyengine by jMonkeyEngine.
the class FractalTileLoader method getTerrainQuadAt.
public TerrainQuad getTerrainQuadAt(Vector3f location) {
HeightMap heightMapAt = getHeightMapAt(location);
TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap());
return q;
}
Aggregations