- add coord display for WorldOfInception

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10407 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 12 years ago
parent e100931c1f
commit bd76d72ec7
  1. 46
      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.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.RigidBodyControl; import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.debug.DebugTools; import com.jme3.bullet.debug.DebugTools;
import com.jme3.font.BitmapText;
import com.jme3.input.KeyInput; import com.jme3.input.KeyInput;
import com.jme3.input.controls.AnalogListener; import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger; import com.jme3.input.controls.KeyTrigger;
@ -116,6 +117,7 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene
poiCollisionShape = new SphereCollisionShape(1f); poiCollisionShape = new SphereCollisionShape(1f);
ballCollisionShape = new SphereCollisionShape(1f); ballCollisionShape = new SphereCollisionShape(1f);
setupKeys(); setupKeys();
setupDisplay();
} }
private void setupKeys() { 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"); 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) { public void onAnalog(String name, float value, float tpf) {
Vector3f left = rootNode.getLocalRotation().mult(Vector3f.UNIT_X.negate()); Vector3f left = rootNode.getLocalRotation().mult(Vector3f.UNIT_X.negate());
Vector3f forward = rootNode.getLocalRotation().mult(Vector3f.UNIT_Z.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) { public void simpleUpdate(float tpf) {
currentLevel = currentLevel.getCurrentLevel(); currentLevel = currentLevel.getCurrentLevel();
currentLevel.move(walkDirection); currentLevel.move(walkDirection);
fpsText.setText("Location: " + currentLevel.getCoordinates());
walkDirection.set(Vector3f.ZERO); 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) { private void scaleAsChild(float percent, Vector3f dist) {
float childScale = mapValue(percent, 1.0f / poiRadius, 1); float childScale = mapValue(percent, 1.0f / poiRadius, 1);
Vector3f distToHorizon = dist.normalize(); Vector3f distToHorizon = dist.normalize();
@ -324,6 +330,12 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene
return null; 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() { private void initData() {
getRootNode(); getRootNode();
physicsState = new BulletAppState(); physicsState = new BulletAppState();
@ -375,7 +387,7 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene
} }
private void cleanupData() { private void cleanupData() {
physicsState.cleanup(); physicsState.stopPhysics();
//TODO: remove all objects? //TODO: remove all objects?
physicsState = null; physicsState = null;
rootNode = null; rootNode = null;
@ -439,9 +451,25 @@ public class WorldOfInception extends SimpleApplication implements AnalogListene
return curScaleAmount; return curScaleAmount;
} }
public InceptionLevel getParent() {
return parent;
}
public InceptionLevel getCurrentLevel() { public InceptionLevel getCurrentLevel() {
return currentReturnLevel; 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) { public static Vector3f[] getPositions(int count, long seed) {

Loading…
Cancel
Save