com.jme3.bullet.collision.PhysicsCollisionObject Java Examples

The following examples show how to use com.jme3.bullet.collision.PhysicsCollisionObject. 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: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * removes an object from the physics space
 * @param obj the PhysicsControl or Spatial with PhysicsControl to remove
 */
public void remove(Object obj) {
    if (obj instanceof PhysicsControl) {
        ((PhysicsControl) obj).setPhysicsSpace(null);
    } else if (obj instanceof Spatial) {
        Spatial node = (Spatial) obj;
        PhysicsControl control = node.getControl(PhysicsControl.class);
        control.setPhysicsSpace(null);
    } else if (obj instanceof PhysicsCollisionObject) {
        removeCollisionObject((PhysicsCollisionObject) obj);
    } else if (obj instanceof PhysicsJoint) {
        removeJoint((PhysicsJoint) obj);
    } else {
        throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space."));
    }
}
 
Example #2
Source File: PhysicsSpace.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * removes an object from the physics space
 *
 * @param obj the PhysicsControl or Spatial with PhysicsControl to remove
 */
public void remove(Object obj) {
    if (obj == null) return;
    if (obj instanceof PhysicsControl) {
        ((PhysicsControl) obj).setPhysicsSpace(null);
    } else if (obj instanceof Spatial) {
        Spatial node = (Spatial) obj;
        for (int i = 0; i < node.getNumControls(); i++) {
            if (node.getControl(i) instanceof PhysicsControl) {
                remove(node.getControl(i));
            }
        }
    } else if (obj instanceof PhysicsCollisionObject) {
        removeCollisionObject((PhysicsCollisionObject) obj);
    } else if (obj instanceof PhysicsJoint) {
        removeJoint((PhysicsJoint) obj);
    } else {
        throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space."));
    }
}
 
Example #3
Source File: PhysicsSpace.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * adds an object to the physics space
 * @param obj the PhysicsControl or Spatial with PhysicsControl to add
 */
public void add(Object obj) {
    if (obj == null) return;
    if (obj instanceof PhysicsControl) {
        ((PhysicsControl) obj).setPhysicsSpace(this);
    } else if (obj instanceof Spatial) {
        Spatial node = (Spatial) obj;
        for (int i = 0; i < node.getNumControls(); i++) {
            if (node.getControl(i) instanceof PhysicsControl) {
                add(node.getControl(i));
            }
        }
    } else if (obj instanceof PhysicsCollisionObject) {
        addCollisionObject((PhysicsCollisionObject) obj);
    } else if (obj instanceof PhysicsJoint) {
        addJoint((PhysicsJoint) obj);
    } else {
        throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space."));
    }
}
 
Example #4
Source File: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * adds an object to the physics space
 * @param obj the PhysicsControl or Spatial with PhysicsControl to add
 */
public void add(Object obj) {
    if (obj instanceof PhysicsControl) {
        ((PhysicsControl) obj).setPhysicsSpace(this);
    } else if (obj instanceof Spatial) {
        Spatial node = (Spatial) obj;
        PhysicsControl control = node.getControl(PhysicsControl.class);
        control.setPhysicsSpace(this);
    } else if (obj instanceof PhysicsCollisionObject) {
        addCollisionObject((PhysicsCollisionObject) obj);
    } else if (obj instanceof PhysicsJoint) {
        addJoint((PhysicsJoint) obj);
    } else {
        throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space."));
    }
}
 
Example #5
Source File: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * removes an object from the physics space
 * @param obj the PhysicsControl or Spatial with PhysicsControl to remove
 */
public void remove(Object obj) {
    if (obj instanceof PhysicsControl) {
        ((PhysicsControl) obj).setPhysicsSpace(null);
    } else if (obj instanceof Spatial) {
        Spatial node = (Spatial) obj;
        PhysicsControl control = node.getControl(PhysicsControl.class);
        control.setPhysicsSpace(null);
    } else if (obj instanceof PhysicsCollisionObject) {
        removeCollisionObject((PhysicsCollisionObject) obj);
    } else if (obj instanceof PhysicsJoint) {
        removeJoint((PhysicsJoint) obj);
    } else if (obj == null) {
        return;
    } else {
        throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space."+obj));
    }
}
 
Example #6
Source File: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * adds an object to the physics space
 * @param obj the PhysicsControl or Spatial with PhysicsControl to add
 */
public void add(Object obj) {
    if (obj instanceof PhysicsControl) {
        ((PhysicsControl) obj).setPhysicsSpace(this);
    } else if (obj instanceof Spatial) {
        Spatial node = (Spatial) obj;
        PhysicsControl control = node.getControl(PhysicsControl.class);
        control.setPhysicsSpace(this);
    } else if (obj instanceof PhysicsCollisionObject) {
        addCollisionObject((PhysicsCollisionObject) obj);
    } else if (obj instanceof PhysicsJoint) {
        addJoint((PhysicsJoint) obj);
    } else {
        throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space."));
    }
}
 
Example #7
Source File: TestHoveringTank.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void buildPlayer() {
    spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
    CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft);
    spaceCraft.setShadowMode(ShadowMode.CastAndReceive);
    spaceCraft.setLocalTranslation(startLocation);
    spaceCraft.setLocalRotation(startOrientation);

    hoverControl = new PhysicsHoverControl(colShape, 500);

    spaceCraft.addControl(hoverControl);


    rootNode.attachChild(spaceCraft);
    getPhysicsSpace().add(hoverControl);
    hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);

    ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
    spaceCraft.addControl(chaseCam);

    flyCam.setEnabled(false);
}
 
Example #8
Source File: TestSweepTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {

    float move = tpf * 1;
    boolean colliding = false;

    List<PhysicsSweepTestResult> sweepTest = bulletAppState.getPhysicsSpace().sweepTest(capsuleCollisionShape, new Transform(capsule.getWorldTranslation()), new Transform(capsule.getWorldTranslation().add(dist, 0, 0)));

    for (PhysicsSweepTestResult result : sweepTest) {
        if (result.getCollisionObject().getCollisionShape() != capsuleCollisionShape) {
            PhysicsCollisionObject collisionObject = result.getCollisionObject();
            fpsText.setText("Almost colliding with " + collisionObject.getUserObject().toString());
            colliding = true;
        }
    }

    if (!colliding) {
        // if the sweep is clear then move the spatial
        capsule.move(move, 0, 0);
    }
}
 
Example #9
Source File: BombControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void physicsTick(PhysicsSpace space, float f) {
    //get all overlapping objects and apply impulse to them
    for (Iterator<PhysicsCollisionObject> it = ghostObject.getOverlappingObjects().iterator(); it.hasNext();) {            
        PhysicsCollisionObject physicsCollisionObject = it.next();
        if (physicsCollisionObject instanceof PhysicsRigidBody) {
            PhysicsRigidBody rBody = (PhysicsRigidBody) physicsCollisionObject;
            rBody.getPhysicsLocation(vector2);
            vector2.subtractLocal(vector);
            float force = explosionRadius - vector2.length();
            force *= forceFactor;
            force = force > 0 ? force : 0;
            vector2.normalizeLocal();
            vector2.multLocal(force);
            ((PhysicsRigidBody) physicsCollisionObject).applyImpulse(vector2, Vector3f.ZERO);
        }
    }
    space.removeTickListener(this);
    space.remove(ghostObject);
}
 
Example #10
Source File: TestPhysicsRayCast.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
    float rayLength = 50f;
    Vector3f start = cam.getLocation();
    Vector3f end = cam.getDirection().scaleAdd(rayLength, start);
    List<PhysicsRayTestResult> rayTest
            = bulletAppState.getPhysicsSpace().rayTest(start, end);
    if (rayTest.size() > 0) {
        PhysicsRayTestResult get = rayTest.get(0);
        PhysicsCollisionObject collisionObject = get.getCollisionObject();
        // Display the name of the 1st object in place of FPS.
        fpsText.setText(collisionObject.getUserObject().toString());
    } else {
        // Provide prompt feedback that no collision object was hit.
        fpsText.setText("MISSING");
    }
}
 
Example #11
Source File: SceneToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void attachPhysicsSelection(Spatial geom) {
    PhysicsCollisionObject control = geom.getControl(RigidBodyControl.class);
    if (control == null) {
        control = geom.getControl(VehicleControl.class);
    }
    if (control == null) {
        control = geom.getControl(GhostControl.class);
    }
    if (control == null) {
        control = geom.getControl(CharacterControl.class);
    }
    if (control == null) {
        return;
    }
    Spatial selectionGeometry = DebugShapeFactory.getDebugShape(control.getCollisionShape());
    if (selectionGeometry != null) {
        selectionGeometry.setMaterial(blueMat);
        selectionGeometry.setLocalTransform(geom.getWorldTransform());
        toolsNode.attachChild(selectionGeometry);
        selectionShape = selectionGeometry;
    }
}
 
Example #12
Source File: TestHoveringTank.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void buildPlayer() {
    spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
    CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft);
    spaceCraft.setShadowMode(ShadowMode.CastAndReceive);
    spaceCraft.setLocalTranslation(new Vector3f(-140, 14, -23));
    spaceCraft.setLocalRotation(new Quaternion(new float[]{0, 0.01f, 0}));

    hoverControl = new PhysicsHoverControl(colShape, 500);
    hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);

    spaceCraft.addControl(hoverControl);


    rootNode.attachChild(spaceCraft);
    getPhysicsSpace().add(hoverControl);

    ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
    spaceCraft.addControl(chaseCam);

    flyCam.setEnabled(false);
}
 
Example #13
Source File: PhysicsControlTreeNode.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
public void fillContextMenu(@NotNull final NodeTree<?> nodeTree,
                            @NotNull final ObservableList<MenuItem> items) {

    if (getElement() instanceof PhysicsCollisionObject) {

        final Menu changeShapeMenu = new Menu(Messages.MODEL_NODE_TREE_ACTION_CHANGE_COLLISION_SHAPE, new ImageView(Icons.ADD_12));
        changeShapeMenu.getItems().addAll(new GenerateCollisionShapeAction(nodeTree, this),
                new CreateBoxCollisionShapeAction(nodeTree, this),
                new CreateCapsuleCollisionShapeAction(nodeTree, this),
                new CreateConeCollisionShapeAction(nodeTree, this),
                new CreateCylinderCollisionShapeAction(nodeTree, this),
                new CreateSphereCollisionShapeAction(nodeTree, this));

        items.add(changeShapeMenu);
    }

    super.fillContextMenu(nodeTree, items);
}
 
Example #14
Source File: BombControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void physicsTick(PhysicsSpace space, float f) {
    //get all overlapping objects and apply impulse to them
    for (Iterator<PhysicsCollisionObject> it = ghostObject.getOverlappingObjects().iterator(); it.hasNext();) {            
        PhysicsCollisionObject physicsCollisionObject = it.next();
        if (physicsCollisionObject instanceof PhysicsRigidBody) {
            PhysicsRigidBody rBody = (PhysicsRigidBody) physicsCollisionObject;
            rBody.getPhysicsLocation(vector2);
            vector2.subtractLocal(vector);
            float force = explosionRadius - vector2.length();
            force *= forceFactor;
            force = force > 0 ? force : 0;
            vector2.normalizeLocal();
            vector2.multLocal(force);
            ((PhysicsRigidBody) physicsCollisionObject).applyImpulse(vector2, Vector3f.ZERO);
        }
    }
    space.removeTickListener(this);
    space.remove(ghostObject);
}
 
Example #15
Source File: ApplyScaleToPhysicsControlsHandler.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Disable all controls before transform.
 *
 * @param spatial the spatial.
 */
@JmeThread
public void onPreTransform(@NotNull final Spatial spatial) {
    NodeUtils.children(NodeUtils.findParent(spatial, ApplyScaleToPhysicsControlsHandler::isModelRoot))
            .filter(sp -> ControlUtils.has(sp, PhysicsCollisionObject.class))
            .peek(sp -> previousScales.put(sp, sp.getWorldScale().clone()))
            .flatMap(NodeUtils::children)
            .filter(ch -> !previousScales.containsKey(ch))
            .forEach(ch -> previousScales.put(ch, ch.getWorldScale().clone()));
}
 
Example #16
Source File: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void addCollisionObject(PhysicsCollisionObject obj) {
    if (obj instanceof PhysicsGhostObject) {
        addGhostObject((PhysicsGhostObject) obj);
    } else if (obj instanceof PhysicsRigidBody) {
        addRigidBody((PhysicsRigidBody) obj);
    } else if (obj instanceof PhysicsVehicle) {
        addRigidBody((PhysicsVehicle) obj);
    } else if (obj instanceof PhysicsCharacter) {
        addCharacter((PhysicsCharacter) obj);
    }
}
 
Example #17
Source File: TestCollisionGroups.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    
    // 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(Vector3f.ZERO, 100f, 0.2f, 100f)), 0);
    node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);
}
 
Example #18
Source File: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setOverlapFilterCallback() {
    OverlapFilterCallback callback = new OverlapFilterCallback() {

        public boolean needBroadphaseCollision(BroadphaseProxy bp, BroadphaseProxy bp1) {
            boolean collides = (bp.collisionFilterGroup & bp1.collisionFilterMask) != 0;
            if (collides) {
                collides = (bp1.collisionFilterGroup & bp.collisionFilterMask) != 0;
            }
            if (collides) {
                assert (bp.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject && bp.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject);
                com.bulletphysics.collision.dispatch.CollisionObject colOb = (com.bulletphysics.collision.dispatch.CollisionObject) bp.clientObject;
                com.bulletphysics.collision.dispatch.CollisionObject colOb1 = (com.bulletphysics.collision.dispatch.CollisionObject) bp1.clientObject;
                assert (colOb.getUserPointer() != null && colOb1.getUserPointer() != null);
                PhysicsCollisionObject collisionObject = (PhysicsCollisionObject) colOb.getUserPointer();
                PhysicsCollisionObject collisionObject1 = (PhysicsCollisionObject) colOb1.getUserPointer();
                if ((collisionObject.getCollideWithGroups() & collisionObject1.getCollisionGroup()) > 0
                        || (collisionObject1.getCollideWithGroups() & collisionObject.getCollisionGroup()) > 0) {
                    PhysicsCollisionGroupListener listener = collisionGroupListeners.get(collisionObject.getCollisionGroup());
                    PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(collisionObject1.getCollisionGroup());
                    if (listener != null) {
                        return listener.collide(collisionObject, collisionObject1);
                    } else if (listener1 != null) {
                        return listener1.collide(collisionObject, collisionObject1);
                    }
                    return true;
                } else {
                    return false;
                }
            }
            return collides;
        }
    };
    dynamicsWorld.getPairCache().setOverlapFilterCallback(callback);
}
 
Example #19
Source File: VehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * returns the object this wheel is in contact with or null if no contact
 * @return the PhysicsCollisionObject (PhysicsRigidBody, PhysicsGhostObject)
 */
public PhysicsCollisionObject getGroundObject() {
    if (wheelInfo.raycastInfo.groundObject == null) {
        return null;
    } else if (wheelInfo.raycastInfo.groundObject instanceof RigidBody) {
        System.out.println("RigidBody");
        return (PhysicsRigidBody) ((RigidBody) wheelInfo.raycastInfo.groundObject).getUserPointer();
    } else {
        return null;
    }
}
 
Example #20
Source File: PhysicsGhostObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Another Object is overlapping with this GhostNode,
 * if and if only there CollisionShapes overlaps.
 * They could be both regular PhysicsRigidBodys or PhysicsGhostObjects.
 * @return All CollisionObjects overlapping with this GhostNode.
 */
public List<PhysicsCollisionObject> getOverlappingObjects() {
    overlappingObjects.clear();
    for (com.bulletphysics.collision.dispatch.CollisionObject collObj : gObject.getOverlappingPairs()) {
        overlappingObjects.add((PhysicsCollisionObject) collObj.getUserPointer());
    }
    return overlappingObjects;
}
 
Example #21
Source File: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void removeCollisionObject(PhysicsCollisionObject obj) {
    if (obj instanceof PhysicsGhostObject) {
        removeGhostObject((PhysicsGhostObject) obj);
    } else if (obj instanceof PhysicsRigidBody) {
        removeRigidBody((PhysicsRigidBody) obj);
    } else if (obj instanceof PhysicsCharacter) {
        removeCharacter((PhysicsCharacter) obj);
    }
}
 
Example #22
Source File: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void removeCollisionObject(PhysicsCollisionObject obj) {
    if (obj instanceof PhysicsGhostObject) {
        removeGhostObject((PhysicsGhostObject) obj);
    } else if (obj instanceof PhysicsRigidBody) {
        removeRigidBody((PhysicsRigidBody) obj);
    } else if (obj instanceof PhysicsCharacter) {
        removeCharacter((PhysicsCharacter) obj);
    }
}
 
Example #23
Source File: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void addCollisionObject(PhysicsCollisionObject obj) {
    if (obj instanceof PhysicsGhostObject) {
        addGhostObject((PhysicsGhostObject) obj);
    } else if (obj instanceof PhysicsRigidBody) {
        addRigidBody((PhysicsRigidBody) obj);
    } else if (obj instanceof PhysicsVehicle) {
        addRigidBody((PhysicsVehicle) obj);
    } else if (obj instanceof PhysicsCharacter) {
        addCharacter((PhysicsCharacter) obj);
    }
}
 
Example #24
Source File: TestHoveringTank.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void makeMissile() {
    Vector3f pos = spaceCraft.getWorldTranslation().clone();
    Quaternion rot = spaceCraft.getWorldRotation();
    Vector3f dir = rot.getRotationColumn(2);

    Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
    missile.scale(0.5f);
    missile.rotate(0, FastMath.PI, 0);
    missile.updateGeometricState();

    BoundingBox box = (BoundingBox) missile.getWorldBound();
    final Vector3f extent = box.getExtent(null);

    BoxCollisionShape boxShape = new BoxCollisionShape(extent);

    missile.setName("Missile");
    missile.rotate(rot);
    missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0));
    missile.setLocalRotation(hoverControl.getPhysicsRotation());
    missile.setShadowMode(ShadowMode.Cast);
    RigidBodyControl control = new BombControl(assetManager, boxShape, 20);
    control.setLinearVelocity(dir.mult(100));
    control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
    missile.addControl(control);


    rootNode.attachChild(missile);
    getPhysicsSpace().add(missile);
}
 
Example #25
Source File: VehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
     * returns the object this wheel is in contact with or null if no contact
     * @return the PhysicsCollisionObject (PhysicsRigidBody, PhysicsGhostObject)
     */
    public PhysicsCollisionObject getGroundObject() {
//        if (wheelInfo.raycastInfo.groundObject == null) {
//            return null;
//        } else if (wheelInfo.raycastInfo.groundObject instanceof RigidBody) {
//            System.out.println("RigidBody");
//            return (PhysicsRigidBody) ((RigidBody) wheelInfo.raycastInfo.groundObject).getUserPointer();
//        } else {
            return null;
//        }
    }
 
Example #26
Source File: TestBoneRagdoll.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void collide(Bone bone, PhysicsCollisionObject object, PhysicsCollisionEvent event) {

        if (object.getUserObject() != null && object.getUserObject() instanceof Geometry) {
            Geometry geom = (Geometry) object.getUserObject();
            if ("Floor".equals(geom.getName())) {
                return;
            }
        }

        ragdoll.setRagdollMode();

    }
 
Example #27
Source File: PhysicsGhostObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
     * Another Object is overlapping with this GhostNode,
     * if and if only there CollisionShapes overlaps.
     * They could be both regular PhysicsRigidBodys or PhysicsGhostObjects.
     * @return All CollisionObjects overlapping with this GhostNode.
     */
    public List<PhysicsCollisionObject> getOverlappingObjects() {
        overlappingObjects.clear();
        getOverlappingObjects(objectId);
//        for (com.bulletphysics.collision.dispatch.CollisionObject collObj : gObject.getOverlappingPairs()) {
//            overlappingObjects.add((PhysicsCollisionObject) collObj.getUserPointer());
//        }
        return overlappingObjects;
    }
 
Example #28
Source File: TestIssue1283.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Add a projectile to the scene and physics space. Its initial position and
 * velocity are determined by the camera the and mouse pointer.
 */
private void launchProjectile() {
    Vector2f screenXY = inputManager.getCursorPosition();
    float nearZ = 0f;
    Vector3f nearLocation = cam.getWorldCoordinates(screenXY, nearZ);
    float farZ = 1f;
    Vector3f farLocation = cam.getWorldCoordinates(screenXY, farZ);
    Vector3f direction = farLocation.subtract(nearLocation);
    direction.normalizeLocal();

    Geometry geometry = new Geometry("projectile", projectileMesh);
    rootNode.attachChild(geometry);
    geometry.setLocalTranslation(nearLocation);
    geometry.setMaterial(projectileMaterial);

    float mass = 1f;
    RigidBodyControl physicsControl = new RigidBodyControl(mass);
    geometry.addControl(physicsControl);

    physicsControl.setCcdMotionThreshold(0.01f);
    physicsControl.setCcdSweptSphereRadius(projectileRadius);
    physicsControl.setCollisionGroup(
            PhysicsCollisionObject.COLLISION_GROUP_02);
    physicsControl.setCollideWithGroups(
            PhysicsCollisionObject.COLLISION_GROUP_02);
    physicsControl.setRestitution(0.8f);

    float projectileSpeed = 250f; // physics-space units per second
    Vector3f initialVelocity = direction.mult(projectileSpeed);
    physicsControl.setLinearVelocity(initialVelocity);

    physicsSpace.add(physicsControl);
}
 
Example #29
Source File: PhysicsSpace.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void addCollisionObject(PhysicsCollisionObject obj) {
    if (obj instanceof PhysicsGhostObject) {
        addGhostObject((PhysicsGhostObject) obj);
    } else if (obj instanceof PhysicsRigidBody) {
        addRigidBody((PhysicsRigidBody) obj);
    } else if (obj instanceof PhysicsVehicle) {
        addRigidBody((PhysicsVehicle) obj);
    } else if (obj instanceof PhysicsCharacter) {
        addCharacter((PhysicsCharacter) obj);
    }
}
 
Example #30
Source File: TestHoveringTank.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void makeMissile() {
    Vector3f pos = spaceCraft.getWorldTranslation().clone();
    Quaternion rot = spaceCraft.getWorldRotation();
    Vector3f dir = rot.getRotationColumn(2);

    Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
    missile.scale(0.5f);
    missile.rotate(0, FastMath.PI, 0);
    missile.updateGeometricState();

    BoundingBox box = (BoundingBox) missile.getWorldBound();
    final Vector3f extent = box.getExtent(null);

    BoxCollisionShape boxShape = new BoxCollisionShape(extent);

    missile.setName("Missile");
    missile.rotate(rot);
    missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0));
    missile.setLocalRotation(hoverControl.getPhysicsRotation());
    missile.setShadowMode(ShadowMode.Cast);
    RigidBodyControl control = new BombControl(assetManager, boxShape, 20);
    control.setLinearVelocity(dir.mult(100));
    control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
    missile.addControl(control);


    rootNode.attachChild(missile);
    getPhysicsSpace().add(missile);
}