Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disabled physics control gets added to a physics space #889

Closed
stephengold opened this issue Sep 3, 2018 · 1 comment
Closed

disabled physics control gets added to a physics space #889

stephengold opened this issue Sep 3, 2018 · 1 comment
Assignees
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect". Physics Issues with all kinds of Physics and their Bindings
Milestone

Comments

@stephengold
Copy link
Member

One of the invariants of physics controls is that if the control is disabled, the physics object cannot be "in" (added to) any physics space.

Care was taken to preserve this invariant for RigidBodyControl, CharacterControl, and VehicleControl, but not for AbstractPhysicsControl nor GhostControl.

@stephengold
Copy link
Member Author

stephengold commented Sep 3, 2018

Here is a test case that demonstrates the issue:

package jme3test.bullet;

/**
 * Test case for JME issue #889: disabled physics control gets added to a
 * physics space.
 * <p>
 * If successful, no debug meshes will be visible.
 */
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.BetterCharacterControl;
import com.jme3.bullet.control.GhostControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.math.Vector3f;

public class TestIssue889 extends SimpleApplication {

    public static void main(String[] args) {
        TestIssue889 app = new TestIssue889();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        flyCam.setEnabled(false);

        BulletAppState bulletAppState = new BulletAppState();
        bulletAppState.setDebugEnabled(true);
        bulletAppState.setSpeed(0f);
        stateManager.attach(bulletAppState);
        PhysicsSpace space = bulletAppState.getPhysicsSpace();

        float radius = 1f;
        CollisionShape sphere = new SphereCollisionShape(radius);
        CollisionShape box = new BoxCollisionShape(Vector3f.UNIT_XYZ);

        RigidBodyControl rbc = new RigidBodyControl(box);
        rbc.setEnabled(false);
        rbc.setPhysicsSpace(space);
        rootNode.addControl(rbc);

        BetterCharacterControl bcc = new BetterCharacterControl(radius, 4f, 1f);
        bcc.setEnabled(false);
        bcc.setPhysicsSpace(space);
        rootNode.addControl(bcc);

        GhostControl gc = new GhostControl(sphere);
        gc.setEnabled(false);
        gc.setPhysicsSpace(space);
        rootNode.addControl(gc);
    }
}

@stephengold stephengold self-assigned this Sep 6, 2018
stephengold added a commit that referenced this issue Sep 7, 2018
joliver82 pushed a commit to joliver82/jmonkeyengine that referenced this issue Nov 14, 2018
@stephengold stephengold added this to the v3.2.2 milestone Dec 16, 2018
@stephengold stephengold added the bug Something that is supposed to work, but doesn't. More severe than a "defect". label Dec 16, 2018
stephengold added a commit that referenced this issue Dec 22, 2018
@stephengold stephengold added the Physics Issues with all kinds of Physics and their Bindings label Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect". Physics Issues with all kinds of Physics and their Bindings
Projects
None yet
Development

No branches or pull requests

1 participant