Bugfix: proper debugshape position for CharacterControl in local physics (3 posts)

Topic tags: bullet, CharacterControl, debug shape, physics
  • Profile picture of DulcetTone DulcetTone1p said 3 months, 2 weeks ago:

    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);
    
  • Profile picture of Momoko_Fan Momoko_Fan366p said 3 months, 2 weeks ago:

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

  • Profile picture of normen normen1271p said 3 months, 1 week ago:

    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.