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.setContactResponse(isContactResponse()); 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()); VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel()); newWheel.setFrictionSlip(wheel.getFrictionSlip()); newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
/** * Alter which spatial is controlled. * * @param spatial spatial to control (or null) */ public void setSpatial(Spatial spatial) { this.spatial = spatial; setUserObject(spatial); if (spatial == null) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
steeringValue += -.5f; vehicle.steer(steeringValue); } else if (binding.equals("Rights")) { if (value) { steeringValue += .5f; vehicle.steer(steeringValue); } else if (binding.equals("Ups")) { if (value) { vehicle.accelerate(accelerationValue); } else if (binding.equals("Downs")) { if (value) { vehicle.brake(brakeForce); } else { vehicle.brake(0f); vehicle.applyImpulse(jumpForce, Vector3f.ZERO); vehicle.setPhysicsLocation(Vector3f.ZERO); vehicle.setPhysicsRotation(new Matrix3f()); vehicle.setLinearVelocity(Vector3f.ZERO); vehicle.setAngularVelocity(Vector3f.ZERO); vehicle.resetSuspension(); } else {
player = new VehicleControl(carHull, mass); carNode.addControl(player); player.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness)); player.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness)); player.setSuspensionStiffness(stiffness); player.setMaxSuspensionForce(10000); float back_wheel_h = (wheelRadius * 1.7f) - 1f; float front_wheel_h = (wheelRadius * 1.9f) - 1f; player.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true); wheel_fl.center(); box = (BoundingBox) wheel_fl.getModelBound(); player.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true); wheel_br.center(); box = (BoundingBox) wheel_br.getModelBound(); player.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false); wheel_bl.center(); box = (BoundingBox) wheel_bl.getModelBound(); player.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false); player.getWheel(2).setFrictionSlip(4);
@Override public void simpleUpdate(float tpf) { cam.lookAt(vehicle.getPhysicsLocation(), Vector3f.UNIT_Y); }
/** * Alter which spatial is controlled. * * @param spatial spatial to control (or null) */ public void setSpatial(Spatial spatial) { this.spatial = spatial; setUserObject(spatial); if (spatial == null) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
vehicle = new VehicleControl(compoundShape, 400); vehicleNode.addControl(vehicle); 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); wheels1.rotate(0, FastMath.HALF_PI, 0); wheels1.setMaterial(mat); vehicle.addWheel(node1, new Vector3f(-xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); wheels2.rotate(0, FastMath.HALF_PI, 0); wheels2.setMaterial(mat); vehicle.addWheel(node2, new Vector3f(xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); wheels3.rotate(0, FastMath.HALF_PI, 0); wheels3.setMaterial(mat); vehicle.addWheel(node3, new Vector3f(-xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); wheels4.rotate(0, FastMath.HALF_PI, 0); wheels4.setMaterial(mat); vehicle.addWheel(node4, new Vector3f(xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false);
steeringValue += -.5f; player.steer(steeringValue); } else if (binding.equals("Rights")) { if (value) { steeringValue += .5f; player.steer(steeringValue); accelerationValue += 800; player.accelerate(accelerationValue); player.setCollisionShape(CollisionShapeFactory.createDynamicMeshShape(findGeom(carNode, "Car"))); } else if (binding.equals("Downs")) { if (value) { player.brake(40f); } else { player.brake(0f); player.setPhysicsLocation(Vector3f.ZERO); player.setPhysicsRotation(new Matrix3f()); player.setLinearVelocity(Vector3f.ZERO); player.setAngularVelocity(Vector3f.ZERO); player.resetSuspension(); } else {
@Override public void simpleUpdate(float tpf) { Quaternion quat=new Quaternion(); cam.lookAt(vehicle.getPhysicsLocation(), Vector3f.UNIT_Y); }
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.setContactResponse(isContactResponse()); 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()); VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel()); newWheel.setFrictionSlip(wheel.getFrictionSlip()); newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
/** * Enable or disable this control. * <p> * When the control is disabled, the vehicle is removed from physics space. * When the control is enabled again, the physics object is moved to the * spatial's location and then added to the physics space. * * @param enabled true→enable the control, false→disable it */ public void setEnabled(boolean enabled) { this.enabled = enabled; if (space != null) { if (enabled && !added) { if(spatial!=null){ setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); } space.addCollisionObject(this); added = true; } else if (!enabled && added) { space.removeCollisionObject(this); added = false; } } }
vehicle = new VehicleControl(compoundShape, 800); vehicleNode.addControl(vehicle); 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); wheels1.rotate(0, FastMath.HALF_PI, 0); wheels1.setMaterial(mat); vehicle.addWheel(node1, new Vector3f(-xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); wheels2.rotate(0, FastMath.HALF_PI, 0); wheels2.setMaterial(mat); vehicle.addWheel(node2, new Vector3f(xOff, yOff, zOff), wheelDirection, wheelAxle, restLength, radius, true); wheels3.rotate(0, FastMath.HALF_PI, 0); wheels3.setMaterial(mat); vehicle.addWheel(node3, new Vector3f(-xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false); wheels4.rotate(0, FastMath.HALF_PI, 0); wheels4.setMaterial(mat); vehicle.addWheel(node4, new Vector3f(xOff, yOff, -zOff), wheelDirection, wheelAxle, restLength, radius, false);
steeringValue += -.5f; vehicle.steer(steeringValue); } else if (binding.equals("Rights")) { if (value) { vehicle.steer(steeringValue); } else if (binding.equals("Ups")) { if (value) { vehicle.accelerate(accelerationValue); } else if (binding.equals("Downs")) { if (value) { vehicle.brake(brakeForce); } else { vehicle.brake(0f); getPhysicsSpace().remove(slider); slider.destroy(); vehicle.applyImpulse(jumpForce, Vector3f.ZERO); vehicle.setPhysicsLocation(new Vector3f(0, 0, 0)); vehicle.setPhysicsRotation(new Matrix3f()); vehicle.setLinearVelocity(Vector3f.ZERO); vehicle.setAngularVelocity(Vector3f.ZERO); vehicle.resetSuspension(); bridge.setPhysicsLocation(new Vector3f(0,1.4f,4)); bridge.setPhysicsRotation(Quaternion.DIRECTION_Z.toRotationMatrix());
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()); VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel()); newWheel.setFrictionSlip(wheel.getFrictionSlip()); newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
/** * Enable or disable this control. * <p> * When the control is disabled, the vehicle is removed from physics space. * When the control is enabled again, the physics object is moved to the * spatial's location and then added to the physics space. * * @param enabled true→enable the control, false→disable it */ public void setEnabled(boolean enabled) { this.enabled = enabled; if (space != null) { if (enabled && !added) { if(spatial!=null){ setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); } space.addCollisionObject(this); added = true; } else if (!enabled && added) { space.removeCollisionObject(this); added = false; } } }
@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()); VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel()); newWheel.setFrictionSlip(wheel.getFrictionSlip()); newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
public void setSpatial(Spatial spatial) { this.spatial = spatial; setUserObject(spatial); if (spatial == null) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
@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()); VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel()); newWheel.setFrictionSlip(wheel.getFrictionSlip()); newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
/** * Alter which spatial is controlled. * * @param spatial spatial to control (or null) */ public void setSpatial(Spatial spatial) { this.spatial = spatial; setUserObject(spatial); if (spatial == null) { return; } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
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()); VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel()); newWheel.setFrictionSlip(wheel.getFrictionSlip()); newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());