Browse Source

- fix PhysicsVehicle initialization

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8477 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
nor..67 14 years ago
parent
commit
0868244b9a

+ 0 - 3
engine/src/bullet/com/jme3/bullet/PhysicsSpace.java

@@ -615,9 +615,7 @@ public class PhysicsSpace {
         Logger.getLogger(PhysicsSpace.class.getName()).log(Level.INFO, "Adding RigidBody {0} to physics space.", node.getObjectId());
         Logger.getLogger(PhysicsSpace.class.getName()).log(Level.INFO, "Adding RigidBody {0} to physics space.", node.getObjectId());
         if (node instanceof PhysicsVehicle) {
         if (node instanceof PhysicsVehicle) {
             Logger.getLogger(PhysicsSpace.class.getName()).log(Level.INFO, "Adding vehicle constraint {0} to physics space.", Long.toHexString(((PhysicsVehicle) node).getVehicleId()));
             Logger.getLogger(PhysicsSpace.class.getName()).log(Level.INFO, "Adding vehicle constraint {0} to physics space.", Long.toHexString(((PhysicsVehicle) node).getVehicleId()));
-            ((PhysicsVehicle) node).createVehicle(this);
             addVehicle(physicsSpaceId, ((PhysicsVehicle) node).getVehicleId());
             addVehicle(physicsSpaceId, ((PhysicsVehicle) node).getVehicleId());
-//            dynamicsWorld.addVehicle(((PhysicsVehicle) node).getVehicleId());
         }
         }
     }
     }
 
 
@@ -625,7 +623,6 @@ public class PhysicsSpace {
         if (node instanceof PhysicsVehicle) {
         if (node instanceof PhysicsVehicle) {
             Logger.getLogger(PhysicsSpace.class.getName()).log(Level.INFO, "Removing vehicle constraint {0} from physics space.", Long.toHexString(((PhysicsVehicle) node).getVehicleId()));
             Logger.getLogger(PhysicsSpace.class.getName()).log(Level.INFO, "Removing vehicle constraint {0} from physics space.", Long.toHexString(((PhysicsVehicle) node).getVehicleId()));
             removeVehicle(physicsSpaceId, ((PhysicsVehicle) node).getVehicleId());
             removeVehicle(physicsSpaceId, ((PhysicsVehicle) node).getVehicleId());
-//            dynamicsWorld.removeVehicle(((PhysicsVehicle) node).getVehicleId());
         }
         }
         Logger.getLogger(PhysicsSpace.class.getName()).log(Level.INFO, "Removing RigidBody {0} from physics space.", Long.toHexString(node.getObjectId()));
         Logger.getLogger(PhysicsSpace.class.getName()).log(Level.INFO, "Removing RigidBody {0} from physics space.", Long.toHexString(node.getObjectId()));
         physicsNodes.remove(node.getObjectId());
         physicsNodes.remove(node.getObjectId());

+ 4 - 19
engine/src/bullet/com/jme3/bullet/objects/PhysicsVehicle.java

@@ -114,9 +114,7 @@ public class PhysicsVehicle extends PhysicsRigidBody {
             tuning = new VehicleTuning();
             tuning = new VehicleTuning();
         }
         }
         motionState.setVehicle(this);
         motionState.setVehicle(this);
-//        if (physicsSpace != null) {
-//            createVehicle(physicsSpace);
-//        }
+        createVehicle(physicsSpace);
     }
     }
 
 
     /**
     /**
@@ -124,12 +122,6 @@ public class PhysicsVehicle extends PhysicsRigidBody {
      */
      */
     public void createVehicle(PhysicsSpace space) {
     public void createVehicle(PhysicsSpace space) {
         physicsSpace = space;
         physicsSpace = space;
-//        try{
-//        if(5==5)
-//            throw new IllegalStateException("Who calls this!");
-//        }catch(Exception e){
-//            e.printStackTrace();
-//        }
         if (space == null) {
         if (space == null) {
             return;
             return;
         }
         }
@@ -137,7 +129,6 @@ public class PhysicsVehicle extends PhysicsRigidBody {
             throw new IllegalStateException("Physics space is not initialized!");
             throw new IllegalStateException("Physics space is not initialized!");
         }
         }
         if (rayCasterId != 0) {
         if (rayCasterId != 0) {
-            space.removeCollisionObject(this);
             Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Clearing RayCaster {0}", Long.toHexString(rayCasterId));
             Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Clearing RayCaster {0}", Long.toHexString(rayCasterId));
             Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Clearing Vehicle {0}", Long.toHexString(vehicleId));
             Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Clearing Vehicle {0}", Long.toHexString(vehicleId));
             finalizeNative(rayCasterId, vehicleId);
             finalizeNative(rayCasterId, vehicleId);
@@ -149,12 +140,6 @@ public class PhysicsVehicle extends PhysicsRigidBody {
         setCoordinateSystem(vehicleId, 0, 1, 2);
         setCoordinateSystem(vehicleId, 0, 1, 2);
         for (VehicleWheel wheel : wheels) {
         for (VehicleWheel wheel : wheels) {
             wheel.setWheelId(addWheel(vehicleId, wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), tuning, wheel.isFrontWheel()));
             wheel.setWheelId(addWheel(vehicleId, wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), tuning, wheel.isFrontWheel()));
-            wheel.setFrictionSlip(tuning.frictionSlip);
-            wheel.setMaxSuspensionTravelCm(tuning.maxSuspensionTravelCm);
-            wheel.setSuspensionStiffness(tuning.suspensionStiffness);
-            wheel.setWheelsDampingCompression(tuning.suspensionCompression);
-            wheel.setWheelsDampingRelaxation(tuning.suspensionDamping);
-            wheel.setMaxSuspensionForce(tuning.maxSuspensionForce);
         }
         }
     }
     }
 
 
@@ -198,9 +183,6 @@ public class PhysicsVehicle extends PhysicsRigidBody {
         } else {
         } else {
             wheel = new VehicleWheel(spat, connectionPoint, direction, axle, suspensionRestLength, wheelRadius, isFrontWheel);
             wheel = new VehicleWheel(spat, connectionPoint, direction, axle, suspensionRestLength, wheelRadius, isFrontWheel);
         }
         }
-        if (vehicleId != 0) {
-            wheel.setWheelId(addWheel(vehicleId, wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), tuning, wheel.isFrontWheel()));
-        }
         wheel.setFrictionSlip(tuning.frictionSlip);
         wheel.setFrictionSlip(tuning.frictionSlip);
         wheel.setMaxSuspensionTravelCm(tuning.maxSuspensionTravelCm);
         wheel.setMaxSuspensionTravelCm(tuning.maxSuspensionTravelCm);
         wheel.setSuspensionStiffness(tuning.suspensionStiffness);
         wheel.setSuspensionStiffness(tuning.suspensionStiffness);
@@ -208,6 +190,9 @@ public class PhysicsVehicle extends PhysicsRigidBody {
         wheel.setWheelsDampingRelaxation(tuning.suspensionDamping);
         wheel.setWheelsDampingRelaxation(tuning.suspensionDamping);
         wheel.setMaxSuspensionForce(tuning.maxSuspensionForce);
         wheel.setMaxSuspensionForce(tuning.maxSuspensionForce);
         wheels.add(wheel);
         wheels.add(wheel);
+        if (vehicleId != 0) {
+            wheel.setWheelId(addWheel(vehicleId, wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), tuning, wheel.isFrontWheel()));
+        }
         if (debugShape != null) {
         if (debugShape != null) {
             updateDebugShape();
             updateDebugShape();
         }
         }

+ 1 - 1
engine/src/bullet/com/jme3/bullet/objects/VehicleWheel.java

@@ -418,7 +418,7 @@ public class VehicleWheel implements Savable {
     protected void finalize() throws Throwable {
     protected void finalize() throws Throwable {
         super.finalize();
         super.finalize();
         Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Finalizing Wheel {0}", Long.toHexString(wheelId));
         Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Finalizing Wheel {0}", Long.toHexString(wheelId));
-        finalizeNative(wheelId);
+//        finalizeNative(wheelId);
     }
     }
 
 
     private native void finalizeNative(long wheelId);
     private native void finalizeNative(long wheelId);