diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java index 98d9beef0..1ea8cb19c 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGrid.java @@ -61,6 +61,11 @@ public class TerrainGrid extends TerrainQuad { if (cache.get(temp) == null) { HeightMap heightMapAt = heightMapGrid.getHeightMapAt(temp); TerrainQuad q = new TerrainQuad(getName() + "Quad" + temp, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap(), lodCalculatorFactory); + Material mat = material.clone(); + for (TerrainGridListener l : listeners.values()) { + mat = l.tileLoaded(mat, temp); + } + q.setMaterial(mat); cache.put(temp, q); } } @@ -95,8 +100,6 @@ public class TerrainGrid extends TerrainQuad { new Vector3f(0, 0, -1), new Vector3f(0, 0, 0), new Vector3f(0, 0, 1), new Vector3f(0, 0, 2), new Vector3f(1, 0, -1), new Vector3f(1, 0, 0), new Vector3f(1, 0, 1), new Vector3f(1, 0, 2), new Vector3f(2, 0, -1), new Vector3f(2, 0, 0), new Vector3f(2, 0, 1), new Vector3f(2, 0, 2)}; - - updateChildrens(Vector3f.ZERO); } public TerrainGrid(String name, int patchSize, int size, Vector3f scale, HeightMapGrid heightMapGrid, @@ -115,6 +118,14 @@ public class TerrainGrid extends TerrainQuad { public TerrainGrid() { } + public void initialize(Vector3f location) { + Vector3f camCell = this.getCell(location); + this.updateChildrens(camCell); + for (TerrainGridListener l : this.listeners.values()) { + l.gridMoved(camCell); + } + } + @Override public void update(List locations) { // for now, only the first camera is handled. @@ -152,7 +163,7 @@ public class TerrainGrid extends TerrainQuad { } protected void attachQuadAt(TerrainQuad q, int quadrant) { - q.setMaterial(this.material); + //q.setMaterial(this.material); q.setLocalTranslation(quadOrigins[quadrant - 1]); q.setQuadrant((short) quadrant); this.attachChild(q); @@ -223,6 +234,7 @@ public class TerrainGrid extends TerrainQuad { this.removeQuad(2); this.removeQuad(3); this.removeQuad(4); + attachQuadAt(q1, 1); attachQuadAt(q2, 2); attachQuadAt(q3, 3); diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGridListener.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGridListener.java index d4aab45d9..e11577386 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGridListener.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainGridListener.java @@ -4,6 +4,7 @@ */ package com.jme3.terrain.geomipmap; +import com.jme3.material.Material; import com.jme3.math.Vector3f; /** @@ -14,4 +15,6 @@ public interface TerrainGridListener { public void gridMoved(Vector3f newCenter); + public Material tileLoaded(Material material, Vector3f cell); + } diff --git a/engine/src/test-data/Textures/Terrain/grid/alphamap_0_0.png b/engine/src/test-data/Textures/Terrain/grid/alphamap_0_0.png new file mode 100644 index 000000000..98ee74a76 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/alphamap_0_0.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/alphamap_0_512.png b/engine/src/test-data/Textures/Terrain/grid/alphamap_0_512.png new file mode 100644 index 000000000..01e46af39 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/alphamap_0_512.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/alphamap_512_0.png b/engine/src/test-data/Textures/Terrain/grid/alphamap_512_0.png new file mode 100644 index 000000000..3a919f774 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/alphamap_512_0.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/alphamap_512_512.png b/engine/src/test-data/Textures/Terrain/grid/alphamap_512_512.png new file mode 100644 index 000000000..e10c087b6 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/alphamap_512_512.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_-1_-1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_-1.png new file mode 100644 index 000000000..3ade16282 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_-1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_-1_-2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_-2.png new file mode 100644 index 000000000..b5ab35c7c Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_-2.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_-1_0.png b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_0.png new file mode 100644 index 000000000..e01b3b8be Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_0.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_-1_1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_1.png new file mode 100644 index 000000000..1c3a395a0 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_-1_2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_2.png new file mode 100644 index 000000000..552516e1d Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_2.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_-1_3.png b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_3.png new file mode 100644 index 000000000..bf32bd614 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_3.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_-1_4.png b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_4.png new file mode 100644 index 000000000..c8901b896 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_-1_4.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_0_-1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_0_-1.png new file mode 100644 index 000000000..bcfbf9dea Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_0_-1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_0_-2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_0_-2.png new file mode 100644 index 000000000..3b98e1a12 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_0_-2.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_0_-3.png b/engine/src/test-data/Textures/Terrain/grid/terrain_0_-3.png new file mode 100644 index 000000000..3615981b3 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_0_-3.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_0_0.png b/engine/src/test-data/Textures/Terrain/grid/terrain_0_0.png new file mode 100644 index 000000000..4303a523e Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_0_0.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_0_1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_0_1.png new file mode 100644 index 000000000..2cf4130d2 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_0_1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_0_2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_0_2.png new file mode 100644 index 000000000..3125d53ea Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_0_2.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_0_3.png b/engine/src/test-data/Textures/Terrain/grid/terrain_0_3.png new file mode 100644 index 000000000..666d8da74 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_0_3.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_0_4.png b/engine/src/test-data/Textures/Terrain/grid/terrain_0_4.png new file mode 100644 index 000000000..e06f0a414 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_0_4.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_1_-1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_1_-1.png new file mode 100644 index 000000000..193ed1d4f Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_1_-1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_1_-2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_1_-2.png new file mode 100644 index 000000000..fd2c1ca34 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_1_-2.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_1_-3.png b/engine/src/test-data/Textures/Terrain/grid/terrain_1_-3.png new file mode 100644 index 000000000..10b0f44f0 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_1_-3.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_1_0.png b/engine/src/test-data/Textures/Terrain/grid/terrain_1_0.png new file mode 100644 index 000000000..29603d4c7 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_1_0.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_1_1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_1_1.png new file mode 100644 index 000000000..b98cb1695 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_1_1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_1_2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_1_2.png new file mode 100644 index 000000000..eb357d64a Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_1_2.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_1_3.png b/engine/src/test-data/Textures/Terrain/grid/terrain_1_3.png new file mode 100644 index 000000000..dda11d702 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_1_3.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_1_4.png b/engine/src/test-data/Textures/Terrain/grid/terrain_1_4.png new file mode 100644 index 000000000..e24e210f0 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_1_4.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_2_-1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_2_-1.png new file mode 100644 index 000000000..1f727ad32 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_2_-1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_2_-2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_2_-2.png new file mode 100644 index 000000000..a682d7944 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_2_-2.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_2_-3.png b/engine/src/test-data/Textures/Terrain/grid/terrain_2_-3.png new file mode 100644 index 000000000..e48d50f06 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_2_-3.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_2_0.png b/engine/src/test-data/Textures/Terrain/grid/terrain_2_0.png new file mode 100644 index 000000000..0e1be3f9d Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_2_0.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_2_1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_2_1.png new file mode 100644 index 000000000..7c01134e3 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_2_1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_2_2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_2_2.png new file mode 100644 index 000000000..e3b4aa12a Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_2_2.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_2_3.png b/engine/src/test-data/Textures/Terrain/grid/terrain_2_3.png new file mode 100644 index 000000000..c64d6837b Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_2_3.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_2_4.png b/engine/src/test-data/Textures/Terrain/grid/terrain_2_4.png new file mode 100644 index 000000000..0d3a71222 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_2_4.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_3_-1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_3_-1.png new file mode 100644 index 000000000..901fdeffc Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_3_-1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_3_-2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_3_-2.png new file mode 100644 index 000000000..bb017dfcf Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_3_-2.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_3_-3.png b/engine/src/test-data/Textures/Terrain/grid/terrain_3_-3.png new file mode 100644 index 000000000..7e20923fb Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_3_-3.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_3_0.png b/engine/src/test-data/Textures/Terrain/grid/terrain_3_0.png new file mode 100644 index 000000000..3e64f53e5 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_3_0.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_3_1.png b/engine/src/test-data/Textures/Terrain/grid/terrain_3_1.png new file mode 100644 index 000000000..994c4372f Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_3_1.png differ diff --git a/engine/src/test-data/Textures/Terrain/grid/terrain_3_2.png b/engine/src/test-data/Textures/Terrain/grid/terrain_3_2.png new file mode 100644 index 000000000..98ec28079 Binary files /dev/null and b/engine/src/test-data/Textures/Terrain/grid/terrain_3_2.png differ diff --git a/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java b/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java new file mode 100644 index 000000000..729234d62 --- /dev/null +++ b/engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java @@ -0,0 +1,258 @@ +package jme3test.terrain; + +import java.util.ArrayList; +import java.util.List; + +import com.jme3.app.SimpleApplication; +import com.jme3.app.state.ScreenshotAppState; +import com.jme3.bullet.BulletAppState; +import com.jme3.bullet.collision.shapes.CapsuleCollisionShape; +import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape; +import com.jme3.bullet.control.CharacterControl; +import com.jme3.bullet.control.RigidBodyControl; +import com.jme3.input.KeyInput; +import com.jme3.input.controls.ActionListener; +import com.jme3.input.controls.KeyTrigger; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.jme3.renderer.Camera; +import com.jme3.terrain.geomipmap.TerrainGrid; +import com.jme3.terrain.geomipmap.TerrainGridListener; +import com.jme3.terrain.geomipmap.TerrainLodControl; +import com.jme3.terrain.geomipmap.TerrainQuad; +import com.jme3.terrain.heightmap.FractalHeightMapGrid; +import com.jme3.terrain.heightmap.ImageBasedHeightMapGrid; +import com.jme3.terrain.heightmap.Namer; +import com.jme3.texture.Texture; +import com.jme3.texture.Texture.WrapMode; +import org.novyon.noise.ShaderUtils; +import org.novyon.noise.basis.FilteredBasis; +import org.novyon.noise.filter.IterativeFilter; +import org.novyon.noise.filter.OptimizedErode; +import org.novyon.noise.filter.PerturbFilter; +import org.novyon.noise.filter.SmoothFilter; +import org.novyon.noise.fractal.FractalSum; +import org.novyon.noise.modulator.NoiseModulator; + +public class TerrainGridAlphaMapTest extends SimpleApplication { + + private TerrainGrid terrain; + private float grassScale = 64; + private float dirtScale = 16; + private float rockScale = 128; + private boolean usePhysics = true; + + public static void main(final String[] args) { + TerrainGridAlphaMapTest app = new TerrainGridAlphaMapTest(); + app.start(); + } + private CharacterControl player3; + private FractalSum base; + private PerturbFilter perturb; + private OptimizedErode therm; + private SmoothFilter smooth; + private IterativeFilter iterate; + private Material matRock; + private Material matWire; + + @Override + public void simpleInitApp() { + this.flyCam.setMoveSpeed(100f); + ScreenshotAppState state = new ScreenshotAppState(); + this.stateManager.attach(state); + + // TERRAIN TEXTURE material + matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md"); + matRock.setBoolean("useTriPlanarMapping", false); + + // GRASS texture + Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); + grass.setWrap(WrapMode.Repeat); + matRock.setTexture("Tex1", grass); + matRock.setFloat("Tex1Scale", grassScale); + + // DIRT texture + Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg"); + dirt.setWrap(WrapMode.Repeat); + matRock.setTexture("Tex2", dirt); + matRock.setFloat("Tex2Scale", dirtScale); + + // ROCK texture + Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); + rock.setWrap(WrapMode.Repeat); + matRock.setTexture("Tex3", rock); + matRock.setFloat("Tex3Scale", rockScale); + + // WIREFRAME material + matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + matWire.getAdditionalRenderState().setWireframe(true); + matWire.setColor("Color", ColorRGBA.Green); + + this.base = new FractalSum(); + this.base.setRoughness(0.7f); + this.base.setFrequency(1.0f); + this.base.setAmplitude(1.0f); + this.base.setLacunarity(2.12f); + this.base.setOctaves(8); + this.base.setScale(0.02125f); + this.base.addModulator(new NoiseModulator() { + + @Override + public float value(float... in) { + return ShaderUtils.clamp(in[0] * 0.5f + 0.5f, 0, 1); + } + }); + + FilteredBasis ground = new FilteredBasis(this.base); + + this.perturb = new PerturbFilter(); + this.perturb.setMagnitude(0.119f); + + this.therm = new OptimizedErode(); + this.therm.setRadius(5); + this.therm.setTalus(0.011f); + + this.smooth = new SmoothFilter(); + this.smooth.setRadius(1); + this.smooth.setEffect(0.7f); + + this.iterate = new IterativeFilter(); + this.iterate.addPreFilter(this.perturb); + this.iterate.addPostFilter(this.smooth); + this.iterate.setFilter(this.therm); + this.iterate.setIterations(1); + + ground.addPreFilter(this.iterate); + + this.terrain = new TerrainGrid("terrain", 65, 1025, new ImageBasedHeightMapGrid(assetManager, new Namer() { + + public String getName(int x, int y) { + return "Textures/Terrain/grid/terrain_" + x + "_" + y + ".png"; + } + })); + this.terrain.setMaterial(this.matRock); + + this.terrain.addListener("alphaListener", new TerrainGridListener() { + + public void gridMoved(Vector3f newCenter) { + } + + public Material tileLoaded(Material material, Vector3f cell) { + material.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/grid/alphamap_" + (int)Math.abs(512 * (cell.x % 2)) + "_" + (int)Math.abs(512 * (cell.z % 2)) + ".png")); + return material; + } + }); + + this.terrain.setLocalTranslation(0, 0, 0); + this.terrain.setLocalScale(2f, 1f, 2f); + this.terrain.initialize(Vector3f.ZERO); + this.rootNode.attachChild(this.terrain); + + List cameras = new ArrayList(); + cameras.add(this.getCamera()); + TerrainLodControl control = new TerrainLodControl(this.terrain, cameras); + this.terrain.addControl(control); + + BulletAppState bulletAppState = new BulletAppState(); + stateManager.attach(bulletAppState); + + + this.getCamera().setLocation(new Vector3f(0, 256, 0)); + + this.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f)); + + if (usePhysics) { + RigidBodyControl body = new RigidBodyControl(new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()), 0); + terrain.addControl(body); + bulletAppState.getPhysicsSpace().add(terrain); + CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1); + this.player3 = new CharacterControl(capsuleShape, 0.5f); + this.player3.setJumpSpeed(20); + this.player3.setFallSpeed(30); + this.player3.setGravity(30); + + this.player3.setPhysicsLocation(new Vector3f(0, 256, 0)); + + bulletAppState.getPhysicsSpace().add(this.player3); + } + this.initKeys(); + } + + private void initKeys() { + // You can map one or several inputs to one named action + this.inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_A)); + this.inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_D)); + this.inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_W)); + this.inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_S)); + this.inputManager.addMapping("Jumps", new KeyTrigger(KeyInput.KEY_SPACE)); + this.inputManager.addListener(this.actionListener, "Lefts"); + this.inputManager.addListener(this.actionListener, "Rights"); + this.inputManager.addListener(this.actionListener, "Ups"); + this.inputManager.addListener(this.actionListener, "Downs"); + this.inputManager.addListener(this.actionListener, "Jumps"); + } + + private boolean left; + private boolean right; + private boolean up; + private boolean down; + private final ActionListener actionListener = new ActionListener() { + + @Override + public void onAction(final String name, final boolean keyPressed, final float tpf) { + if (name.equals("Lefts")) { + if (keyPressed) { + TerrainGridAlphaMapTest.this.left = true; + } else { + TerrainGridAlphaMapTest.this.left = false; + } + } else if (name.equals("Rights")) { + if (keyPressed) { + TerrainGridAlphaMapTest.this.right = true; + } else { + TerrainGridAlphaMapTest.this.right = false; + } + } else if (name.equals("Ups")) { + if (keyPressed) { + TerrainGridAlphaMapTest.this.up = true; + } else { + TerrainGridAlphaMapTest.this.up = false; + } + } else if (name.equals("Downs")) { + if (keyPressed) { + TerrainGridAlphaMapTest.this.down = true; + } else { + TerrainGridAlphaMapTest.this.down = false; + } + } else if (name.equals("Jumps")) { + TerrainGridAlphaMapTest.this.player3.jump(); + } + } + }; + private final Vector3f walkDirection = new Vector3f(); + + @Override + public void simpleUpdate(final float tpf) { + Vector3f camDir = this.cam.getDirection().clone().multLocal(0.6f); + Vector3f camLeft = this.cam.getLeft().clone().multLocal(0.4f); + this.walkDirection.set(0, 0, 0); + if (this.left) { + this.walkDirection.addLocal(camLeft); + } + if (this.right) { + this.walkDirection.addLocal(camLeft.negate()); + } + if (this.up) { + this.walkDirection.addLocal(camDir); + } + if (this.down) { + this.walkDirection.addLocal(camDir.negate()); + } + + if (usePhysics) { + this.player3.setWalkDirection(this.walkDirection); + this.cam.setLocation(this.player3.getPhysicsLocation()); + } + } +}