Search in sources :

Example 1 with KinematicRagdollControl

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

the class TestRagdollCharacter method simpleInitApp.

public void simpleInitApp() {
    setupKeys();
    bulletAppState = new BulletAppState();
    bulletAppState.setEnabled(true);
    stateManager.attach(bulletAppState);
    //        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    initWall(2, 1, 1);
    setupLight();
    cam.setLocation(new Vector3f(-8, 0, -4));
    cam.lookAt(new Vector3f(4, 0, -7), Vector3f.UNIT_Y);
    model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
    model.lookAt(new Vector3f(0, 0, -1), Vector3f.UNIT_Y);
    model.setLocalTranslation(4, 0, -7f);
    ragdoll = new KinematicRagdollControl(0.5f);
    model.addControl(ragdoll);
    getPhysicsSpace().add(ragdoll);
    speed = 1.3f;
    rootNode.attachChild(model);
    AnimControl control = model.getControl(AnimControl.class);
    animChannel = control.createChannel();
    animChannel.setAnim("IdleTop");
    control.addListener(this);
}
Also used : BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) KinematicRagdollControl(com.jme3.bullet.control.KinematicRagdollControl) AnimControl(com.jme3.animation.AnimControl)

Example 2 with KinematicRagdollControl

use of com.jme3.bullet.control.KinematicRagdollControl 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 3 with KinematicRagdollControl

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

the class TestIK method simpleInitApp.

@Override
public void simpleInitApp() {
    super.simpleInitApp();
    final KinematicRagdollControl ikControl = model.getControl(KinematicRagdollControl.class);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("stop") && isPressed) {
                ikControl.setEnabled(!ikControl.isEnabled());
                ikControl.setIKMode();
            }
            if (name.equals("one") && isPressed) {
                //ragdoll.setKinematicMode();
                targetPoint = model.getWorldTranslation().add(new Vector3f(0, 2, 4));
                targetNode.setLocalTranslation(targetPoint);
                ikControl.setIKTarget(ikControl.getBone("Hand.L"), targetPoint, 2);
                ikControl.setIKMode();
            }
            if (name.equals("two") && isPressed) {
                //ragdoll.setKinematicMode();
                targetPoint = model.getWorldTranslation().add(new Vector3f(-3, 3, 0));
                targetNode.setLocalTranslation(targetPoint);
                ikControl.setIKTarget(ikControl.getBone("Hand.R"), targetPoint, 3);
                ikControl.setIKMode();
            }
        }
    }, "one", "two");
    inputManager.addMapping("one", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addMapping("two", new KeyTrigger(KeyInput.KEY_2));
    inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H));
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) Vector3f(com.jme3.math.Vector3f) KeyTrigger(com.jme3.input.controls.KeyTrigger) KinematicRagdollControl(com.jme3.bullet.control.KinematicRagdollControl)

Aggregations

KinematicRagdollControl (com.jme3.bullet.control.KinematicRagdollControl)3 Vector3f (com.jme3.math.Vector3f)3 BulletAppState (com.jme3.bullet.BulletAppState)2 ActionListener (com.jme3.input.controls.ActionListener)2 KeyTrigger (com.jme3.input.controls.KeyTrigger)2 AnimControl (com.jme3.animation.AnimControl)1 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)1 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)1 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)1 Material (com.jme3.material.Material)1 Quaternion (com.jme3.math.Quaternion)1 Geometry (com.jme3.scene.Geometry)1 SkeletonDebugger (com.jme3.scene.debug.SkeletonDebugger)1 Sphere (com.jme3.scene.shape.Sphere)1