com.jme3.bullet.collision.shapes.CollisionShape Java Examples

The following examples show how to use com.jme3.bullet.collision.shapes.CollisionShape. 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: JmeGhostControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected Sheet createSheet() {
    Sheet sheet = super.createSheet();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("GhostControl");
    set.setName(GhostControl.class.getName());
    GhostControl obj = geom;//getLookup().lookup(Spatial.class);
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, Vector3f.class, "getPhysicsLocation", "setPhysicsLocation", "Physics Location"));
    set.put(makeProperty(obj, Quaternion.class, "getPhysicsRotation", "setPhysicsRotation", "Physics Rotation"));
    
    set.put(makeProperty(obj, CollisionShape.class, "getCollisionShape", "setCollisionShape", "Collision Shape"));
    set.put(makeProperty(obj, int.class, "getCollisionGroup", "setCollisionGroup", "Collision Group"));
    set.put(makeProperty(obj, int.class, "getCollideWithGroups", "setCollideWithGroups", "Collide With Groups"));

    sheet.put(set);
    return sheet;

}
 
Example #2
Source File: TestPhysicsRayCast.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    stateManager.attach(bulletAppState);
    initCrossHair();

    Spatial s = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
    s.setLocalScale(0.1f);

    CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(s);
    Node n = new Node("elephant");
    n.addControl(new RigidBodyControl(collisionShape, 1));
    n.getControl(RigidBodyControl.class).setKinematic(true);
    bulletAppState.getPhysicsSpace().add(n);
    rootNode.attachChild(n);
    bulletAppState.setDebugEnabled(true);
}
 
Example #3
Source File: BulletCharacterDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Update this control. Invoked once per frame during the logical-state
 * update, provided the control is enabled and added to a scene. Should be
 * invoked only by a subclass or by AbstractControl.
 *
 * @param tpf the time interval between frames (in seconds, ≥0)
 */
@Override
protected void controlUpdate(float tpf) {
    CollisionShape newShape = body.getCollisionShape();
    Vector3f newScale = newShape.getScale();
    if (myShape != newShape || !oldScale.equals(newScale)) {
        myShape = newShape;
        oldScale.set(newScale);

        Node node = (Node) spatial;
        node.detachChild(geom);

        geom = DebugShapeFactory.getDebugShape(myShape);
        geom.setName(body.toString());

        node.attachChild(geom);
    }
    geom.setMaterial(debugAppState.DEBUG_PINK);

    body.getPhysicsLocation(location);
    applyPhysicsTransform(location, Quaternion.IDENTITY);
}
 
Example #4
Source File: DacLinks.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a jointless BoneLink for the named bone, and add it to the
 * boneLinks map.
 *
 * @param boneName the name of the bone to be linked (not null)
 * @param vertexLocations the set of vertex locations (not null, not empty)
 */
private void createBoneLink(String boneName, VectorSet vertexLocations) {
    Joint bone = findBone(boneName);
    Transform boneToMesh = bone.getModelTransform();
    Transform meshToBone = boneToMesh.invert();
    //logger3.log(Level.INFO, "meshToBone = {0}", meshToBone);
    /*
     * Create the CollisionShape and locate the center of mass.
     */
    CollisionShape shape;
    Vector3f center;
    if (vertexLocations == null || vertexLocations.numVectors() == 0) {
        throw new IllegalStateException("no vertex for " + boneName);
    } else {
        center = vertexLocations.mean(null);
        center.subtractLocal(bone.getModelTransform().getTranslation());
        shape = createShape(meshToBone, center, vertexLocations);
    }

    meshToBone.getTranslation().zero();
    float mass = super.mass(boneName);
    Vector3f offset = meshToBone.transformVector(center, null);
    BoneLink link = new BoneLink(this, bone, shape, mass, offset);
    boneLinks.put(boneName, link);
}
 
Example #5
Source File: PhysicsLink.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Instantiate a purely kinematic link between the specified skeleton bone
 * and the specified rigid body.
 *
 * @param control the control that will manage this link (not null, alias
 * created)
 * @param bone the corresponding bone (not null, alias created)
 * @param collisionShape the desired shape (not null, alias created)
 * @param mass the mass (in physics-mass units)
 * @param localOffset the location of the body's center (in the bone's local
 * coordinates, not null, unaffected)
 */
PhysicsLink(DacLinks control, Joint bone, CollisionShape collisionShape,
        float mass, Vector3f localOffset) {
    assert control != null;
    assert bone != null;
    assert collisionShape != null;
    assert localOffset != null;

    this.control = control;
    this.bone = bone;
    rigidBody = createRigidBody(mass, collisionShape);

    logger.log(Level.FINE, "Creating link for bone {0} with mass={1}",
            new Object[]{bone.getName(), rigidBody.getMass()});

    this.localOffset = localOffset.clone();
    updateKPTransform();
}
 
Example #6
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 #7
Source File: DebugShapeFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a debug spatial from the specified collision shape.
 * <p>
 * This is mostly used internally. To attach a debug shape to a physics
 * object, call <code>attachDebugShape(AssetManager manager);</code> on it.
 *
 * @param collisionShape the shape to visualize (may be null, unaffected)
 * @return a new tree of geometries, or null
 */
public static Spatial getDebugShape(CollisionShape collisionShape) {
    if (collisionShape == null) {
        return null;
    }
    Spatial debugShape;
    if (collisionShape instanceof CompoundCollisionShape) {
        CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape;
        List<ChildCollisionShape> children = shape.getChildren();
        Node node = new Node("DebugShapeNode");
        for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext();) {
            ChildCollisionShape childCollisionShape = it.next();
            CollisionShape ccollisionShape = childCollisionShape.shape;
            Geometry geometry = createDebugShape(ccollisionShape);

            // apply translation
            geometry.setLocalTranslation(childCollisionShape.location);

            // apply rotation
            TempVars vars = TempVars.get();                
            Matrix3f tempRot = vars.tempMat3;

            tempRot.set(geometry.getLocalRotation());
            childCollisionShape.rotation.mult(tempRot, tempRot);
            geometry.setLocalRotation(tempRot);

            vars.release();

            node.attachChild(geometry);
        }
        debugShape = node;
    } else {
        debugShape = createDebugShape(collisionShape);
    }
    if (debugShape == null) {
        return null;
    }
    debugShape.updateGeometricState();
    return debugShape;
}
 
Example #8
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 #9
Source File: PhysicsSpace.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults<br/>
 * You have to use different Transforms for start and end (at least distance greater than 0.4f).
 * SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center.
 */
public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results) {
    results.clear();
    if (!(shape.getCShape() instanceof ConvexShape)) {
        logger.log(Level.WARNING, "Trying to sweep test with incompatible mesh shape!");
        return results;
    }
    dynamicsWorld.convexSweepTest((ConvexShape) shape.getCShape(), Converter.convert(start, sweepTrans1), Converter.convert(end, sweepTrans2), new InternalSweepListener(results));
    return results;
}
 
Example #10
Source File: CollisionShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This method creates a hull shape for the given Spatial.<br>
 * If you want to have mesh-accurate dynamic shapes (CPU intense!!!) use GImpact shapes, its probably best to do so with a low-poly version of your model.
 * @return A HullCollisionShape or a CompoundCollisionShape with HullCollisionShapes as children if the supplied spatial is a Node.
 */
public static CollisionShape createDynamicMeshShape(Spatial spatial) {
    if (spatial instanceof Geometry) {
        return createSingleDynamicMeshShape((Geometry) spatial, spatial);
    } else if (spatial instanceof Node) {
        return createCompoundShape((Node) spatial, (Node) spatial, new CompoundCollisionShape(), true, true);
    } else {
        throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!");
    }

}
 
Example #11
Source File: PhysicsCharacter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
     * Apply the specified CollisionShape to this character. Note that the
     * character should not be in any physics space while changing shape; the
     * character gets rebuilt on the physics side.
     *
     * @param collisionShape the shape to apply (not null, alias created)
     */
    @Override
    public void setCollisionShape(CollisionShape collisionShape) {
//        if (!(collisionShape.getObjectId() instanceof ConvexShape)) {
//            throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes"));
//        }
        super.setCollisionShape(collisionShape);
        if (objectId == 0) {
            buildObject();
        } else {
            attachCollisionShape(objectId, collisionShape.getObjectId());
        }
    }
 
Example #12
Source File: PhysicsGhostObject.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Apply the specified CollisionShape to this object. Note that the object
 * should not be in any physics space while changing shape; the object gets
 * rebuilt on the physics side.
 *
 * @param collisionShape the shape to apply (not null, alias created)
 */
@Override
public void setCollisionShape(CollisionShape collisionShape) {
    super.setCollisionShape(collisionShape);
    if (objectId == 0) {
        buildObject();
    } else {
        attachCollisionShape(objectId, collisionShape.getObjectId());
    }
}
 
Example #13
Source File: PhysicsSpace.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
     * Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults<br/>
     * You have to use different Transforms for start and end (at least distance > 0.4f).
     * SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center.
     */
    public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results) {
        results.clear();
//        if (!(shape.getCShape() instanceof ConvexShape)) {
//            Logger.getLogger(PhysicsSpace.class.getName()).log(Level.WARNING, "Trying to sweep test with incompatible mesh shape!");
//            return results;
//        }
//        dynamicsWorld.convexSweepTest((ConvexShape) shape.getCShape(), Converter.convert(start, sweepTrans1), Converter.convert(end, sweepTrans2), new InternalSweepListener(results));
        return results;
    }
 
Example #14
Source File: PhysicsRigidBody.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setCollisionShape(CollisionShape collisionShape) {
    super.setCollisionShape(collisionShape);
    if(collisionShape instanceof MeshCollisionShape && mass!=0){
        throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!");
    }
    if (rBody == null) {
        rebuildRigidBody();
    } else {
        collisionShape.calculateLocalInertia(mass, localInertia);
        constructionInfo.collisionShape = collisionShape.getCShape();
        rBody.setCollisionShape(collisionShape.getCShape());
    }
}
 
Example #15
Source File: DebugShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a debug shape from the given collision shape. This is mostly used internally.<br>
 * To attach a debug shape to a physics object, call <code>attachDebugShape(AssetManager manager);</code> on it.
 * @param collisionShape
 * @return
 */
public static Spatial getDebugShape(CollisionShape collisionShape) {
    if (collisionShape == null) {
        return null;
    }
    Spatial debugShape;
    if (collisionShape instanceof CompoundCollisionShape) {
        CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape;
        List<ChildCollisionShape> children = shape.getChildren();
        Node node = new Node("DebugShapeNode");
        for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext();) {
            ChildCollisionShape childCollisionShape = it.next();
            CollisionShape ccollisionShape = childCollisionShape.shape;
            Geometry geometry = createDebugShape(ccollisionShape);

            // apply translation
            geometry.setLocalTranslation(childCollisionShape.location);

            // apply rotation
            TempVars vars = TempVars.get();                
            Matrix3f tempRot = vars.tempMat3;

            tempRot.set(geometry.getLocalRotation());
            childCollisionShape.rotation.mult(tempRot, tempRot);
            geometry.setLocalRotation(tempRot);

            vars.release();

            node.attachChild(geometry);
        }
        debugShape = node;
    } else {
        debugShape = createDebugShape(collisionShape);
    }
    if (debugShape == null) {
        return null;
    }
    debugShape.updateGeometricState();
    return debugShape;
}
 
Example #16
Source File: PMDRigidBody.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public PMDRigidBody(PMDNode pmdNode, Bone bone, int rigidBodyType, Vector3f pos, Quaternion rot, CollisionShape cs, float f) {
        super(cs, f);
        this.pmdNode = pmdNode;
        this.bone = bone;
        this.rigidBodyType = rigidBodyType;
        this.pos.set(pos);
        this.rot.set(rot);

        invPos.set(pos);
        invPos.negateLocal();
        invRot.set(rot);
        invRot.inverseLocal();
        invM.setTransform(pos, new Vector3f(1f, 1f, 1f), rot.toRotationMatrix());
        m.set(invM);
        invM.invertLocal();
        m2.loadIdentity();
        centerBone = pmdNode.getSkeleton().getBone("センター");
        if (bone == centerBone) {
            centerFlag = true;
        } else {
            centerFlag = false;
        }
//        if (bone != null) {
//            if (!isKinematic()) {
//                bone.setUseModelSpaceVectors(true);
//            }else {
//                bone.setUseModelSpaceVectors(false);
//            }
//        }
    }
 
Example #17
Source File: PhysicsCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
     * @param shape The CollisionShape (no Mesh or CompoundCollisionShapes)
     * @param stepHeight The quantization size for vertical movement
     */
    public PhysicsCharacter(CollisionShape shape, float stepHeight) {
        this.collisionShape = shape;
//        if (shape instanceof MeshCollisionShape || shape instanceof CompoundCollisionShape) {
//            throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh or compound collision shapes"));
//        }
        this.stepHeight = stepHeight;
        buildObject();
    }
 
Example #18
Source File: PhysicsCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param shape The CollisionShape (no Mesh or CompoundCollisionShapes)
 * @param stepHeight The quantization size for vertical movement
 */
public PhysicsCharacter(CollisionShape shape, float stepHeight) {
    this.collisionShape = shape;
    if (!(shape.getCShape() instanceof ConvexShape)) {
        throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes"));
    }
    this.stepHeight = stepHeight;
    buildObject();
}
 
Example #19
Source File: DebugShapeFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
     * Create a geometry for visualizing the specified shape.
     *
     * @param shape (not null, unaffected)
     * @return a new geometry (not null)
     */
    private static Geometry createDebugShape(CollisionShape shape) {
        Geometry geom = new Geometry();
        geom.setMesh(DebugShapeFactory.getDebugMesh(shape));
//        geom.setLocalScale(shape.getScale());
        geom.updateModelBound();
        return geom;
    }
 
Example #20
Source File: CollisionShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static CollisionShape createBoxShape(Spatial spatial) {
    if (spatial instanceof Geometry) {
        return createSingleBoxShape((Geometry) spatial, spatial);
    } else if (spatial instanceof Node) {
        return createBoxCompoundShape((Node) spatial);
    } else {
        throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!");
    }
}
 
Example #21
Source File: BulletRigidBodyDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Update this control. Invoked once per frame during the logical-state
 * update, provided the control is enabled and added to a scene. Should be
 * invoked only by a subclass or by AbstractControl.
 *
 * @param tpf the time interval between frames (in seconds, &ge;0)
 */
@Override
protected void controlUpdate(float tpf) {
    CollisionShape newShape = body.getCollisionShape();
    Vector3f newScale = newShape.getScale();
    if (myShape != newShape || !oldScale.equals(newScale)) {
        myShape = newShape;
        oldScale.set(newScale);

        Node node = (Node) spatial;
        node.detachChild(geom);

        geom = DebugShapeFactory.getDebugShape(myShape);
        geom.setName(body.toString());

        node.attachChild(geom);
    }
    if(body.isActive()){
        geom.setMaterial(debugAppState.DEBUG_MAGENTA);
    }else{
        geom.setMaterial(debugAppState.DEBUG_BLUE);
    }

    body.getPhysicsLocation(location);
    body.getPhysicsRotation(rotation);
    applyPhysicsTransform(location, rotation);
}
 
Example #22
Source File: PhysicsCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
    public void setCollisionShape(CollisionShape collisionShape) {
//        if (!(collisionShape.getObjectId() instanceof ConvexShape)) {
//            throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes"));
//        }
        super.setCollisionShape(collisionShape);
        if (objectId == 0) {
            buildObject();
        } else {
            attachCollisionShape(objectId, collisionShape.getObjectId());
        }
    }
 
Example #23
Source File: TestGhostObject.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);

    // Mesh to be shared across several boxes.
    Box boxGeom = new Box(Vector3f.ZERO, 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 #24
Source File: PhysicsCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void setCollisionShape(CollisionShape collisionShape) {
    if (!(collisionShape.getCShape() instanceof ConvexShape)) {
        throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes"));
    }
    super.setCollisionShape(collisionShape);
    if (gObject == null) {
        buildObject();
    }else{
        gObject.setCollisionShape(collisionShape.getCShape());
    }
}
 
Example #25
Source File: BetterCharacterControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a collision shape based on the scale parameter. The new shape is a
 * compound shape containing an offset capsule.
 *
 * @return a new compound shape (not null)
 */
protected CollisionShape getShape() {
    //TODO: cleanup size mess..
    CapsuleCollisionShape capsuleCollisionShape = new CapsuleCollisionShape(getFinalRadius(), (getFinalHeight() - (2 * getFinalRadius())));
    CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape();
    Vector3f addLocation = new Vector3f(0, (getFinalHeight() / 2.0f), 0);
    compoundCollisionShape.addChildShape(capsuleCollisionShape, addLocation);
    return compoundCollisionShape;
}
 
Example #26
Source File: CollisionShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static CollisionShape createBoxShape(Spatial spatial) {
    if (spatial instanceof Geometry) {
        return createSingleBoxShape((Geometry) spatial, spatial);
    } else if (spatial instanceof Node) {
        return createBoxCompoundShape((Node) spatial);
    } else {
        throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!");
    }
}
 
Example #27
Source File: PhysicsGhostObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void setCollisionShape(CollisionShape collisionShape) {
    super.setCollisionShape(collisionShape);
    if (objectId == 0) {
        buildObject();
    }else{
        attachCollisionShape(objectId, collisionShape.getObjectId());
    }
}
 
Example #28
Source File: PhysicsRigidBody.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setCollisionShape(CollisionShape collisionShape) {
    super.setCollisionShape(collisionShape);
    if(collisionShape instanceof MeshCollisionShape && mass!=0){
        throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!");
    }
    if (rBody == null) {
        rebuildRigidBody();
    } else {
        collisionShape.calculateLocalInertia(mass, localInertia);
        constructionInfo.collisionShape = collisionShape.getCShape();
        rBody.setCollisionShape(collisionShape.getCShape());
    }
}
 
Example #29
Source File: PhysicsCharacter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setCollisionShape(CollisionShape collisionShape) {
    if (!(collisionShape.getCShape() instanceof ConvexShape)) {
        throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes"));
    }
    super.setCollisionShape(collisionShape);
    if (gObject == null) {
        buildObject();
    }else{
        gObject.setCollisionShape(collisionShape.getCShape());
    }
}
 
Example #30
Source File: JmeVehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Sheet createSheet() {
    Sheet sheet = super.createSheet();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("VehicleControl");
    set.setName(VehicleControl.class.getName());
    VehicleControl obj = vehicle;//getLookup().lookup(Spatial.class);
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, Vector3f.class, "getPhysicsLocation", "setPhysicsLocation", "Physics Location"));
    set.put(makeProperty(obj, Quaternion.class, "getPhysicsRotation", "setPhysicsRotation", "Physics Rotation"));

    set.put(makeProperty(obj, CollisionShape.class, "getCollisionShape", "setCollisionShape", "Collision Shape"));
    set.put(makeProperty(obj, int.class, "getCollisionGroup", "setCollisionGroup", "Collision Group"));
    set.put(makeProperty(obj, int.class, "getCollideWithGroups", "setCollideWithGroups", "Collide With Groups"));

    set.put(makeProperty(obj, float.class, "getFriction", "setFriction", "Friction"));
    set.put(makeProperty(obj, float.class, "getMass", "setMass", "Mass"));
    set.put(makeProperty(obj, boolean.class, "isKinematic", "setKinematic", "Kinematic"));
    set.put(makeProperty(obj, Vector3f.class, "getGravity", "setGravity", "Gravity"));
    set.put(makeProperty(obj, float.class, "getLinearDamping", "setLinearDamping", "Linear Damping"));
    set.put(makeProperty(obj, float.class, "getAngularDamping", "setAngularDamping", "Angular Damping"));
    set.put(makeProperty(obj, float.class, "getRestitution", "setRestitution", "Restitution"));

    set.put(makeProperty(obj, float.class, "getLinearSleepingThreshold", "setLinearSleepingThreshold", "Linear Sleeping Threshold"));
    set.put(makeProperty(obj, float.class, "getAngularSleepingThreshold", "setAngularSleepingThreshold", "Angular Sleeping Threshold"));

    set.put(makeProperty(obj, float.class, "getFrictionSlip", "setFrictionSlip", "Friction Slip"));
    set.put(makeProperty(obj, float.class, "getMaxSuspensionTravelCm", "setMaxSuspensionTravelCm", "Max Suspension Travel Cm"));
    set.put(makeProperty(obj, float.class, "getMaxSuspensionForce", "setMaxSuspensionForce", "Max Suspension Force"));
    set.put(makeProperty(obj, float.class, "getSuspensionCompression", "setSuspensionCompression", "Suspension Compression"));
    set.put(makeProperty(obj, float.class, "getSuspensionDamping", "setSuspensionDamping", "Suspension Damping"));
    set.put(makeProperty(obj, float.class, "getSuspensionStiffness", "setSuspensionStiffness", "Suspension Stiffness"));

    sheet.put(set);
    return sheet;

}