Search in sources :

Example 11 with RigidBodyControl

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

the class TestBoneRagdoll method simpleInitApp.

public void simpleInitApp() {
    initCrossHairs();
    initMaterial();
    cam.setLocation(new Vector3f(0.26924422f, 6.646658f, 22.265987f));
    cam.setRotation(new Quaternion(-2.302544E-4f, 0.99302495f, -0.117888905f, -0.0019395084f));
    bulletAppState = new BulletAppState();
    bulletAppState.setEnabled(true);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 1.0f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(1.0f);
    //        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    setupLight();
    model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
    //  model.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
    //debug view
    AnimControl control = model.getControl(AnimControl.class);
    SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.getSkeleton());
    Material mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.getAdditionalRenderState().setWireframe(true);
    mat2.setColor("Color", ColorRGBA.Green);
    mat2.getAdditionalRenderState().setDepthTest(false);
    skeletonDebug.setMaterial(mat2);
    skeletonDebug.setLocalTranslation(model.getLocalTranslation());
    //Note: PhysicsRagdollControl is still TODO, constructor will change
    ragdoll = new KinematicRagdollControl(0.5f);
    setupSinbad(ragdoll);
    ragdoll.addCollisionListener(this);
    model.addControl(ragdoll);
    float eighth_pi = FastMath.PI * 0.125f;
    ragdoll.setJointLimit("Waist", eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi, eighth_pi);
    ragdoll.setJointLimit("Chest", eighth_pi, eighth_pi, 0, 0, eighth_pi, eighth_pi);
    //Oto's head is almost rigid
    //    ragdoll.setJointLimit("head", 0, 0, eighth_pi, -eighth_pi, 0, 0);
    getPhysicsSpace().add(ragdoll);
    speed = 1.3f;
    rootNode.attachChild(model);
    // rootNode.attachChild(skeletonDebug);
    flyCam.setMoveSpeed(50);
    animChannel = control.createChannel();
    animChannel.setAnim("Dance");
    control.addListener(this);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("toggle") && isPressed) {
                Vector3f v = new Vector3f();
                v.set(model.getLocalTranslation());
                v.y = 0;
                model.setLocalTranslation(v);
                Quaternion q = new Quaternion();
                float[] angles = new float[3];
                model.getLocalRotation().toAngles(angles);
                q.fromAngleAxis(angles[1], Vector3f.UNIT_Y);
                model.setLocalRotation(q);
                if (angles[0] < 0) {
                    animChannel.setAnim("StandUpBack");
                    ragdoll.blendToKinematicMode(0.5f);
                } else {
                    animChannel.setAnim("StandUpFront");
                    ragdoll.blendToKinematicMode(0.5f);
                }
            }
            if (name.equals("bullet+") && isPressed) {
                bulletSize += 0.1f;
            }
            if (name.equals("bullet-") && isPressed) {
                bulletSize -= 0.1f;
            }
            if (name.equals("stop") && isPressed) {
                ragdoll.setEnabled(!ragdoll.isEnabled());
                ragdoll.setRagdollMode();
            }
            if (name.equals("shoot") && !isPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(matBullet);
                bulletg.setLocalTranslation(cam.getLocation());
                bulletg.setLocalScale(bulletSize);
                bulletCollisionShape = new SphereCollisionShape(bulletSize);
                RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, bulletSize * 10);
                bulletNode.setCcdMotionThreshold(0.001f);
                bulletNode.setLinearVelocity(cam.getDirection().mult(80));
                bulletg.addControl(bulletNode);
                rootNode.attachChild(bulletg);
                getPhysicsSpace().add(bulletNode);
            }
            if (name.equals("boom") && !isPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(matBullet);
                bulletg.setLocalTranslation(cam.getLocation());
                bulletg.setLocalScale(bulletSize);
                bulletCollisionShape = new SphereCollisionShape(bulletSize);
                BombControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
                bulletNode.setForceFactor(8);
                bulletNode.setExplosionRadius(20);
                bulletNode.setCcdMotionThreshold(0.001f);
                bulletNode.setLinearVelocity(cam.getDirection().mult(180));
                bulletg.addControl(bulletNode);
                rootNode.attachChild(bulletg);
                getPhysicsSpace().add(bulletNode);
            }
        }
    }, "toggle", "shoot", "stop", "bullet+", "bullet-", "boom");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addMapping("boom", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("bullet-", new KeyTrigger(KeyInput.KEY_COMMA));
    inputManager.addMapping("bullet+", new KeyTrigger(KeyInput.KEY_PERIOD));
}
Also used : SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) KinematicRagdollControl(com.jme3.bullet.control.KinematicRagdollControl) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) SkeletonDebugger(com.jme3.scene.debug.SkeletonDebugger) ActionListener(com.jme3.input.controls.ActionListener) Vector3f(com.jme3.math.Vector3f) BulletAppState(com.jme3.bullet.BulletAppState) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Example 12 with RigidBodyControl

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

the class TestBrickTower 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, 0);
    floor.addControl(new RigidBodyControl(0));
    this.rootNode.attachChild(floor);
    this.getPhysicsSpace().add(floor);
}
Also used : Geometry(com.jme3.scene.Geometry) Vector2f(com.jme3.math.Vector2f) Box(com.jme3.scene.shape.Box) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 13 with RigidBodyControl

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

the class TestCcd method onAction.

public void onAction(String binding, boolean value, float tpf) {
    if (binding.equals("shoot") && !value) {
        Geometry bulletg = new Geometry("bullet", bullet);
        bulletg.setMaterial(mat);
        bulletg.setName("bullet");
        bulletg.setLocalTranslation(cam.getLocation());
        bulletg.setShadowMode(ShadowMode.CastAndReceive);
        bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
        bulletg.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f);
        bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
        rootNode.attachChild(bulletg);
        getPhysicsSpace().add(bulletg);
    } else if (binding.equals("shoot2") && !value) {
        Geometry bulletg = new Geometry("bullet", bullet);
        bulletg.setMaterial(mat2);
        bulletg.setName("bullet");
        bulletg.setLocalTranslation(cam.getLocation());
        bulletg.setShadowMode(ShadowMode.CastAndReceive);
        bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
        bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
        rootNode.attachChild(bulletg);
        getPhysicsSpace().add(bulletg);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 14 with RigidBodyControl

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

the class PhysicsTestHelper method createBallShooter.

/**
     * creates the necessary inputlistener and action to shoot balls from teh camera
     * @param app
     * @param rootNode
     * @param space
     */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(10);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) TextureKey(com.jme3.asset.TextureKey) ActionListener(com.jme3.input.controls.ActionListener) Material(com.jme3.material.Material) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) Texture(com.jme3.texture.Texture) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 15 with RigidBodyControl

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

the class TestBetterCharacter method setupPlanet.

private void setupPlanet() {
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    //immovable sphere with mesh collision shape
    Sphere sphere = new Sphere(64, 64, 20);
    planet = new Geometry("Sphere", sphere);
    planet.setMaterial(material);
    planet.setLocalTranslation(30, -15, 30);
    planet.addControl(new RigidBodyControl(new MeshCollisionShape(sphere), 0));
    rootNode.attachChild(planet);
    getPhysicsSpace().add(planet);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) MeshCollisionShape(com.jme3.bullet.collision.shapes.MeshCollisionShape) Material(com.jme3.material.Material) 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