My app uses CharacterControls in local physics mode to allow walking around on ship models that themselves move about the world (the character’s spatial is a child of the ship model).
I noticed that the debug shape is not displayed in the proper position.
This patch fixes it.
Index: src/bullet-common/com/jme3/bullet/control/CharacterControl.java
===================================================================
--- src/bullet-common/com/jme3/bullet/control/CharacterControl.java (revision 9125)
+++ src/bullet-common/com/jme3/bullet/control/CharacterControl.java (working copy)
@@ -151,12 +151,26 @@
}
}
+ private static Vector3f renderHelper;
public void render(RenderManager rm, ViewPort vp) {
if (enabled && space != null && space.getDebugManager() != null) {
if (debugShape == null) {
attachDebugShape(space.getDebugManager());
}
- debugShape.setLocalTranslation(getPhysicsLocation());
+
+ if (renderHelper == null)
+ renderHelper = new Vector3f();
+
+ getPhysicsLocation(renderHelper);
+
+ // if we are in a local physics context, transform physical position within parent
+ // to a world position, as the debug shape is attached to the root node
+ if (isApplyPhysicsLocal() && spatial.getParent() != null) {
+ spatial.getParent().getWorldTransform().transformVector(renderHelper, renderHelper);
+ }
+
+ debugShape.setLocalTranslation(renderHelper);
+
debugShape.updateLogicalState(0);
debugShape.updateGeometricState();
rm.renderScene(debugShape, vp);