diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 0204967..82d7c44 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -45,7 +45,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
45 | private static string LogHeader = "[BULLETSIM VEHICLE]"; | 45 | private static string LogHeader = "[BULLETSIM VEHICLE]"; |
46 | 46 | ||
47 | // the prim this dynamic controller belongs to | 47 | // the prim this dynamic controller belongs to |
48 | private BSPrim ControllingPrim { get; set; } | 48 | private BSPrimLinkable ControllingPrim { get; set; } |
49 | 49 | ||
50 | private bool m_haveRegisteredForSceneEvents; | 50 | private bool m_haveRegisteredForSceneEvents; |
51 | 51 | ||
@@ -128,9 +128,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
128 | public BSDynamics(BSScene myScene, BSPrim myPrim, string actorName) | 128 | public BSDynamics(BSScene myScene, BSPrim myPrim, string actorName) |
129 | : base(myScene, myPrim, actorName) | 129 | : base(myScene, myPrim, actorName) |
130 | { | 130 | { |
131 | ControllingPrim = myPrim; | ||
132 | Type = Vehicle.TYPE_NONE; | 131 | Type = Vehicle.TYPE_NONE; |
133 | m_haveRegisteredForSceneEvents = false; | 132 | m_haveRegisteredForSceneEvents = false; |
133 | |||
134 | ControllingPrim = myPrim as BSPrimLinkable; | ||
135 | if (ControllingPrim == null) | ||
136 | { | ||
137 | // THIS CANNOT HAPPEN!! | ||
138 | } | ||
139 | VDetailLog("{0},Creation", ControllingPrim.LocalID); | ||
134 | } | 140 | } |
135 | 141 | ||
136 | // Return 'true' if this vehicle is doing vehicle things | 142 | // Return 'true' if this vehicle is doing vehicle things |
@@ -585,6 +591,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
585 | // Friction affects are handled by this vehicle code | 591 | // Friction affects are handled by this vehicle code |
586 | m_physicsScene.PE.SetFriction(ControllingPrim.PhysBody, BSParam.VehicleFriction); | 592 | m_physicsScene.PE.SetFriction(ControllingPrim.PhysBody, BSParam.VehicleFriction); |
587 | m_physicsScene.PE.SetRestitution(ControllingPrim.PhysBody, BSParam.VehicleRestitution); | 593 | m_physicsScene.PE.SetRestitution(ControllingPrim.PhysBody, BSParam.VehicleRestitution); |
594 | // ControllingPrim.Linkset.SetPhysicalFriction(BSParam.VehicleFriction); | ||
595 | // ControllingPrim.Linkset.SetPhysicalRestitution(BSParam.VehicleRestitution); | ||
588 | 596 | ||
589 | // Moderate angular movement introduced by Bullet. | 597 | // Moderate angular movement introduced by Bullet. |
590 | // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. | 598 | // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. |
@@ -595,17 +603,20 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
595 | 603 | ||
596 | // Vehicles report collision events so we know when it's on the ground | 604 | // Vehicles report collision events so we know when it's on the ground |
597 | m_physicsScene.PE.AddToCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); | 605 | m_physicsScene.PE.AddToCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); |
606 | // ControllingPrim.Linkset.SetPhysicalCollisionFlags(CollisionFlags.BS_VEHICLE_COLLISIONS); | ||
598 | 607 | ||
599 | Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(ControllingPrim.PhysShape.physShapeInfo, m_vehicleMass); | 608 | Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(ControllingPrim.PhysShape.physShapeInfo, m_vehicleMass); |
600 | ControllingPrim.Inertia = inertia * BSParam.VehicleInertiaFactor; | 609 | ControllingPrim.Inertia = inertia * BSParam.VehicleInertiaFactor; |
601 | m_physicsScene.PE.SetMassProps(ControllingPrim.PhysBody, m_vehicleMass, ControllingPrim.Inertia); | 610 | m_physicsScene.PE.SetMassProps(ControllingPrim.PhysBody, m_vehicleMass, ControllingPrim.Inertia); |
602 | m_physicsScene.PE.UpdateInertiaTensor(ControllingPrim.PhysBody); | 611 | m_physicsScene.PE.UpdateInertiaTensor(ControllingPrim.PhysBody); |
612 | // ControllingPrim.Linkset.ComputeLocalInertia(BSParam.VehicleInertiaFactor); | ||
603 | 613 | ||
604 | // Set the gravity for the vehicle depending on the buoyancy | 614 | // Set the gravity for the vehicle depending on the buoyancy |
605 | // TODO: what should be done if prim and vehicle buoyancy differ? | 615 | // TODO: what should be done if prim and vehicle buoyancy differ? |
606 | m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); | 616 | m_VehicleGravity = ControllingPrim.ComputeGravity(m_VehicleBuoyancy); |
607 | // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. | 617 | // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. |
608 | m_physicsScene.PE.SetGravity(ControllingPrim.PhysBody, Vector3.Zero); | 618 | m_physicsScene.PE.SetGravity(ControllingPrim.PhysBody, Vector3.Zero); |
619 | // ControllingPrim.Linkset.SetPhysicalGravity(Vector3.Zero); | ||
609 | 620 | ||
610 | VDetailLog("{0},BSDynamics.SetPhysicalParameters,mass={1},inert={2},vehGrav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}", | 621 | VDetailLog("{0},BSDynamics.SetPhysicalParameters,mass={1},inert={2},vehGrav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}", |
611 | ControllingPrim.LocalID, m_vehicleMass, ControllingPrim.Inertia, m_VehicleGravity, | 622 | ControllingPrim.LocalID, m_vehicleMass, ControllingPrim.Inertia, m_VehicleGravity, |
@@ -617,6 +628,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
617 | { | 628 | { |
618 | if (ControllingPrim.PhysBody.HasPhysicalBody) | 629 | if (ControllingPrim.PhysBody.HasPhysicalBody) |
619 | m_physicsScene.PE.RemoveFromCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); | 630 | m_physicsScene.PE.RemoveFromCollisionFlags(ControllingPrim.PhysBody, CollisionFlags.BS_VEHICLE_COLLISIONS); |
631 | // ControllingPrim.Linkset.RemoveFromPhysicalCollisionFlags(CollisionFlags.BS_VEHICLE_COLLISIONS); | ||
620 | } | 632 | } |
621 | } | 633 | } |
622 | 634 | ||
@@ -629,6 +641,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
629 | // BSActor.Release() | 641 | // BSActor.Release() |
630 | public override void Dispose() | 642 | public override void Dispose() |
631 | { | 643 | { |
644 | VDetailLog("{0},Dispose", ControllingPrim.LocalID); | ||
632 | UnregisterForSceneEvents(); | 645 | UnregisterForSceneEvents(); |
633 | Type = Vehicle.TYPE_NONE; | 646 | Type = Vehicle.TYPE_NONE; |
634 | Enabled = false; | 647 | Enabled = false; |
@@ -1001,7 +1014,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1001 | else if (newVelocityLengthSq < 0.001f) | 1014 | else if (newVelocityLengthSq < 0.001f) |
1002 | VehicleVelocity = Vector3.Zero; | 1015 | VehicleVelocity = Vector3.Zero; |
1003 | 1016 | ||
1004 | VDetailLog("{0}, MoveLinear,done,isColl={1},newVel={2}", ControllingPrim.LocalID, ControllingPrim.IsColliding, VehicleVelocity ); | 1017 | VDetailLog("{0}, MoveLinear,done,isColl={1},newVel={2}", ControllingPrim.LocalID, ControllingPrim.HasSomeCollision, VehicleVelocity ); |
1005 | 1018 | ||
1006 | } // end MoveLinear() | 1019 | } // end MoveLinear() |
1007 | 1020 | ||
@@ -1029,8 +1042,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1029 | // Add this correction to the velocity to make it faster/slower. | 1042 | // Add this correction to the velocity to make it faster/slower. |
1030 | VehicleVelocity += linearMotorVelocityW; | 1043 | VehicleVelocity += linearMotorVelocityW; |
1031 | 1044 | ||
1032 | VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},correctV={3},correctW={4},newVelW={5},fricFact={6}", | 1045 | VDetailLog("{0}, MoveLinear,velocity,origVelW={1},velV={2},tgt={3},correctV={4},correctW={5},newVelW={6},fricFact={7}", |
1033 | ControllingPrim.LocalID, origVelW, currentVelV, linearMotorCorrectionV, | 1046 | ControllingPrim.LocalID, origVelW, currentVelV, m_linearMotor.TargetValue, linearMotorCorrectionV, |
1034 | linearMotorVelocityW, VehicleVelocity, frictionFactorV); | 1047 | linearMotorVelocityW, VehicleVelocity, frictionFactorV); |
1035 | } | 1048 | } |
1036 | 1049 | ||
@@ -1062,7 +1075,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1062 | Vector3 linearDeflectionW = linearDeflectionV * VehicleOrientation; | 1075 | Vector3 linearDeflectionW = linearDeflectionV * VehicleOrientation; |
1063 | 1076 | ||
1064 | // Optionally, if not colliding, don't effect world downward velocity. Let falling things fall. | 1077 | // Optionally, if not colliding, don't effect world downward velocity. Let falling things fall. |
1065 | if (BSParam.VehicleLinearDeflectionNotCollidingNoZ && !m_controllingPrim.IsColliding) | 1078 | if (BSParam.VehicleLinearDeflectionNotCollidingNoZ && !m_controllingPrim.HasSomeCollision) |
1066 | { | 1079 | { |
1067 | linearDeflectionW.Z = 0f; | 1080 | linearDeflectionW.Z = 0f; |
1068 | } | 1081 | } |
@@ -1222,7 +1235,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1222 | float targetHeight = Type == Vehicle.TYPE_BOAT ? GetWaterLevel(VehiclePosition) : GetTerrainHeight(VehiclePosition); | 1235 | float targetHeight = Type == Vehicle.TYPE_BOAT ? GetWaterLevel(VehiclePosition) : GetTerrainHeight(VehiclePosition); |
1223 | distanceAboveGround = VehiclePosition.Z - targetHeight; | 1236 | distanceAboveGround = VehiclePosition.Z - targetHeight; |
1224 | // Not colliding if the vehicle is off the ground | 1237 | // Not colliding if the vehicle is off the ground |
1225 | if (!Prim.IsColliding) | 1238 | if (!Prim.HasSomeCollision) |
1226 | { | 1239 | { |
1227 | // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); | 1240 | // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); |
1228 | VehicleVelocity += new Vector3(0, 0, -distanceAboveGround); | 1241 | VehicleVelocity += new Vector3(0, 0, -distanceAboveGround); |
@@ -1233,12 +1246,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1233 | // be computed with a motor. | 1246 | // be computed with a motor. |
1234 | // TODO: add interaction with banking. | 1247 | // TODO: add interaction with banking. |
1235 | VDetailLog("{0}, MoveLinear,limitMotorUp,distAbove={1},colliding={2},ret={3}", | 1248 | VDetailLog("{0}, MoveLinear,limitMotorUp,distAbove={1},colliding={2},ret={3}", |
1236 | Prim.LocalID, distanceAboveGround, Prim.IsColliding, ret); | 1249 | Prim.LocalID, distanceAboveGround, Prim.HasSomeCollision, ret); |
1237 | */ | 1250 | */ |
1238 | 1251 | ||
1239 | // Another approach is to measure if we're going up. If going up and not colliding, | 1252 | // Another approach is to measure if we're going up. If going up and not colliding, |
1240 | // the vehicle is in the air. Fix that by pushing down. | 1253 | // the vehicle is in the air. Fix that by pushing down. |
1241 | if (!ControllingPrim.IsColliding && VehicleVelocity.Z > 0.1) | 1254 | if (!ControllingPrim.HasSomeCollision && VehicleVelocity.Z > 0.1) |
1242 | { | 1255 | { |
1243 | // Get rid of any of the velocity vector that is pushing us up. | 1256 | // Get rid of any of the velocity vector that is pushing us up. |
1244 | float upVelocity = VehicleVelocity.Z; | 1257 | float upVelocity = VehicleVelocity.Z; |
@@ -1260,7 +1273,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1260 | } | 1273 | } |
1261 | */ | 1274 | */ |
1262 | VDetailLog("{0}, MoveLinear,limitMotorUp,collide={1},upVel={2},newVel={3}", | 1275 | VDetailLog("{0}, MoveLinear,limitMotorUp,collide={1},upVel={2},newVel={3}", |
1263 | ControllingPrim.LocalID, ControllingPrim.IsColliding, upVelocity, VehicleVelocity); | 1276 | ControllingPrim.LocalID, ControllingPrim.HasSomeCollision, upVelocity, VehicleVelocity); |
1264 | } | 1277 | } |
1265 | } | 1278 | } |
1266 | } | 1279 | } |
@@ -1270,14 +1283,14 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1270 | Vector3 appliedGravity = m_VehicleGravity * m_vehicleMass; | 1283 | Vector3 appliedGravity = m_VehicleGravity * m_vehicleMass; |
1271 | 1284 | ||
1272 | // Hack to reduce downward force if the vehicle is probably sitting on the ground | 1285 | // Hack to reduce downward force if the vehicle is probably sitting on the ground |
1273 | if (ControllingPrim.IsColliding && IsGroundVehicle) | 1286 | if (ControllingPrim.HasSomeCollision && IsGroundVehicle) |
1274 | appliedGravity *= BSParam.VehicleGroundGravityFudge; | 1287 | appliedGravity *= BSParam.VehicleGroundGravityFudge; |
1275 | 1288 | ||
1276 | VehicleAddForce(appliedGravity); | 1289 | VehicleAddForce(appliedGravity); |
1277 | 1290 | ||
1278 | VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},collid={2},fudge={3},mass={4},appliedForce={5}", | 1291 | VDetailLog("{0}, MoveLinear,applyGravity,vehGrav={1},collid={2},fudge={3},mass={4},appliedForce={5}", |
1279 | ControllingPrim.LocalID, m_VehicleGravity, | 1292 | ControllingPrim.LocalID, m_VehicleGravity, |
1280 | ControllingPrim.IsColliding, BSParam.VehicleGroundGravityFudge, m_vehicleMass, appliedGravity); | 1293 | ControllingPrim.HasSomeCollision, BSParam.VehicleGroundGravityFudge, m_vehicleMass, appliedGravity); |
1281 | } | 1294 | } |
1282 | 1295 | ||
1283 | // ======================================================================= | 1296 | // ======================================================================= |