Search in sources :

Example 86 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class TestGhostObject method initGhostObject.

private void initGhostObject() {
    Vector3f halfExtents = new Vector3f(3, 4.2f, 1);
    ghostControl = new GhostControl(new BoxCollisionShape(halfExtents));
    Node node = new Node("Ghost Object");
    node.addControl(ghostControl);
    rootNode.attachChild(node);
    getPhysicsSpace().add(ghostControl);
}
Also used : GhostControl(com.jme3.bullet.control.GhostControl) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape)

Example 87 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class TestPhysicsCar method buildPlayer.

private void buildPlayer() {
    Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Red);
    //create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0
    //this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0
    CompoundCollisionShape compoundShape = new CompoundCollisionShape();
    BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f));
    compoundShape.addChildShape(box, new Vector3f(0, 1, 0));
    //create vehicle node
    Node vehicleNode = new Node("vehicleNode");
    vehicle = new VehicleControl(compoundShape, 400);
    vehicleNode.addControl(vehicle);
    //setting suspension values for wheels, this can be a bit tricky
    //see also https://docs.google.com/Doc?docid=0AXVUZ5xw6XpKZGNuZG56a3FfMzU0Z2NyZnF4Zmo&hl=en
    //200=f1 car
    float stiffness = 60.0f;
    //(should be lower than damp)
    float compValue = .3f;
    float dampValue = .4f;
    vehicle.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
    vehicle.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
    vehicle.setSuspensionStiffness(stiffness);
    vehicle.setMaxSuspensionForce(10000.0f);
    //Create four wheels and add them at their locations
    // was 0, -1, 0
    Vector3f wheelDirection = new Vector3f(0, -1, 0);
    // was -1, 0, 0
    Vector3f wheelAxle = new Vector3f(-1, 0, 0);
    float radius = 0.5f;
    float restLength = 0.3f;
    float yOff = 0.5f;
    float xOff = 1f;
    float zOff = 2f;
    Cylinder wheelMesh = new Cylinder(16, 16, radius, radius * 0.6f, true);
    Node node1 = new Node("wheel 1 node");
    Geometry wheels1 = new Geometry("wheel 1", wheelMesh);
    node1.attachChild(wheels1);
    wheels1.rotate(0, FastMath.HALF_PI, 0);
    wheels1.setMaterial(mat);
    vehicle.addWheel(node1, new Vector3f(-xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true);
    Node node2 = new Node("wheel 2 node");
    Geometry wheels2 = new Geometry("wheel 2", wheelMesh);
    node2.attachChild(wheels2);
    wheels2.rotate(0, FastMath.HALF_PI, 0);
    wheels2.setMaterial(mat);
    vehicle.addWheel(node2, new Vector3f(xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true);
    Node node3 = new Node("wheel 3 node");
    Geometry wheels3 = new Geometry("wheel 3", wheelMesh);
    node3.attachChild(wheels3);
    wheels3.rotate(0, FastMath.HALF_PI, 0);
    wheels3.setMaterial(mat);
    vehicle.addWheel(node3, new Vector3f(-xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false);
    Node node4 = new Node("wheel 4 node");
    Geometry wheels4 = new Geometry("wheel 4", wheelMesh);
    node4.attachChild(wheels4);
    wheels4.rotate(0, FastMath.HALF_PI, 0);
    wheels4.setMaterial(mat);
    vehicle.addWheel(node4, new Vector3f(xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false);
    vehicleNode.attachChild(node1);
    vehicleNode.attachChild(node2);
    vehicleNode.attachChild(node3);
    vehicleNode.attachChild(node4);
    rootNode.attachChild(vehicleNode);
    getPhysicsSpace().add(vehicle);
}
Also used : Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) CompoundCollisionShape(com.jme3.bullet.collision.shapes.CompoundCollisionShape) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) VehicleControl(com.jme3.bullet.control.VehicleControl) Material(com.jme3.material.Material) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape)

Example 88 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class TestPhysicsHingeJoint method setupJoint.

public void setupJoint() {
    Node holderNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.1f, .1f, .1f)), 0);
    holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f));
    rootNode.attachChild(holderNode);
    getPhysicsSpace().add(holderNode);
    Node hammerNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 1);
    hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -1, 0f));
    rootNode.attachChild(hammerNode);
    getPhysicsSpace().add(hammerNode);
    joint = new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f, -1, 0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z);
    getPhysicsSpace().add(joint);
}
Also used : HingeJoint(com.jme3.bullet.joints.HingeJoint) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 89 with Node

use of com.jme3.scene.Node 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 90 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class RagdollUtils method buildPointMap.

public static Map<Integer, List<Float>> buildPointMap(Spatial model) {
    Map<Integer, List<Float>> map = new HashMap<Integer, List<Float>>();
    if (model instanceof Geometry) {
        Geometry g = (Geometry) model;
        buildPointMapForMesh(g.getMesh(), map);
    } else if (model instanceof Node) {
        Node node = (Node) model;
        for (Spatial s : node.getChildren()) {
            if (s instanceof Geometry) {
                Geometry g = (Geometry) s;
                buildPointMapForMesh(g.getMesh(), map);
            }
        }
    }
    return map;
}
Also used : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node)

Aggregations

Node (com.jme3.scene.Node)135 Vector3f (com.jme3.math.Vector3f)81 Geometry (com.jme3.scene.Geometry)64 Spatial (com.jme3.scene.Spatial)53 Material (com.jme3.material.Material)51 DirectionalLight (com.jme3.light.DirectionalLight)35 Quaternion (com.jme3.math.Quaternion)32 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)26 Box (com.jme3.scene.shape.Box)24 Sphere (com.jme3.scene.shape.Sphere)19 AmbientLight (com.jme3.light.AmbientLight)17 BulletAppState (com.jme3.bullet.BulletAppState)16 ColorRGBA (com.jme3.math.ColorRGBA)15 AnimControl (com.jme3.animation.AnimControl)14 KeyTrigger (com.jme3.input.controls.KeyTrigger)14 FilterPostProcessor (com.jme3.post.FilterPostProcessor)14 HashMap (java.util.HashMap)14 CameraNode (com.jme3.scene.CameraNode)13 ArrayList (java.util.ArrayList)13 ActionListener (com.jme3.input.controls.ActionListener)12