Search in sources :

Example 1 with VehicleWheel

use of com.jme3.bullet.objects.VehicleWheel in project jmonkeyengine by jMonkeyEngine.

the class VehicleControl method cloneFields.

@Override
public void cloneFields(Cloner cloner, Object original) {
    this.spatial = cloner.clone(spatial);
    for (VehicleWheel wheel : wheels) {
        Spatial spatial = cloner.clone(wheel.getWheelSpatial());
        wheel.setWheelSpatial(spatial);
    }
}
Also used : Spatial(com.jme3.scene.Spatial) VehicleWheel(com.jme3.bullet.objects.VehicleWheel)

Example 2 with VehicleWheel

use of com.jme3.bullet.objects.VehicleWheel in project jmonkeyengine by jMonkeyEngine.

the class VehicleControl method jmeClone.

@Override
public Object jmeClone() {
    VehicleControl control = new VehicleControl(collisionShape, mass);
    control.setAngularFactor(getAngularFactor());
    control.setAngularSleepingThreshold(getAngularSleepingThreshold());
    control.setAngularVelocity(getAngularVelocity());
    control.setCcdMotionThreshold(getCcdMotionThreshold());
    control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
    control.setCollideWithGroups(getCollideWithGroups());
    control.setCollisionGroup(getCollisionGroup());
    control.setDamping(getLinearDamping(), getAngularDamping());
    control.setFriction(getFriction());
    control.setGravity(getGravity());
    control.setKinematic(isKinematic());
    control.setLinearSleepingThreshold(getLinearSleepingThreshold());
    control.setLinearVelocity(getLinearVelocity());
    control.setPhysicsLocation(getPhysicsLocation());
    control.setPhysicsRotation(getPhysicsRotationMatrix());
    control.setRestitution(getRestitution());
    control.setFrictionSlip(getFrictionSlip());
    control.setMaxSuspensionTravelCm(getMaxSuspensionTravelCm());
    control.setSuspensionStiffness(getSuspensionStiffness());
    control.setSuspensionCompression(tuning.suspensionCompression);
    control.setSuspensionDamping(tuning.suspensionDamping);
    control.setMaxSuspensionForce(getMaxSuspensionForce());
    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext(); ) {
        VehicleWheel wheel = it.next();
        VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel());
        newWheel.setFrictionSlip(wheel.getFrictionSlip());
        newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
        newWheel.setSuspensionStiffness(wheel.getSuspensionStiffness());
        newWheel.setWheelsDampingCompression(wheel.getWheelsDampingCompression());
        newWheel.setWheelsDampingRelaxation(wheel.getWheelsDampingRelaxation());
        newWheel.setMaxSuspensionForce(wheel.getMaxSuspensionForce());
        // Copy the wheel spatial reference directly for now.  They'll
        // get fixed up in the cloneFields() method
        newWheel.setWheelSpatial(wheel.getWheelSpatial());
    }
    control.setApplyPhysicsLocal(isApplyPhysicsLocal());
    control.setEnabled(isEnabled());
    control.spatial = spatial;
    return control;
}
Also used : VehicleWheel(com.jme3.bullet.objects.VehicleWheel)

Example 3 with VehicleWheel

use of com.jme3.bullet.objects.VehicleWheel in project jmonkeyengine by jMonkeyEngine.

the class BulletVehicleDebugControl method createVehicle.

private void createVehicle() {
    suspensionNode.detachAllChildren();
    for (int i = 0; i < body.getNumWheels(); i++) {
        VehicleWheel physicsVehicleWheel = body.getWheel(i);
        Vector3f location = physicsVehicleWheel.getLocation().clone();
        Vector3f direction = physicsVehicleWheel.getDirection().clone();
        Vector3f axle = physicsVehicleWheel.getAxle().clone();
        float restLength = physicsVehicleWheel.getRestLength();
        float radius = physicsVehicleWheel.getRadius();
        Arrow locArrow = new Arrow(location);
        Arrow axleArrow = new Arrow(axle.normalizeLocal().multLocal(0.3f));
        Arrow wheelArrow = new Arrow(direction.normalizeLocal().multLocal(radius));
        Arrow dirArrow = new Arrow(direction.normalizeLocal().multLocal(restLength));
        Geometry locGeom = new Geometry("WheelLocationDebugShape" + i, locArrow);
        Geometry dirGeom = new Geometry("WheelDirectionDebugShape" + i, dirArrow);
        Geometry axleGeom = new Geometry("WheelAxleDebugShape" + i, axleArrow);
        Geometry wheelGeom = new Geometry("WheelRadiusDebugShape" + i, wheelArrow);
        dirGeom.setLocalTranslation(location);
        axleGeom.setLocalTranslation(location.add(direction));
        wheelGeom.setLocalTranslation(location.add(direction));
        locGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        dirGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        axleGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        wheelGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        suspensionNode.attachChild(locGeom);
        suspensionNode.attachChild(dirGeom);
        suspensionNode.attachChild(axleGeom);
        suspensionNode.attachChild(wheelGeom);
    }
}
Also used : Arrow(com.jme3.scene.debug.Arrow) Geometry(com.jme3.scene.Geometry) VehicleWheel(com.jme3.bullet.objects.VehicleWheel) Vector3f(com.jme3.math.Vector3f)

Example 4 with VehicleWheel

use of com.jme3.bullet.objects.VehicleWheel in project jmonkeyengine by jMonkeyEngine.

the class PhysicsVehicle method read.

@Override
public void read(JmeImporter im) throws IOException {
    InputCapsule capsule = im.getCapsule(this);
    tuning = new VehicleTuning();
    tuning.frictionSlip = capsule.readFloat("frictionSlip", 10.5f);
    tuning.maxSuspensionTravelCm = capsule.readFloat("maxSuspensionTravelCm", 500f);
    tuning.maxSuspensionForce = capsule.readFloat("maxSuspensionForce", 6000f);
    tuning.suspensionCompression = capsule.readFloat("suspensionCompression", 0.83f);
    tuning.suspensionDamping = capsule.readFloat("suspensionDamping", 0.88f);
    tuning.suspensionStiffness = capsule.readFloat("suspensionStiffness", 5.88f);
    wheels = capsule.readSavableArrayList("wheelsList", new ArrayList<VehicleWheel>());
    motionState.setVehicle(this);
    super.read(im);
}
Also used : InputCapsule(com.jme3.export.InputCapsule) ArrayList(java.util.ArrayList)

Example 5 with VehicleWheel

use of com.jme3.bullet.objects.VehicleWheel in project jmonkeyengine by jMonkeyEngine.

the class VehicleControl method setApplyPhysicsLocal.

/**
     * When set to true, the physics coordinates will be applied to the local
     * translation of the Spatial
     * @param applyPhysicsLocal
     */
public void setApplyPhysicsLocal(boolean applyPhysicsLocal) {
    motionState.setApplyPhysicsLocal(applyPhysicsLocal);
    for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext(); ) {
        VehicleWheel vehicleWheel = it.next();
        vehicleWheel.setApplyLocal(applyPhysicsLocal);
    }
}
Also used : VehicleWheel(com.jme3.bullet.objects.VehicleWheel)

Aggregations

VehicleWheel (com.jme3.bullet.objects.VehicleWheel)6 Vector3f (com.jme3.math.Vector3f)2 Geometry (com.jme3.scene.Geometry)2 Spatial (com.jme3.scene.Spatial)2 Arrow (com.jme3.scene.debug.Arrow)2 InputCapsule (com.jme3.export.InputCapsule)1 OutputCapsule (com.jme3.export.OutputCapsule)1 Node (com.jme3.scene.Node)1 ArrayList (java.util.ArrayList)1