Bugfix: proper debugshape position for CharacterControl in local physics

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.



[java]

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());<br />
    

+

  •        if (renderHelper == null)<br />
    
  •            renderHelper = new Vector3f();<br />
    

+

  •        getPhysicsLocation(renderHelper);<br />
    

+

  •        // if we are in a local physics context, transform physical position within parent<br />
    
  •        // to a world position, as the debug shape is attached to the root node<br />
    
  •        if (isApplyPhysicsLocal() &amp;&amp; spatial.getParent() != null) {<br />
    
  •            spatial.getParent().getWorldTransform().transformVector(renderHelper, renderHelper);<br />
    
  •        }<br />
    

+

  •        debugShape.setLocalTranslation(renderHelper);<br />
    

+

debugShape.updateLogicalState(0);

debugShape.updateGeometricState();

rm.renderScene(debugShape, vp);

[/java]

@Normen: This fix is for the case when there’s some transform higher up the hierarchy (above the physics node), can we commit it?

No, local physics implies that the location is off. Else you would see all collison shapes in the middle of the scene instead of where you look at them. This is for moving spaces, remember.