Search in sources :

Example 26 with RigidBodyControl

use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.

the class PhysicsTestHelper method createPhysicsTestNode.

/**
     * creates an empty node with a RigidBodyControl
     * @param manager
     * @param shape
     * @param mass
     * @return
     */
public static Node createPhysicsTestNode(AssetManager manager, CollisionShape shape, float mass) {
    Node node = new Node("PhysicsNode");
    RigidBodyControl control = new RigidBodyControl(shape, mass);
    node.addControl(control);
    return node;
}
Also used : Node(com.jme3.scene.Node) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 27 with RigidBodyControl

use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.

the class PhysicsTestHelper method createPhysicsTestWorld.

/**
     * creates a simple physics test world with a floor, an obstacle and some test boxes
     * @param rootNode
     * @param assetManager
     * @param space
     */
public static void createPhysicsTestWorld(Node rootNode, AssetManager assetManager, PhysicsSpace space) {
    AmbientLight light = new AmbientLight();
    light.setColor(ColorRGBA.LightGray);
    rootNode.addLight(light);
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Box floorBox = new Box(140, 0.25f, 140);
    Geometry floorGeometry = new Geometry("Floor", floorBox);
    floorGeometry.setMaterial(material);
    floorGeometry.setLocalTranslation(0, -5, 0);
    //        Plane plane = new Plane();
    //        plane.setOriginNormal(new Vector3f(0, 0.25f, 0), Vector3f.UNIT_Y);
    //        floorGeometry.addControl(new RigidBodyControl(new PlaneCollisionShape(plane), 0));
    floorGeometry.addControl(new RigidBodyControl(0));
    rootNode.attachChild(floorGeometry);
    space.add(floorGeometry);
    //movable boxes
    for (int i = 0; i < 12; i++) {
        Box box = new Box(0.25f, 0.25f, 0.25f);
        Geometry boxGeometry = new Geometry("Box", box);
        boxGeometry.setMaterial(material);
        boxGeometry.setLocalTranslation(i, 5, -3);
        //RigidBodyControl automatically uses box collision shapes when attached to single geometry with box mesh
        boxGeometry.addControl(new RigidBodyControl(2));
        rootNode.attachChild(boxGeometry);
        space.add(boxGeometry);
    }
    //immovable sphere with mesh collision shape
    Sphere sphere = new Sphere(8, 8, 1);
    Geometry sphereGeometry = new Geometry("Sphere", sphere);
    sphereGeometry.setMaterial(material);
    sphereGeometry.setLocalTranslation(4, -4, 2);
    sphereGeometry.addControl(new RigidBodyControl(new MeshCollisionShape(sphere), 0));
    rootNode.attachChild(sphereGeometry);
    space.add(sphereGeometry);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) MeshCollisionShape(com.jme3.bullet.collision.shapes.MeshCollisionShape) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) AmbientLight(com.jme3.light.AmbientLight)

Example 28 with RigidBodyControl

use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.

the class TestAttachDriver method setupFloor.

public void setupFloor() {
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);
    Box floor = new Box(100, 1f, 100);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setLocalTranslation(new Vector3f(0f, -3, 0f));
    floorGeom.addControl(new RigidBodyControl(new MeshCollisionShape(floorGeom.getMesh()), 0));
    rootNode.attachChild(floorGeom);
    getPhysicsSpace().add(floorGeom);
}
Also used : Geometry(com.jme3.scene.Geometry) MeshCollisionShape(com.jme3.bullet.collision.shapes.MeshCollisionShape) TextureKey(com.jme3.asset.TextureKey) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) Texture(com.jme3.texture.Texture) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 29 with RigidBodyControl

use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.

the class TestAttachDriver 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, 800);
    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);
    //driver
    Node driverNode = new Node("driverNode");
    driverNode.setLocalTranslation(0, 2, 0);
    driver = new RigidBodyControl(new BoxCollisionShape(new Vector3f(0.2f, .5f, 0.2f)));
    driverNode.addControl(driver);
    rootNode.attachChild(driverNode);
    getPhysicsSpace().add(driver);
    //joint
    slider = new SliderJoint(driver, vehicle, Vector3f.UNIT_Y.negate(), Vector3f.UNIT_Y, true);
    slider.setUpperLinLimit(.1f);
    slider.setLowerLinLimit(-.1f);
    getPhysicsSpace().add(slider);
    Node pole1Node = new Node("pole1Node");
    Node pole2Node = new Node("pole1Node");
    Node bridgeNode = new Node("pole1Node");
    pole1Node.setLocalTranslation(new Vector3f(-2, -1, 4));
    pole2Node.setLocalTranslation(new Vector3f(2, -1, 4));
    bridgeNode.setLocalTranslation(new Vector3f(0, 1.4f, 4));
    RigidBodyControl pole1 = new RigidBodyControl(new BoxCollisionShape(new Vector3f(0.2f, 1.25f, 0.2f)), 0);
    pole1Node.addControl(pole1);
    RigidBodyControl pole2 = new RigidBodyControl(new BoxCollisionShape(new Vector3f(0.2f, 1.25f, 0.2f)), 0);
    pole2Node.addControl(pole2);
    bridge = new RigidBodyControl(new BoxCollisionShape(new Vector3f(2.5f, 0.2f, 0.2f)));
    bridgeNode.addControl(bridge);
    rootNode.attachChild(pole1Node);
    rootNode.attachChild(pole2Node);
    rootNode.attachChild(bridgeNode);
    getPhysicsSpace().add(pole1);
    getPhysicsSpace().add(pole2);
    getPhysicsSpace().add(bridge);
}
Also used : Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) CompoundCollisionShape(com.jme3.bullet.collision.shapes.CompoundCollisionShape) SliderJoint(com.jme3.bullet.joints.SliderJoint) Node(com.jme3.scene.Node) VehicleControl(com.jme3.bullet.control.VehicleControl) Material(com.jme3.material.Material) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 30 with RigidBodyControl

use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.

the class TestBrickTower method addBrick.

public void addBrick(Vector3f ori) {
    Geometry reBoxg = new Geometry("brick", brick);
    reBoxg.setMaterial(mat);
    reBoxg.setLocalTranslation(ori);
    reBoxg.rotate(0f, (float) Math.toRadians(angle), 0f);
    reBoxg.addControl(new RigidBodyControl(1.5f));
    reBoxg.setShadowMode(ShadowMode.CastAndReceive);
    reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f);
    this.rootNode.attachChild(reBoxg);
    this.getPhysicsSpace().add(reBoxg);
}
Also used : Geometry(com.jme3.scene.Geometry) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Aggregations

RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)42 Geometry (com.jme3.scene.Geometry)25 Material (com.jme3.material.Material)19 Vector3f (com.jme3.math.Vector3f)14 BulletAppState (com.jme3.bullet.BulletAppState)12 Node (com.jme3.scene.Node)11 Box (com.jme3.scene.shape.Box)11 Texture (com.jme3.texture.Texture)10 Sphere (com.jme3.scene.shape.Sphere)9 CapsuleCollisionShape (com.jme3.bullet.collision.shapes.CapsuleCollisionShape)8 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)8 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)8 ColorRGBA (com.jme3.math.ColorRGBA)7 CharacterControl (com.jme3.bullet.control.CharacterControl)6 BoxCollisionShape (com.jme3.bullet.collision.shapes.BoxCollisionShape)5 MeshCollisionShape (com.jme3.bullet.collision.shapes.MeshCollisionShape)5 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)5 DirectionalLight (com.jme3.light.DirectionalLight)5 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)5 ScreenshotAppState (com.jme3.app.state.ScreenshotAppState)4