159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/*
259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2010 jMonkeyEngine
359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved.
459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without
659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are
759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met:
859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright
1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer.
1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright
1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer in the
1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   documentation and/or other materials provided with the distribution.
1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   may be used to endorse or promote products derived from this software
1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   without specific prior written permission.
1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */
3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage jme3test.bullet;
3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.app.SimpleApplication;
3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.asset.TextureKey;
3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.BulletAppState;
3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.PhysicsSpace;
3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.collision.shapes.BoxCollisionShape;
4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.collision.shapes.CompoundCollisionShape;
4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.collision.shapes.MeshCollisionShape;
4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.control.RigidBodyControl;
4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.control.VehicleControl;
4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.joints.SliderJoint;
4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.KeyInput;
4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.ActionListener;
4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.KeyTrigger;
4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.material.Material;
4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.*;
5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.Geometry;
5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.Node;
5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.shape.Box;
5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.shape.Cylinder;
5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.texture.Texture;
5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/**
5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Tests attaching/detaching nodes via joints
5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author normenhansen
5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */
6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class TestAttachDriver extends SimpleApplication implements ActionListener {
6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private VehicleControl vehicle;
6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private RigidBodyControl driver;
6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private RigidBodyControl bridge;
6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private SliderJoint slider;
6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private final float accelerationForce = 1000.0f;
6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private final float brakeForce = 100.0f;
6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private float steeringValue = 0;
6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private float accelerationValue = 0;
7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private Vector3f jumpForce = new Vector3f(0, 3000, 0);
7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private BulletAppState bulletAppState;
7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static void main(String[] args) {
7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        TestAttachDriver app = new TestAttachDriver();
7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        app.start();
7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    @Override
7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void simpleInitApp() {
8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        bulletAppState = new BulletAppState();
8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        stateManager.attach(bulletAppState);
8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        setupKeys();
8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        setupFloor();
8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        buildPlayer();
8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private PhysicsSpace getPhysicsSpace(){
8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return bulletAppState.getPhysicsSpace();
9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void setupKeys() {
9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_H));
9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_K));
9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_U));
9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_J));
9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("Space", new KeyTrigger(KeyInput.KEY_SPACE));
9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("Reset", new KeyTrigger(KeyInput.KEY_RETURN));
9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(this, "Lefts");
10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(this, "Rights");
10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(this, "Ups");
10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(this, "Downs");
10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(this, "Space");
10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(this, "Reset");
10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void setupFloor() {
10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        key.setGenerateMips(true);
11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Texture tex = assetManager.loadTexture(key);
11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        tex.setMinFilter(Texture.MinFilter.Trilinear);
11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setTexture("ColorMap", tex);
11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Box floor = new Box(Vector3f.ZERO, 100, 1f, 100);
11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Geometry floorGeom = new Geometry("Floor", floor);
11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        floorGeom.setMaterial(mat);
11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        floorGeom.setLocalTranslation(new Vector3f(0f, -3, 0f));
11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        floorGeom.addControl(new RigidBodyControl(new MeshCollisionShape(floorGeom.getMesh()), 0));
12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rootNode.attachChild(floorGeom);
12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        getPhysicsSpace().add(floorGeom);
12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void buildPlayer() {
12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.getAdditionalRenderState().setWireframe(true);
12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        mat.setColor("Color", ColorRGBA.Red);
12959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
13059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        //create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0
13159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        //this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0
13259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        CompoundCollisionShape compoundShape = new CompoundCollisionShape();
13359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        BoxCollisionShape box = new BoxCollisionShape(new Vector3f(1.2f, 0.5f, 2.4f));
13459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        compoundShape.addChildShape(box, new Vector3f(0, 1, 0));
13559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
13659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        //create vehicle node
13759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Node vehicleNode=new Node("vehicleNode");
13859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicle = new VehicleControl(compoundShape, 800);
13959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicleNode.addControl(vehicle);
14059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
14159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        //setting suspension values for wheels, this can be a bit tricky
14259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        //see also https://docs.google.com/Doc?docid=0AXVUZ5xw6XpKZGNuZG56a3FfMzU0Z2NyZnF4Zmo&hl=en
14359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        float stiffness = 60.0f;//200=f1 car
14459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        float compValue = .3f; //(should be lower than damp)
14559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        float dampValue = .4f;
14659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicle.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
14759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicle.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
14859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicle.setSuspensionStiffness(stiffness);
14959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicle.setMaxSuspensionForce(10000.0f);
15059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
15159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        //Create four wheels and add them at their locations
15259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Vector3f wheelDirection = new Vector3f(0, -1, 0); // was 0, -1, 0
15359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Vector3f wheelAxle = new Vector3f(-1, 0, 0); // was -1, 0, 0
15459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        float radius = 0.5f;
15559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        float restLength = 0.3f;
15659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        float yOff = 0.5f;
15759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        float xOff = 1f;
15859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        float zOff = 2f;
15959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
16059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Cylinder wheelMesh = new Cylinder(16, 16, radius, radius * 0.6f, true);
16159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
16259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Node node1 = new Node("wheel 1 node");
16359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Geometry wheels1 = new Geometry("wheel 1", wheelMesh);
16459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        node1.attachChild(wheels1);
16559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        wheels1.rotate(0, FastMath.HALF_PI, 0);
16659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        wheels1.setMaterial(mat);
16759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicle.addWheel(node1, new Vector3f(-xOff, yOff, zOff),
16859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                wheelDirection, wheelAxle, restLength, radius, true);
16959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
17059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Node node2 = new Node("wheel 2 node");
17159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Geometry wheels2 = new Geometry("wheel 2", wheelMesh);
17259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        node2.attachChild(wheels2);
17359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        wheels2.rotate(0, FastMath.HALF_PI, 0);
17459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        wheels2.setMaterial(mat);
17559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicle.addWheel(node2, new Vector3f(xOff, yOff, zOff),
17659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                wheelDirection, wheelAxle, restLength, radius, true);
17759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
17859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Node node3 = new Node("wheel 3 node");
17959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Geometry wheels3 = new Geometry("wheel 3", wheelMesh);
18059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        node3.attachChild(wheels3);
18159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        wheels3.rotate(0, FastMath.HALF_PI, 0);
18259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        wheels3.setMaterial(mat);
18359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicle.addWheel(node3, new Vector3f(-xOff, yOff, -zOff),
18459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                wheelDirection, wheelAxle, restLength, radius, false);
18559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
18659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Node node4 = new Node("wheel 4 node");
18759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Geometry wheels4 = new Geometry("wheel 4", wheelMesh);
18859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        node4.attachChild(wheels4);
18959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        wheels4.rotate(0, FastMath.HALF_PI, 0);
19059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        wheels4.setMaterial(mat);
19159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicle.addWheel(node4, new Vector3f(xOff, yOff, -zOff),
19259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                wheelDirection, wheelAxle, restLength, radius, false);
19359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
19459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicleNode.attachChild(node1);
19559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicleNode.attachChild(node2);
19659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicleNode.attachChild(node3);
19759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        vehicleNode.attachChild(node4);
19859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
19959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rootNode.attachChild(vehicleNode);
20059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        getPhysicsSpace().add(vehicle);
20159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
20259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        //driver
20359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Node driverNode=new Node("driverNode");
20459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        driverNode.setLocalTranslation(0,2,0);
20559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        driver=new RigidBodyControl(new BoxCollisionShape(new Vector3f(0.2f,.5f,0.2f)));
20659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        driverNode.addControl(driver);
20759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
20859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rootNode.attachChild(driverNode);
20959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        getPhysicsSpace().add(driver);
21059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
21159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        //joint
21259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        slider=new SliderJoint(driver, vehicle, Vector3f.UNIT_Y.negate(), Vector3f.UNIT_Y, true);
21359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        slider.setUpperLinLimit(.1f);
21459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        slider.setLowerLinLimit(-.1f);
21559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
21659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        getPhysicsSpace().add(slider);
21759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
21859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Node pole1Node=new Node("pole1Node");
21959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Node pole2Node=new Node("pole1Node");
22059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Node bridgeNode=new Node("pole1Node");
22159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        pole1Node.setLocalTranslation(new Vector3f(-2,-1,4));
22259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        pole2Node.setLocalTranslation(new Vector3f(2,-1,4));
22359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        bridgeNode.setLocalTranslation(new Vector3f(0,1.4f,4));
22459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
22559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        RigidBodyControl pole1=new RigidBodyControl(new BoxCollisionShape(new Vector3f(0.2f,1.25f,0.2f)),0);
22659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        pole1Node.addControl(pole1);
22759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        RigidBodyControl pole2=new RigidBodyControl(new BoxCollisionShape(new Vector3f(0.2f,1.25f,0.2f)),0);
22859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        pole2Node.addControl(pole2);
22959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        bridge=new RigidBodyControl(new BoxCollisionShape(new Vector3f(2.5f,0.2f,0.2f)));
23059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        bridgeNode.addControl(bridge);
23159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
23259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rootNode.attachChild(pole1Node);
23359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rootNode.attachChild(pole2Node);
23459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rootNode.attachChild(bridgeNode);
23559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        getPhysicsSpace().add(pole1);
23659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        getPhysicsSpace().add(pole2);
23759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        getPhysicsSpace().add(bridge);
23859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
23959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
24059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
24159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    @Override
24259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void simpleUpdate(float tpf) {
24359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Quaternion quat=new Quaternion();
24459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        cam.lookAt(vehicle.getPhysicsLocation(), Vector3f.UNIT_Y);
24559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
24659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
24759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void onAction(String binding, boolean value, float tpf) {
24859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        if (binding.equals("Lefts")) {
24959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            if (value) {
25059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                steeringValue += .5f;
25159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            } else {
25259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                steeringValue += -.5f;
25359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
25459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            vehicle.steer(steeringValue);
25559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        } else if (binding.equals("Rights")) {
25659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            if (value) {
25759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                steeringValue += -.5f;
25859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            } else {
25959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                steeringValue += .5f;
26059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
26159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            vehicle.steer(steeringValue);
26259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        } else if (binding.equals("Ups")) {
26359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            if (value) {
26459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                accelerationValue += accelerationForce;
26559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            } else {
26659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                accelerationValue -= accelerationForce;
26759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
26859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            vehicle.accelerate(accelerationValue);
26959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        } else if (binding.equals("Downs")) {
27059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            if (value) {
27159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                vehicle.brake(brakeForce);
27259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            } else {
27359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                vehicle.brake(0f);
27459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
27559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        } else if (binding.equals("Space")) {
27659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            if (value) {
27759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                getPhysicsSpace().remove(slider);
27859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                slider.destroy();
27959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                vehicle.applyImpulse(jumpForce, Vector3f.ZERO);
28059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
28159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        } else if (binding.equals("Reset")) {
28259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            if (value) {
28359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                System.out.println("Reset");
28459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                vehicle.setPhysicsLocation(new Vector3f(0, 0, 0));
28559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                vehicle.setPhysicsRotation(new Matrix3f());
28659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                vehicle.setLinearVelocity(Vector3f.ZERO);
28759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                vehicle.setAngularVelocity(Vector3f.ZERO);
28859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                vehicle.resetSuspension();
28959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                bridge.setPhysicsLocation(new Vector3f(0,1.4f,4));
29059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                bridge.setPhysicsRotation(Quaternion.DIRECTION_Z.toRotationMatrix());
29159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
29259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
29359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
29459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta}
295