From 0868244b9a160c0e0fc64ada831b1a0e281ccb0a Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Fri, 21 Oct 2011 18:26:20 +0000 Subject: [PATCH] - fix PhysicsVehicle initialization git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8477 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../bullet/com/jme3/bullet/PhysicsSpace.java | 3 --- .../jme3/bullet/objects/PhysicsVehicle.java | 23 ++++--------------- .../com/jme3/bullet/objects/VehicleWheel.java | 2 +- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/engine/src/bullet/com/jme3/bullet/PhysicsSpace.java b/engine/src/bullet/com/jme3/bullet/PhysicsSpace.java index d2f02e7e2..708d84c85 100644 --- a/engine/src/bullet/com/jme3/bullet/PhysicsSpace.java +++ b/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()); if (node instanceof PhysicsVehicle) { 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()); -// dynamicsWorld.addVehicle(((PhysicsVehicle) node).getVehicleId()); } } @@ -625,7 +623,6 @@ public class PhysicsSpace { if (node instanceof PhysicsVehicle) { 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()); -// dynamicsWorld.removeVehicle(((PhysicsVehicle) node).getVehicleId()); } Logger.getLogger(PhysicsSpace.class.getName()).log(Level.INFO, "Removing RigidBody {0} from physics space.", Long.toHexString(node.getObjectId())); physicsNodes.remove(node.getObjectId()); diff --git a/engine/src/bullet/com/jme3/bullet/objects/PhysicsVehicle.java b/engine/src/bullet/com/jme3/bullet/objects/PhysicsVehicle.java index c0ae3233a..a85a081ea 100644 --- a/engine/src/bullet/com/jme3/bullet/objects/PhysicsVehicle.java +++ b/engine/src/bullet/com/jme3/bullet/objects/PhysicsVehicle.java @@ -114,9 +114,7 @@ public class PhysicsVehicle extends PhysicsRigidBody { tuning = new VehicleTuning(); } motionState.setVehicle(this); -// if (physicsSpace != null) { -// createVehicle(physicsSpace); -// } + createVehicle(physicsSpace); } /** @@ -124,12 +122,6 @@ public class PhysicsVehicle extends PhysicsRigidBody { */ public void createVehicle(PhysicsSpace space) { physicsSpace = space; -// try{ -// if(5==5) -// throw new IllegalStateException("Who calls this!"); -// }catch(Exception e){ -// e.printStackTrace(); -// } if (space == null) { return; } @@ -137,7 +129,6 @@ public class PhysicsVehicle extends PhysicsRigidBody { throw new IllegalStateException("Physics space is not initialized!"); } 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 Vehicle {0}", Long.toHexString(vehicleId)); finalizeNative(rayCasterId, vehicleId); @@ -149,12 +140,6 @@ public class PhysicsVehicle extends PhysicsRigidBody { setCoordinateSystem(vehicleId, 0, 1, 2); for (VehicleWheel wheel : wheels) { 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 { 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.setMaxSuspensionTravelCm(tuning.maxSuspensionTravelCm); wheel.setSuspensionStiffness(tuning.suspensionStiffness); @@ -208,6 +190,9 @@ public class PhysicsVehicle extends PhysicsRigidBody { wheel.setWheelsDampingRelaxation(tuning.suspensionDamping); wheel.setMaxSuspensionForce(tuning.maxSuspensionForce); 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) { updateDebugShape(); } diff --git a/engine/src/bullet/com/jme3/bullet/objects/VehicleWheel.java b/engine/src/bullet/com/jme3/bullet/objects/VehicleWheel.java index 7b31f7b0b..5c1252b08 100644 --- a/engine/src/bullet/com/jme3/bullet/objects/VehicleWheel.java +++ b/engine/src/bullet/com/jme3/bullet/objects/VehicleWheel.java @@ -418,7 +418,7 @@ public class VehicleWheel implements Savable { protected void finalize() throws Throwable { super.finalize(); Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Finalizing Wheel {0}", Long.toHexString(wheelId)); - finalizeNative(wheelId); +// finalizeNative(wheelId); } private native void finalizeNative(long wheelId);