Search in sources :

Example 6 with ChildCollisionShape

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

the class CollisionShapeFactory method shiftCompoundShapeContents.

/**
     * This method moves each child shape of a compound shape by the given vector
     * @param vector
     */
public static void shiftCompoundShapeContents(CompoundCollisionShape compoundShape, Vector3f vector) {
    for (Iterator<ChildCollisionShape> it = new LinkedList(compoundShape.getChildren()).iterator(); it.hasNext(); ) {
        ChildCollisionShape childCollisionShape = it.next();
        CollisionShape child = childCollisionShape.shape;
        Vector3f location = childCollisionShape.location;
        Matrix3f rotation = childCollisionShape.rotation;
        compoundShape.removeChildShape(child);
        compoundShape.addChildShape(child, location.add(vector), rotation);
    }
}
Also used : ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) Matrix3f(com.jme3.math.Matrix3f) Vector3f(com.jme3.math.Vector3f) ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) LinkedList(java.util.LinkedList)

Example 7 with ChildCollisionShape

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

the class DebugShapeFactory method getDebugShape.

/** The maximum corner for the aabb used for triangles to include in ConcaveShape processing.*/
//    private static final Vector3f aabbMax = new Vector3f(1e30f, 1e30f, 1e30f);
/** The minimum corner for the aabb used for triangles to include in ConcaveShape processing.*/
//    private static final Vector3f aabbMin = new Vector3f(-1e30f, -1e30f, -1e30f);
/**
     * 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 8 with ChildCollisionShape

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

the class CompoundCollisionShape method write.

public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule capsule = ex.getCapsule(this);
    capsule.writeSavableArrayList(children, "children", new ArrayList<ChildCollisionShape>());
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule) ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape)

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