|
@@ -46,6 +46,8 @@ import com.jme3.renderer.ViewPort;
|
|
import com.jme3.scene.Node;
|
|
import com.jme3.scene.Node;
|
|
import com.jme3.scene.Spatial;
|
|
import com.jme3.scene.Spatial;
|
|
import com.jme3.scene.control.Control;
|
|
import com.jme3.scene.control.Control;
|
|
|
|
+import com.jme3.util.clone.Cloner;
|
|
|
|
+import com.jme3.util.clone.JmeCloneable;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
|
|
|
|
@@ -53,7 +55,7 @@ import java.util.Iterator;
|
|
*
|
|
*
|
|
* @author normenhansen
|
|
* @author normenhansen
|
|
*/
|
|
*/
|
|
-public class VehicleControl extends PhysicsVehicle implements PhysicsControl {
|
|
|
|
|
|
+public class VehicleControl extends PhysicsVehicle implements PhysicsControl, JmeCloneable {
|
|
|
|
|
|
protected Spatial spatial;
|
|
protected Spatial spatial;
|
|
protected boolean enabled = true;
|
|
protected boolean enabled = true;
|
|
@@ -156,6 +158,63 @@ public class VehicleControl extends PhysicsVehicle implements PhysicsControl {
|
|
return control;
|
|
return control;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @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.spatial = spatial;
|
|
|
|
+ return control;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public void setSpatial(Spatial spatial) {
|
|
public void setSpatial(Spatial spatial) {
|
|
this.spatial = spatial;
|
|
this.spatial = spatial;
|
|
setUserObject(spatial);
|
|
setUserObject(spatial);
|