fixed TerrainGrid.getTerrainAtCell() and TerrainGrid.getTerrainAt(), updated TerrainGridTileLoaderTest

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9982 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..om 12 years ago
parent b3e63e9732
commit d68fba1fef
  1. 11
      engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java
  2. 9
      engine/src/test/jme3test/terrain/TerrainGridTileLoaderTest.java

@ -317,7 +317,8 @@ public class TerrainGrid extends TerrainQuad {
public Terrain getTerrainAt(Vector3f worldLocation) { public Terrain getTerrainAt(Vector3f worldLocation) {
if (worldLocation == null) if (worldLocation == null)
return null; return null;
Vector3f tileCell = getTileCell(worldLocation); Vector3f tileCell = getTileCell(worldLocation.setY(0));
tileCell = new Vector3f(Math.round(tileCell.x), tileCell.y, Math.round(tileCell.z));
return cache.get(tileCell); return cache.get(tileCell);
} }
@ -327,16 +328,16 @@ public class TerrainGrid extends TerrainQuad {
* @return the terrain tile at that location * @return the terrain tile at that location
*/ */
public Terrain getTerrainAtCell(Vector3f cellCoordinate) { public Terrain getTerrainAtCell(Vector3f cellCoordinate) {
Vector3f gridLocation = cellCoordinate.mult(getLocalScale()).multLocal(quadSize - 1); return cache.get(cellCoordinate);
Vector3f tileCell = getTileCell(gridLocation);
return cache.get(tileCell);
} }
/** /**
* Convert the world location into a cell location (integer coordinates) * Convert the world location into a cell location (integer coordinates)
*/ */
public Vector3f toCellSpace(Vector3f worldLocation) { public Vector3f toCellSpace(Vector3f worldLocation) {
return getTileCell(worldLocation); Vector3f tileCell = getTileCell(worldLocation);
tileCell = new Vector3f(Math.round(tileCell.x), tileCell.y, Math.round(tileCell.z));
return tileCell;
} }
/** /**

@ -10,11 +10,14 @@ import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape;
import com.jme3.bullet.control.CharacterControl; import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl; import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.KeyInput; import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger; import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.terrain.Terrain;
import com.jme3.terrain.geomipmap.TerrainGrid; import com.jme3.terrain.geomipmap.TerrainGrid;
import com.jme3.terrain.geomipmap.TerrainGridListener; import com.jme3.terrain.geomipmap.TerrainGridListener;
import com.jme3.terrain.geomipmap.TerrainGridLodControl; import com.jme3.terrain.geomipmap.TerrainGridLodControl;
@ -164,11 +167,13 @@ public class TerrainGridTileLoaderTest extends SimpleApplication {
this.inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_W)); this.inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_W));
this.inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_S)); this.inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_S));
this.inputManager.addMapping("Jumps", new KeyTrigger(KeyInput.KEY_SPACE)); this.inputManager.addMapping("Jumps", new KeyTrigger(KeyInput.KEY_SPACE));
this.inputManager.addMapping("pick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
this.inputManager.addListener(this.actionListener, "Lefts"); this.inputManager.addListener(this.actionListener, "Lefts");
this.inputManager.addListener(this.actionListener, "Rights"); this.inputManager.addListener(this.actionListener, "Rights");
this.inputManager.addListener(this.actionListener, "Ups"); this.inputManager.addListener(this.actionListener, "Ups");
this.inputManager.addListener(this.actionListener, "Downs"); this.inputManager.addListener(this.actionListener, "Downs");
this.inputManager.addListener(this.actionListener, "Jumps"); this.inputManager.addListener(this.actionListener, "Jumps");
this.inputManager.addListener(this.actionListener, "pick");
} }
private boolean left; private boolean left;
private boolean right; private boolean right;
@ -204,6 +209,10 @@ public class TerrainGridTileLoaderTest extends SimpleApplication {
} }
} else if (name.equals("Jumps")) { } else if (name.equals("Jumps")) {
TerrainGridTileLoaderTest.this.player3.jump(); TerrainGridTileLoaderTest.this.player3.jump();
} else if (name.equals("pick") && keyPressed) {
//Terrain picked = terrain.getTerrainAt(player3.getPhysicsLocation());
Terrain picked = terrain.getTerrainAtCell(terrain.getCurrentCell());
System.out.println("** cell "+player3.getPhysicsLocation()+" picked terrain: "+picked);
} }
} }
}; };

Loading…
Cancel
Save