Java Code Examples for com.jme3.bullet.BulletAppState#setDebugEnabled()

The following examples show how to use com.jme3.bullet.BulletAppState#setDebugEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestIssue1120.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void initializeNewTest() {
    bulletAppState = new BulletAppState();
    bulletAppState.setDebugEnabled(physicsDebug);
    stateManager.attach(bulletAppState);

    bulletAppState.setSpeed(bulletSpeed);

    dropTest();

    Geometry leftFloor = PhysicsTestHelper.createMeshTestFloor(assetManager, 20, new Vector3f(-11, -5, -10));
    addObject(leftFloor);

    //Hide physics debug visualization for floors
    if (physicsDebug) {
        BulletDebugAppState bulletDebugAppState = stateManager.getState(BulletDebugAppState.class);
        bulletDebugAppState.setFilter((Object obj) -> {
            return !(obj.equals(leftFloor.getControl(RigidBodyControl.class)));
        });
    }
}
 
Example 2
Source File: TestCcd.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.1f);
    setupKeys();

    mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);

    mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.getAdditionalRenderState().setWireframe(true);
    mat2.setColor("Color", ColorRGBA.Red);

    // An obstacle mesh, does not move (mass=0)
    Node node2 = new Node();
    node2.setName("mesh");
    node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
    node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(4, 4, 0.1f)), 0));
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);

    // The floor, does not move (mass=0)
    Node node3 = new Node();
    node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
    node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);

}
 
Example 3
Source File: TestCollisionListener.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);

    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());

    // add ourselves as collision listener
    getPhysicsSpace().addCollisionListener(this);
}
 
Example 4
Source File: TestPhysicsHingeJoint.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    setupKeys();
    setupJoint();
}
 
Example 5
Source File: TestAttachDriver.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    setupKeys();
    setupFloor();
    buildPlayer();
}
 
Example 6
Source File: TestIssue1125.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Configure physics during startup.
 */
private void configurePhysics() {
    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    physicsSpace = bulletAppState.getPhysicsSpace();
}
 
Example 7
Source File: TestAttachGhostObject.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    setupKeys();
    setupJoint();
}
 
Example 8
Source File: TestRagDoll.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    inputManager.addMapping("Pull ragdoll up", new MouseButtonTrigger(0));
    inputManager.addListener(this, "Pull ragdoll up");
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    createRagDoll();
}
 
Example 9
Source File: TestGhostObject.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);

    // Mesh to be shared across several boxes.
    Box boxGeom = new Box(1f, 1f, 1f);
    // CollisionShape to be shared across several boxes.
    CollisionShape shape = new BoxCollisionShape(new Vector3f(1, 1, 1));

    Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox.setName("box0");
    physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
    rootNode.attachChild(physicsBox);
    getPhysicsSpace().add(physicsBox);

    Node physicsBox1 = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox1.setName("box1");
    physicsBox1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0, 40, 0));
    rootNode.attachChild(physicsBox1);
    getPhysicsSpace().add(physicsBox1);

    Node physicsBox2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
    physicsBox2.setName("box0");
    physicsBox2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.5f, 80, -.8f));
    rootNode.attachChild(physicsBox2);
    getPhysicsSpace().add(physicsBox2);

    // the floor, does not move (mass=0)
    Node node = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(100, 1, 100)), 0);
    node.setName("floor");
    node.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node);
    getPhysicsSpace().add(node);

    initGhostObject();
}
 
Example 10
Source File: TestPhysicsCar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    setupKeys();
    buildPlayer();
}
 
Example 11
Source File: TestCollisionGroups.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);

    // Add a physics sphere to the world
    Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
    rootNode.attachChild(physicsSphere);
    getPhysicsSpace().add(physicsSphere);

    // Add a physics sphere to the world
    Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
    physicsSphere2.getControl(RigidBodyControl.class).addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    rootNode.attachChild(physicsSphere2);
    getPhysicsSpace().add(physicsSphere2);

    // an obstacle mesh, does not move (mass=0)
    Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
    node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
    node2.getControl(RigidBodyControl.class).setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    node2.getControl(RigidBodyControl.class).setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_02);
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);

    // the floor, does not move (mass=0)
    Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Box(100f, 0.2f, 100f)), 0);
    node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);
}
 
Example 12
Source File: TestCollisionShapeFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    createMaterial();

    Node node = new Node("node1");
    attachRandomGeometry(node, mat1);
    randomizeTransform(node);

    Node node2 = new Node("node2");
    attachRandomGeometry(node2, mat2);
    randomizeTransform(node2);

    node.attachChild(node2);
    rootNode.attachChild(node);

    RigidBodyControl control = new RigidBodyControl(0);
    node.addControl(control);
    getPhysicsSpace().add(control);

    //test single geometry too
    Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1));
    myGeom.setMaterial(mat3);
    randomizeTransform(myGeom);
    rootNode.attachChild(myGeom);
    RigidBodyControl control3 = new RigidBodyControl(0);
    myGeom.addControl(control3);
    getPhysicsSpace().add(control3);
}
 
Example 13
Source File: TestIssue889.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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);
}
 
Example 14
Source File: TestKinematicAddToPhysicsSpaceIssue.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {

    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    // Add a physics sphere to the world
    Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
    rootNode.attachChild(physicsSphere);

    //Setting the rigidBody to kinematic before adding it to the physics space
    physicsSphere.getControl(RigidBodyControl.class).setKinematic(true);
    //adding it to the physics space
    getPhysicsSpace().add(physicsSphere);
    //Making it not kinematic again, it should fall under gravity, it doesn't
    physicsSphere.getControl(RigidBodyControl.class).setKinematic(false);

    // Add a physics sphere to the world using the collision shape from sphere one
    Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0));
    rootNode.attachChild(physicsSphere2);

    //Adding the rigid body to physics space
    getPhysicsSpace().add(physicsSphere2);
    //making it kinematic
    physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false);
    //Making it not kinematic again, it works properly, the rigidbody is affected by grvity.
    physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false);



    // an obstacle mesh, does not move (mass=0)
    Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
    node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);

    // the floor mesh, does not move (mass=0)
    Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
    node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);

}
 
Example 15
Source File: TestLocalPhysics.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);
        bulletAppState.setDebugEnabled(true);

        // Add a physics sphere to the world
        Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
        physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
        physicsSphere.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
        rootNode.attachChild(physicsSphere);
        getPhysicsSpace().add(physicsSphere);

        // Add a physics sphere to the world using the collision shape from sphere one
        Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1);
        physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
        physicsSphere2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
        rootNode.attachChild(physicsSphere2);
        getPhysicsSpace().add(physicsSphere2);

        // Add a physics box to the world
        Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
        physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f);
        physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
        physicsBox.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
        rootNode.attachChild(physicsBox);
        getPhysicsSpace().add(physicsBox);

        // Add a physics cylinder to the world
        Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1);
        physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0));
        physicsCylinder.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
        rootNode.attachChild(physicsCylinder);
        getPhysicsSpace().add(physicsCylinder);

        // an obstacle mesh, does not move (mass=0)
        Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
        node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
        node2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
        rootNode.attachChild(node2);
        getPhysicsSpace().add(node2);

        // the floor mesh, does not move (mass=0)
        Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
        node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
        node3.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
        rootNode.attachChild(node3);
        getPhysicsSpace().add(node3);

        // Join the physics objects with a Point2Point joint
//        PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0));
//        PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z);
//        getPhysicsSpace().add(joint);

    }
 
Example 16
Source File: TestPhysicsReadWrite.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    physicsRootNode=new Node("PhysicsRootNode");
    rootNode.attachChild(physicsRootNode);

    // Add a physics sphere to the world
    Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
    rootNode.attachChild(physicsSphere);
    getPhysicsSpace().add(physicsSphere);

    // Add a physics sphere to the world using the collision shape from sphere one
    Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1);
    physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
    rootNode.attachChild(physicsSphere2);
    getPhysicsSpace().add(physicsSphere2);

    // Add a physics box to the world
    Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
    physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f);
    physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
    rootNode.attachChild(physicsBox);
    getPhysicsSpace().add(physicsBox);

    // Add a physics cylinder to the world
    Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1);
    physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0));
    rootNode.attachChild(physicsCylinder);
    getPhysicsSpace().add(physicsCylinder);

    // an obstacle mesh, does not move (mass=0)
    Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
    node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);

    // the floor mesh, does not move (mass=0)
    Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
    node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);

    // Join the physics objects with a Point2Point joint
    HingeJoint joint=new HingeJoint(physicsSphere.getControl(RigidBodyControl.class), physicsBox.getControl(RigidBodyControl.class), new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z);
    getPhysicsSpace().add(joint);

    //save and load the physicsRootNode
    try {
        //remove all physics objects from physics space
        getPhysicsSpace().removeAll(physicsRootNode);
        physicsRootNode.removeFromParent();
        //export to byte array
        ByteArrayOutputStream bout=new ByteArrayOutputStream();
        BinaryExporter.getInstance().save(physicsRootNode, bout);
        //import from byte array
        ByteArrayInputStream bin=new ByteArrayInputStream(bout.toByteArray());
        BinaryImporter imp=BinaryImporter.getInstance();
        imp.setAssetManager(assetManager);
        Node newPhysicsRootNode=(Node)imp.load(bin);
        //add all physics objects to physics space
        getPhysicsSpace().addAll(newPhysicsRootNode);
        rootNode.attachChild(newPhysicsRootNode);
    } catch (IOException ex) {
        Logger.getLogger(TestPhysicsReadWrite.class.getName()).log(Level.SEVERE, null, ex);
    }

}
 
Example 17
Source File: TestSimplePhysics.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);
        bulletAppState.setDebugEnabled(true);

        // Add a physics sphere to the world
        Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
        physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
        rootNode.attachChild(physicsSphere);
        getPhysicsSpace().add(physicsSphere);

        // Add a physics sphere to the world using the collision shape from sphere one
        Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1);
        physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
        rootNode.attachChild(physicsSphere2);
        getPhysicsSpace().add(physicsSphere2);

        // Add a physics box to the world
        Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
        physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f);
        physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
        rootNode.attachChild(physicsBox);
        getPhysicsSpace().add(physicsBox);

        // Add a physics cylinder to the world
        Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1);
        physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0));
        rootNode.attachChild(physicsCylinder);
        getPhysicsSpace().add(physicsCylinder);

        // an obstacle mesh, does not move (mass=0)
        Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
        node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
        rootNode.attachChild(node2);
        getPhysicsSpace().add(node2);

        // the floor mesh, does not move (mass=0)
        Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
        node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
        rootNode.attachChild(node3);
        getPhysicsSpace().add(node3);

        // Join the physics objects with a Point2Point joint
//        PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0));
//        PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z);
//        getPhysicsSpace().add(joint);

    }
 
Example 18
Source File: TestGimpactShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void initializeNewTest() {
    testScale.setText("Object scale: " + String.format("%.1f", scaleMod));
    solverNumIterationsTxt.setText("Solver Iterations: " + solverNumIterations);

    bulletAppState = new BulletAppState();
    bulletAppState.setDebugEnabled(true);
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().setSolverNumIterations(solverNumIterations);

    float floorSize = 80;
    //Left side test - GImpact objects collide with MeshCollisionShape floor
    Vector3f leftFloorPos = new Vector3f(-41, -5, -10);
    Vector3f leftFloorCenter = leftFloorPos.add(floorSize / 2, 0, floorSize / 2);

    dropTest1(leftFloorCenter);
    dropTest2(leftFloorCenter);
    dropPot(leftFloorCenter);
    dropSword(leftFloorCenter);
    dropSign(leftFloorCenter);
    dropRocket(leftFloorCenter);

    Geometry leftFloor = PhysicsTestHelper.createMeshTestFloor(assetManager, floorSize, leftFloorPos);
    addObject(leftFloor);

    //Right side test - GImpact objects collide with GImpact floor
    Vector3f rightFloorPos = new Vector3f(41, -5, -10);
    Vector3f rightFloorCenter = rightFloorPos.add(floorSize / 2, 0, floorSize / 2);

    dropTest1(rightFloorCenter);
    dropTest2(rightFloorCenter);
    dropPot(rightFloorCenter);
    dropSword(rightFloorCenter);
    dropSign(rightFloorCenter);
    dropRocket(rightFloorCenter);

    Geometry rightFloor = PhysicsTestHelper.createGImpactTestFloor(assetManager, floorSize, rightFloorPos);
    addObject(rightFloor);

    //Hide physics debug visualization for floors
    BulletDebugAppState bulletDebugAppState = stateManager.getState(BulletDebugAppState.class);
    bulletDebugAppState.setFilter((Object obj) -> {
        return !(obj.equals(rightFloor.getControl(RigidBodyControl.class))
            || obj.equals(leftFloor.getControl(RigidBodyControl.class)));
    });
}
 
Example 19
Source File: TestBetterCharacter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    //setup keyboard mapping
    setupKeys();

    // activate physics
    bulletAppState = new BulletAppState() {
        @Override
        public void prePhysicsTick(PhysicsSpace space, float tpf) {
            // Apply radial gravity near the planet, downward gravity elsewhere.
            checkPlanetGravity();
        }
    };
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);

    // init a physics test scene
    PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());
    setupPlanet();

    // Create a node for the character model
    characterNode = new Node("character node");
    characterNode.setLocalTranslation(new Vector3f(4, 5, 2));

    // Add a character control to the node so we can add other things and
    // control the model rotation
    physicsCharacter = new BetterCharacterControl(0.3f, 2.5f, 8f);
    characterNode.addControl(physicsCharacter);
    getPhysicsSpace().add(physicsCharacter);

    // Load model, attach to character node
    Node model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o");
    model.setLocalScale(1.50f);
    characterNode.attachChild(model);

    // Add character node to the rootNode
    rootNode.attachChild(characterNode);

    // Set forward camera node that follows the character, only used when
    // view is "locked"
    camNode = new CameraNode("CamNode", cam);
    camNode.setControlDir(ControlDirection.SpatialToCamera);
    camNode.setLocalTranslation(new Vector3f(0, 2, -6));
    Quaternion quat = new Quaternion();
    // These coordinates are local, the camNode is attached to the character node!
    quat.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
    camNode.setLocalRotation(quat);
    characterNode.attachChild(camNode);
    // Disable by default, can be enabled via keyboard shortcut
    camNode.setEnabled(false);
}