Search in sources :

Example 6 with VehicleWheel

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

the class VehicleControl method cloneForSpatial.

@Override
public Control cloneForSpatial(Spatial spatial) {
    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());
        //TODO: bad way finding children!
        if (spatial instanceof Node) {
            Node node = (Node) spatial;
            Spatial wheelSpat = node.getChild(wheel.getWheelSpatial().getName());
            if (wheelSpat != null) {
                newWheel.setWheelSpatial(wheelSpat);
            }
        }
    }
    control.setApplyPhysicsLocal(isApplyPhysicsLocal());
    return control;
}
Also used : Spatial(com.jme3.scene.Spatial) VehicleWheel(com.jme3.bullet.objects.VehicleWheel) Node(com.jme3.scene.Node)

Example 7 with VehicleWheel

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

the class BulletVehicleDebugControl method controlUpdate.

@Override
protected void controlUpdate(float tpf) {
    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();
        Geometry locGeom = (Geometry) suspensionNode.getChild("WheelLocationDebugShape" + i);
        Geometry dirGeom = (Geometry) suspensionNode.getChild("WheelDirectionDebugShape" + i);
        Geometry axleGeom = (Geometry) suspensionNode.getChild("WheelAxleDebugShape" + i);
        Geometry wheelGeom = (Geometry) suspensionNode.getChild("WheelRadiusDebugShape" + i);
        Arrow locArrow = (Arrow) locGeom.getMesh();
        locArrow.setArrowExtent(location);
        Arrow axleArrow = (Arrow) axleGeom.getMesh();
        axleArrow.setArrowExtent(axle.normalizeLocal().multLocal(0.3f));
        Arrow wheelArrow = (Arrow) wheelGeom.getMesh();
        wheelArrow.setArrowExtent(direction.normalizeLocal().multLocal(radius));
        Arrow dirArrow = (Arrow) dirGeom.getMesh();
        dirArrow.setArrowExtent(direction.normalizeLocal().multLocal(restLength));
        dirGeom.setLocalTranslation(location);
        axleGeom.setLocalTranslation(location.addLocal(direction));
        wheelGeom.setLocalTranslation(location);
        i++;
    }
    applyPhysicsTransform(body.getPhysicsLocation(location), body.getPhysicsRotation(rotation));
}
Also used : Geometry(com.jme3.scene.Geometry) Arrow(com.jme3.scene.debug.Arrow) VehicleWheel(com.jme3.bullet.objects.VehicleWheel) Vector3f(com.jme3.math.Vector3f)

Example 8 with VehicleWheel

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

the class PhysicsVehicle method write.

@Override
public void write(JmeExporter ex) throws IOException {
    OutputCapsule capsule = ex.getCapsule(this);
    capsule.write(tuning.frictionSlip, "frictionSlip", 10.5f);
    capsule.write(tuning.maxSuspensionTravelCm, "maxSuspensionTravelCm", 500f);
    capsule.write(tuning.maxSuspensionForce, "maxSuspensionForce", 6000f);
    capsule.write(tuning.suspensionCompression, "suspensionCompression", 0.83f);
    capsule.write(tuning.suspensionDamping, "suspensionDamping", 0.88f);
    capsule.write(tuning.suspensionStiffness, "suspensionStiffness", 5.88f);
    capsule.writeSavableArrayList(wheels, "wheelsList", new ArrayList<VehicleWheel>());
    super.write(ex);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule)

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