Search in sources :

Example 31 with RigidBodyControl

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

the class TestBrickWall method initFloor.

public void initFloor() {
    Box floorBox = new Box(10f, 0.1f, 5f);
    floorBox.scaleTextureCoordinates(new Vector2f(3, 6));
    Geometry floor = new Geometry("floor", floorBox);
    floor.setMaterial(mat3);
    floor.setShadowMode(ShadowMode.Receive);
    floor.setLocalTranslation(0, -0.1f, 0);
    floor.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(10f, 0.1f, 5f)), 0));
    this.rootNode.attachChild(floor);
    this.getPhysicsSpace().add(floor);
}
Also used : Geometry(com.jme3.scene.Geometry) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 32 with RigidBodyControl

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

the class TestBrickWall method addBrick.

public void addBrick(Vector3f ori) {
    Geometry reBoxg = new Geometry("brick", brick);
    reBoxg.setMaterial(mat);
    reBoxg.setLocalTranslation(ori);
    //for geometry with sphere mesh the physics system automatically uses a sphere collision shape
    reBoxg.addControl(new RigidBodyControl(1.5f));
    reBoxg.setShadowMode(ShadowMode.CastAndReceive);
    reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f);
    this.rootNode.attachChild(reBoxg);
    this.getPhysicsSpace().add(reBoxg);
}
Also used : Geometry(com.jme3.scene.Geometry) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 33 with RigidBodyControl

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

the class TestCcd method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.1f);
    setupKeys();
    mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.getAdditionalRenderState().setWireframe(true);
    mat.setColor("Color", ColorRGBA.Green);
    mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.getAdditionalRenderState().setWireframe(true);
    mat2.setColor("Color", ColorRGBA.Red);
    // An obstacle mesh, does not move (mass=0)
    Node node2 = new Node();
    node2.setName("mesh");
    node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
    node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(4, 4, 0.1f)), 0));
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);
    // The floor, does not move (mass=0)
    Node node3 = new Node();
    node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
    node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) MeshCollisionShape(com.jme3.bullet.collision.shapes.MeshCollisionShape) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) BulletAppState(com.jme3.bullet.BulletAppState) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 34 with RigidBodyControl

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

the class TestCollisionShapeFactory method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    createMaterial();
    Node node = new Node("node1");
    attachRandomGeometry(node, mat1);
    randomizeTransform(node);
    Node node2 = new Node("node2");
    attachRandomGeometry(node2, mat2);
    randomizeTransform(node2);
    node.attachChild(node2);
    rootNode.attachChild(node);
    RigidBodyControl control = new RigidBodyControl(0);
    node.addControl(control);
    getPhysicsSpace().add(control);
    //test single geometry too
    Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1));
    myGeom.setMaterial(mat3);
    randomizeTransform(myGeom);
    rootNode.attachChild(myGeom);
    RigidBodyControl control3 = new RigidBodyControl(0);
    myGeom.addControl(control3);
    getPhysicsSpace().add(control3);
}
Also used : Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) BulletAppState(com.jme3.bullet.BulletAppState) Node(com.jme3.scene.Node) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 35 with RigidBodyControl

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

the class TestWalkingChar method bulletControl.

private void bulletControl() {
    shootingChannel.setAnim("Dodge", 0.1f);
    shootingChannel.setLoopMode(LoopMode.DontLoop);
    Geometry bulletg = new Geometry("bullet", bullet);
    bulletg.setMaterial(matBullet);
    bulletg.setShadowMode(ShadowMode.CastAndReceive);
    bulletg.setLocalTranslation(character.getPhysicsLocation().add(cam.getDirection().mult(5)));
    RigidBodyControl bulletControl = new BombControl(bulletCollisionShape, 1);
    bulletControl.setCcdMotionThreshold(0.1f);
    bulletControl.setLinearVelocity(cam.getDirection().mult(80));
    bulletg.addControl(bulletControl);
    rootNode.attachChild(bulletg);
    getPhysicsSpace().add(bulletControl);
}
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