From bd76d72ec7678675de2471f6b0999ae1d79ee9ab Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Thu, 14 Feb 2013 22:16:45 +0000 Subject: [PATCH] - add coord display for WorldOfInception git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10407 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../test/jme3test/games/WorldOfInception.java | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/engine/src/test/jme3test/games/WorldOfInception.java b/engine/src/test/jme3test/games/WorldOfInception.java index ee7548ec0..ab8c2181f 100644 --- a/engine/src/test/jme3test/games/WorldOfInception.java +++ b/engine/src/test/jme3test/games/WorldOfInception.java @@ -41,6 +41,7 @@ import com.jme3.bullet.collision.shapes.MeshCollisionShape; import com.jme3.bullet.collision.shapes.SphereCollisionShape; import com.jme3.bullet.control.RigidBodyControl; import com.jme3.bullet.debug.DebugTools; +import com.jme3.font.BitmapText; import com.jme3.input.KeyInput; import com.jme3.input.controls.AnalogListener; import com.jme3.input.controls.KeyTrigger; @@ -116,6 +117,7 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene poiCollisionShape = new SphereCollisionShape(1f); ballCollisionShape = new SphereCollisionShape(1f); setupKeys(); + setupDisplay(); } private void setupKeys() { @@ -135,6 +137,17 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene inputManager.addListener(this, "StrafeLeft", "StrafeRight", "Forward", "Back", "StrafeUp", "StrafeDown", "Space", "Reset", "Esc", "Up", "Down", "Left", "Right"); } + private void setupDisplay() { + if (fpsText == null) { + fpsText = new BitmapText(guiFont, false); + } + fpsText.setLocalScale(0.7f, 0.7f, 0.7f); + fpsText.setLocalTranslation(0, fpsText.getLineHeight(), 0); + fpsText.setText(""); + fpsText.setCullHint(Spatial.CullHint.Never); + guiNode.attachChild(fpsText); + } + public void onAnalog(String name, float value, float tpf) { Vector3f left = rootNode.getLocalRotation().mult(Vector3f.UNIT_X.negate()); Vector3f forward = rootNode.getLocalRotation().mult(Vector3f.UNIT_Z.negate()); @@ -167,6 +180,7 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene public void simpleUpdate(float tpf) { currentLevel = currentLevel.getCurrentLevel(); currentLevel.move(walkDirection); + fpsText.setText("Location: " + currentLevel.getCoordinates()); walkDirection.set(Vector3f.ZERO); } @@ -275,14 +289,6 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene } } - public static float linear2decibel(float x) { - return (float) (20.0 * Math.log(x) / Math.log(10)); - } - - public static float decibel2linear(float x) { - return (float) Math.pow(10.0, x / 20.0); - } - private void scaleAsChild(float percent, Vector3f dist) { float childScale = mapValue(percent, 1.0f / poiRadius, 1); Vector3f distToHorizon = dist.normalize(); @@ -324,6 +330,12 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene return null; } + public InceptionLevel getLevel(Vector3f... location) { + // TODO: get a level based on positions getting ever more accurate, + // from any given position + return null; + } + private void initData() { getRootNode(); physicsState = new BulletAppState(); @@ -375,7 +387,7 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene } private void cleanupData() { - physicsState.cleanup(); + physicsState.stopPhysics(); //TODO: remove all objects? physicsState = null; rootNode = null; @@ -439,9 +451,25 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene return curScaleAmount; } + public InceptionLevel getParent() { + return parent; + } + public InceptionLevel getCurrentLevel() { return currentReturnLevel; } + + public String getCoordinates() { + InceptionLevel cur = this; + StringBuilder strb = new StringBuilder(); + strb.insert(0, this.getPlayerPosition()); + cur = cur.getParent(); + while (cur != null) { + strb.insert(0, this.getPositionInParent() + " / "); + cur = cur.getParent(); + } + return strb.toString(); + } } public static Vector3f[] getPositions(int count, long seed) {