From 87737f96e005eb3831e0c69d9df9ab2091672b4d Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sun, 3 Jul 2011 00:09:21 +0000 Subject: [PATCH] * Fix BillboardControl "Spatial was not updated before rendering" crash * Add F5 key to hide FPS/stats git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7813 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../core/com/jme3/app/SimpleApplication.java | 11 +++++++-- .../jme3/scene/control/BillboardControl.java | 23 +++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/engine/src/core/com/jme3/app/SimpleApplication.java b/engine/src/core/com/jme3/app/SimpleApplication.java index f165aa5d2..5c875919d 100644 --- a/engine/src/core/com/jme3/app/SimpleApplication.java +++ b/engine/src/core/com/jme3/app/SimpleApplication.java @@ -68,6 +68,7 @@ public abstract class SimpleApplication extends Application { public static final String INPUT_MAPPING_EXIT = "SIMPLEAPP_Exit"; public static final String INPUT_MAPPING_CAMERA_POS = "SIMPLEAPP_CameraPos"; public static final String INPUT_MAPPING_MEMORY = "SIMPLEAPP_Memory"; + public static final String INPUT_MAPPING_HIDE_STATS = "SIMPLEAPP_HideStats"; protected Node rootNode = new Node("Root Node"); protected Node guiNode = new Node("Gui Node"); @@ -79,7 +80,7 @@ public abstract class SimpleApplication extends Application { protected boolean showSettings = true; private boolean showFps = true; private AppActionListener actionListener = new AppActionListener(); - + private class AppActionListener implements ActionListener { public void onAction(String name, boolean value, float tpf) { @@ -100,6 +101,10 @@ public abstract class SimpleApplication extends Application { } } else if (name.equals(INPUT_MAPPING_MEMORY)) { BufferUtils.printCurrentDirectMemory(null); + }else if (name.equals(INPUT_MAPPING_HIDE_STATS)){ + boolean show = showFps; + setDisplayFps(!show); + setDisplayStatView(!show); } } } @@ -215,8 +220,10 @@ public abstract class SimpleApplication extends Application { inputManager.addMapping(INPUT_MAPPING_CAMERA_POS, new KeyTrigger(KeyInput.KEY_C)); inputManager.addMapping(INPUT_MAPPING_MEMORY, new KeyTrigger(KeyInput.KEY_M)); + inputManager.addMapping(INPUT_MAPPING_HIDE_STATS, new KeyTrigger(KeyInput.KEY_F5)); inputManager.addListener(actionListener, INPUT_MAPPING_EXIT, - INPUT_MAPPING_CAMERA_POS, INPUT_MAPPING_MEMORY); + INPUT_MAPPING_CAMERA_POS, INPUT_MAPPING_MEMORY, INPUT_MAPPING_HIDE_STATS); + } // call user code diff --git a/engine/src/core/com/jme3/scene/control/BillboardControl.java b/engine/src/core/com/jme3/scene/control/BillboardControl.java index ed91c25f9..d804bc3bb 100644 --- a/engine/src/core/com/jme3/scene/control/BillboardControl.java +++ b/engine/src/core/com/jme3/scene/control/BillboardControl.java @@ -80,9 +80,6 @@ public class BillboardControl extends AbstractControl { AxialZ; } - - - public BillboardControl() { super(); orient = new Matrix3f(); @@ -107,6 +104,18 @@ public class BillboardControl extends AbstractControl { Camera cam = vp.getCamera(); rotateBillboard(cam); } + + private void fixRefreshFlags(){ + // force transforms to update below this node + spatial.updateGeometricState(); + + // force world bound to update + Spatial rootNode = spatial; + while (rootNode.getParent() != null){ + rootNode = rootNode.getParent(); + } + rootNode.getWorldBound(); + } /** * rotate the billboard based on the type set @@ -168,7 +177,7 @@ public class BillboardControl extends AbstractControl { // The billboard must be oriented to face the camera before it is // transformed into the world. spatial.setLocalRotation(orient); - spatial.updateGeometricState(); + fixRefreshFlags(); } /** @@ -188,10 +197,10 @@ public class BillboardControl extends AbstractControl { Quaternion rot=new Quaternion().fromRotationMatrix(orient); if ( parent != null ) { rot = parent.getWorldRotation().inverse().multLocal(rot); - rot.normalize(); + rot.normalizeLocal(); } spatial.setLocalRotation(rot); - spatial.updateGeometricState(); + fixRefreshFlags(); } /** @@ -256,7 +265,7 @@ public class BillboardControl extends AbstractControl { // The billboard must be oriented to face the camera before it is // transformed into the world. spatial.setLocalRotation(orient); - spatial.updateGeometricState(); + fixRefreshFlags(); } /**