com.jme3.bullet.control.VehicleControl Java Examples

The following examples show how to use com.jme3.bullet.control.VehicleControl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WheelElementModelPropertyControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Check a spatial to have a edited wheel.
 *
 * @param spatial the spatial.
 * @return true if the spatial has this wheel.
 */
private boolean checkSpatial(@NotNull Spatial spatial) {

    var control = spatial.getControl(VehicleControl.class);
    if (control == null) {
        return false;
    }

    var numWheels = control.getNumWheels();

    for (var i = 0; i < numWheels; i++) {
        var wheel = control.getWheel(i);
        if (wheel == getEditObject()) {
            return true;
        }
    }

    return false;
}
 
Example #2
Source File: SceneToolController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void attachPhysicsSelection(Spatial geom) {
    PhysicsCollisionObject control = geom.getControl(RigidBodyControl.class);
    if (control == null) {
        control = geom.getControl(VehicleControl.class);
    }
    if (control == null) {
        control = geom.getControl(GhostControl.class);
    }
    if (control == null) {
        control = geom.getControl(CharacterControl.class);
    }
    if (control == null) {
        return;
    }
    Spatial selectionGeometry = DebugShapeFactory.getDebugShape(control.getCollisionShape());
    if (selectionGeometry != null) {
        selectionGeometry.setMaterial(blueMat);
        selectionGeometry.setLocalTransform(geom.getWorldTransform());
        toolsNode.attachChild(selectionGeometry);
        selectionShape = selectionGeometry;
    }
}
 
Example #3
Source File: CreateVehicleWheelAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
private void handleResult(@NotNull final VarTable vars) {

        final TreeNode<?> node = getNode();
        final VehicleControl control = (VehicleControl) node.getElement();

        final Vector3f location = vars.get(PROPERTY_LOCATION);
        final Vector3f direction = vars.get(PROPERTY_DIRECTION);
        final Vector3f axle = vars.get(PROPERTY_AXLE);

        final float restLength = vars.getFloat(PROPERTY_REST_LENGTH);
        final float radius = vars.getFloat(PROPERTY_RADIUS);

        final boolean isFront = vars.getBoolean(PROPERTY_IS_FRONT);

        final NodeTree<?> nodeTree = getNodeTree();
        final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
        changeConsumer.execute(new AddVehicleWheelOperation(control, location, direction, axle, restLength, radius, isFront));
    }
 
Example #4
Source File: VehicleEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean doCheckVehicle(Node rootNode) {
    VehicleControl control = rootNode.getControl(VehicleControl.class);
    if (control == null) {
        vehicleControl = new VehicleControl(new BoxCollisionShape(Vector3f.UNIT_XYZ), 200);
        vehicleControl.createDebugShape(SceneApplication.getApplication().getAssetManager());
        rootNode.addControl(vehicleControl);
        return true;
    } else {
        vehicleControl = control;
        vehicleControl.createDebugShape(SceneApplication.getApplication().getAssetManager());
        return false;
    }
}
 
Example #5
Source File: JmeVehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public JmeVehicleWheel(VehicleControl vehicle, VehicleWheel wheel) {
    super(Children.LEAF);
    this.vehicle=vehicle;
    this.wheel = wheel;
    getLookupContents().add(wheel);
    getLookupContents().add(this);
    setName("Wheel");
}
 
Example #6
Source File: JmeVehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Sheet createSheet() {
    Sheet sheet = super.createSheet();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("VehicleControl");
    set.setName(VehicleControl.class.getName());
    VehicleControl obj = vehicle;//getLookup().lookup(Spatial.class);
    if (obj == null) {
        return sheet;
    }

    set.put(makeProperty(obj, Vector3f.class, "getPhysicsLocation", "setPhysicsLocation", "Physics Location"));
    set.put(makeProperty(obj, Quaternion.class, "getPhysicsRotation", "setPhysicsRotation", "Physics Rotation"));

    set.put(makeProperty(obj, CollisionShape.class, "getCollisionShape", "setCollisionShape", "Collision Shape"));
    set.put(makeProperty(obj, int.class, "getCollisionGroup", "setCollisionGroup", "Collision Group"));
    set.put(makeProperty(obj, int.class, "getCollideWithGroups", "setCollideWithGroups", "Collide With Groups"));

    set.put(makeProperty(obj, float.class, "getFriction", "setFriction", "Friction"));
    set.put(makeProperty(obj, float.class, "getMass", "setMass", "Mass"));
    set.put(makeProperty(obj, boolean.class, "isKinematic", "setKinematic", "Kinematic"));
    set.put(makeProperty(obj, Vector3f.class, "getGravity", "setGravity", "Gravity"));
    set.put(makeProperty(obj, float.class, "getLinearDamping", "setLinearDamping", "Linear Damping"));
    set.put(makeProperty(obj, float.class, "getAngularDamping", "setAngularDamping", "Angular Damping"));
    set.put(makeProperty(obj, float.class, "getRestitution", "setRestitution", "Restitution"));

    set.put(makeProperty(obj, float.class, "getLinearSleepingThreshold", "setLinearSleepingThreshold", "Linear Sleeping Threshold"));
    set.put(makeProperty(obj, float.class, "getAngularSleepingThreshold", "setAngularSleepingThreshold", "Angular Sleeping Threshold"));

    set.put(makeProperty(obj, float.class, "getFrictionSlip", "setFrictionSlip", "Friction Slip"));
    set.put(makeProperty(obj, float.class, "getMaxSuspensionTravelCm", "setMaxSuspensionTravelCm", "Max Suspension Travel Cm"));
    set.put(makeProperty(obj, float.class, "getMaxSuspensionForce", "setMaxSuspensionForce", "Max Suspension Force"));
    set.put(makeProperty(obj, float.class, "getSuspensionCompression", "setSuspensionCompression", "Suspension Compression"));
    set.put(makeProperty(obj, float.class, "getSuspensionDamping", "setSuspensionDamping", "Suspension Damping"));
    set.put(makeProperty(obj, float.class, "getSuspensionStiffness", "setSuspensionStiffness", "Suspension Stiffness"));

    sheet.put(set);
    return sheet;

}
 
Example #7
Source File: JmeVehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public JmeVehicleControl(VehicleControl vehicle, Children children) {
    super(children);
    getLookupContents().add(vehicle);
    getLookupContents().add(this);
    this.vehicle = vehicle;
    setName("VehicleControl");
}
 
Example #8
Source File: VehicleEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void doApplyWheelData(VehicleControl control, int wheels, SuspensionSettings settings) {
        for (int i = 0; i < control.getNumWheels(); i++) {
            VehicleWheel wheel = control.getWheel(i);
            switch (wheels) {
                case 0:
                    break;
                case 1:
                    if (!wheel.isFrontWheel()) {
                        continue;
                    }
                    break;
                case 2:
                    if (wheel.isFrontWheel()) {
                        continue;
                    }
                    break;
            }
            wheel.setRestLength(settings.getRestLength());
            wheel.setMaxSuspensionForce(settings.getMaxForce());
            wheel.setSuspensionStiffness(settings.getStiffness());
            wheel.setRollInfluence(settings.getRollInfluence());
            wheel.setWheelsDampingCompression(settings.getCompression());
            wheel.setWheelsDampingRelaxation(settings.getRelease());
//            wheel.setRadius(settings.getRadius());
            wheel.setFrictionSlip(settings.getFriction());
        }
    }
 
Example #9
Source File: VehicleEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void doCreateHullShapeFromSelected(VehicleControl control, Spatial spat) {
//        Logger.getLogger(VehicleEditorController.class.getName()).log(Level.INFO, "Merging Geometries");
//        Mesh mesh = new Mesh();
//        GeometryBatchFactory.mergeGeometries(list, mesh);
//        control.setCollisionShape(new HullCollisionShape(list.get(0).getMesh()));
        control.setCollisionShape(CollisionShapeFactory.createDynamicMeshShape(spat));
        refreshSelected();
    }
 
Example #10
Source File: RemoveVehicleWheelOperation.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
public RemoveVehicleWheelOperation(@NotNull final VehicleControl control, @NotNull final VehicleWheel wheel) {
    this.control = control;
    this.connectionPoint = wheel.getLocation();
    this.direction = wheel.getDirection();
    this.axle = wheel.getAxle();
    this.restLength = wheel.getRestLength();
    this.wheelRadius = wheel.getRadius();
    this.isFrontWheel = wheel.isFrontWheel();
    this.createdWheel = wheel;
}
 
Example #11
Source File: RemoveVehicleWheelAction.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected void process() {

    final TreeNode<?> node = getNode();
    final Object element = node.getElement();
    final TreeNode<?> nodeParent = notNull(node.getParent());
    final VehicleControl vehicleControl = (VehicleControl) nodeParent.getElement();
    final VehicleWheel vehicleWheel = (VehicleWheel) element;

    final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
    final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
    changeConsumer.execute(new RemoveVehicleWheelOperation(vehicleControl, vehicleWheel));
}
 
Example #12
Source File: AddVehicleWheelOperation.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new Add vehicle wheel operation.
 *
 * @param control         the control
 * @param connectionPoint the connection point
 * @param direction       the direction
 * @param axle            the axle
 * @param restLength      the rest length
 * @param wheelRadius     the wheel radius
 * @param isFrontWheel    the is front wheel
 */
public AddVehicleWheelOperation(@NotNull final VehicleControl control, @NotNull final Vector3f connectionPoint,
                                @NotNull final Vector3f direction, @NotNull final Vector3f axle,
                                final float restLength, final float wheelRadius, final boolean isFrontWheel) {
    this.control = control;
    this.connectionPoint = connectionPoint;
    this.direction = direction;
    this.axle = axle;
    this.restLength = restLength;
    this.wheelRadius = wheelRadius;
    this.isFrontWheel = isFrontWheel;
}
 
Example #13
Source File: TestPhysicsCar.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
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, 400);
    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
    float stiffness = 60.0f;//200=f1 car
    float compValue = .3f; //(should be lower than damp)
    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
    Vector3f wheelDirection = new Vector3f(0, -1, 0); // was 0, -1, 0
    Vector3f wheelAxle = new Vector3f(-1, 0, 0); // was -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);
}
 
Example #14
Source File: TestPhysicsCar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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, 400);
    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
    float stiffness = 60.0f;//200=f1 car
    float compValue = .3f; //(should be lower than damp)
    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
    Vector3f wheelDirection = new Vector3f(0, -1, 0); // was 0, -1, 0
    Vector3f wheelAxle = new Vector3f(-1, 0, 0); // was -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);
}
 
Example #15
Source File: CreateVehicleControlAction.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@FxThread
protected @NotNull Control createControl(@NotNull final Spatial parent) {
    return new VehicleControl(new BoxCollisionShape(new Vector3f(1F, 1F, 1F)), 1F);
}
 
Example #16
Source File: VehicleControlTreeNode.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
public VehicleControlTreeNode(@NotNull final VehicleControl element, final long objectId) {
    super(element, objectId);
}
 
Example #17
Source File: JmeVehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Class getExplorerObjectClass() {
    return VehicleControl.class;
}
 
Example #18
Source File: JmeVehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public org.openide.nodes.Node[] createNodes(Object key, DataObject key2, boolean cookie) {
    PhysicsVehicleChildren children = new PhysicsVehicleChildren((VehicleControl) key);
    children.setReadOnly(cookie);
    children.setDataObject(key2);
    return new org.openide.nodes.Node[]{new JmeVehicleControl((VehicleControl) key, children).setReadOnly(cookie)};
}
 
Example #19
Source File: JmeVehicleControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public PhysicsVehicleChildren(VehicleControl control) {
    this.control = control;
}