Search in sources :

Example 1 with ChildCollisionShape

use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.

the class BufferedTriangleCallback method getDebugShape.

/**
     * 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;
}
Also used : Geometry(com.jme3.scene.Geometry) CompoundCollisionShape(com.jme3.bullet.collision.shapes.CompoundCollisionShape) ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) CompoundCollisionShape(com.jme3.bullet.collision.shapes.CompoundCollisionShape) Spatial(com.jme3.scene.Spatial) Matrix3f(com.jme3.math.Matrix3f) Node(com.jme3.scene.Node) ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) TempVars(com.jme3.util.TempVars)

Example 2 with ChildCollisionShape

use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.

the class CompoundCollisionShape method addChildShape.

/**
     * adds a child shape at the given local translation
     * @param shape the child shape to add
     * @param location the local location of the child shape
     */
public void addChildShape(CollisionShape shape, Vector3f location) {
    Transform transA = new Transform(Converter.convert(new Matrix3f()));
    Converter.convert(location, transA.origin);
    children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape));
    ((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
Also used : Matrix3f(com.jme3.math.Matrix3f) ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) CompoundShape(com.bulletphysics.collision.shapes.CompoundShape) Transform(com.bulletphysics.linearmath.Transform)

Example 3 with ChildCollisionShape

use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.

the class CompoundCollisionShape method read.

public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule capsule = im.getCapsule(this);
    children = capsule.readSavableArrayList("children", new ArrayList<ChildCollisionShape>());
    cShape.setLocalScaling(Converter.convert(getScale()));
    cShape.setMargin(margin);
    loadChildren();
}
Also used : InputCapsule(com.jme3.export.InputCapsule) ArrayList(java.util.ArrayList)

Example 4 with ChildCollisionShape

use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.

the class CompoundCollisionShape method loadChildren.

private void loadChildren() {
    for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext(); ) {
        ChildCollisionShape child = it.next();
        addChildShapeDirect(child.shape, child.location, child.rotation);
    }
}
Also used : ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape)

Example 5 with ChildCollisionShape

use of com.jme3.bullet.collision.shapes.infos.ChildCollisionShape in project jmonkeyengine by jMonkeyEngine.

the class CompoundCollisionShape method addChildShape.

/**
     * adds a child shape at the given local translation
     * @param shape the child shape to add
     * @param location the local location of the child shape
     */
public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rotation) {
    if (shape instanceof CompoundCollisionShape) {
        throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!");
    }
    Transform transA = new Transform(Converter.convert(rotation));
    Converter.convert(location, transA.origin);
    Converter.convert(rotation, transA.basis);
    children.add(new ChildCollisionShape(location.clone(), rotation.clone(), shape));
    ((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
Also used : ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) CompoundShape(com.bulletphysics.collision.shapes.CompoundShape) Transform(com.bulletphysics.linearmath.Transform)

Aggregations

ChildCollisionShape (com.jme3.bullet.collision.shapes.infos.ChildCollisionShape)7 Matrix3f (com.jme3.math.Matrix3f)4 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)2 Transform (com.bulletphysics.linearmath.Transform)2 CollisionShape (com.jme3.bullet.collision.shapes.CollisionShape)2 CompoundCollisionShape (com.jme3.bullet.collision.shapes.CompoundCollisionShape)2 Geometry (com.jme3.scene.Geometry)2 Node (com.jme3.scene.Node)2 Spatial (com.jme3.scene.Spatial)2 TempVars (com.jme3.util.TempVars)2 InputCapsule (com.jme3.export.InputCapsule)1 OutputCapsule (com.jme3.export.OutputCapsule)1 Vector3f (com.jme3.math.Vector3f)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1