diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index a19d6d7..ff87955 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -97,6 +97,9 @@ public sealed class BSPrim : PhysicsActor | |||
97 | long _collidingStep; | 97 | long _collidingStep; |
98 | long _collidingGroundStep; | 98 | long _collidingGroundStep; |
99 | 99 | ||
100 | private BulletBody m_body; | ||
101 | public BulletBody Body { get { return m_body; } } | ||
102 | |||
100 | private BSDynamics _vehicle; | 103 | private BSDynamics _vehicle; |
101 | 104 | ||
102 | private OMV.Vector3 _PIDTarget; | 105 | private OMV.Vector3 _PIDTarget; |
@@ -138,6 +141,11 @@ public sealed class BSPrim : PhysicsActor | |||
138 | _scene.TaintedObject(delegate() | 141 | _scene.TaintedObject(delegate() |
139 | { | 142 | { |
140 | RecreateGeomAndObject(); | 143 | RecreateGeomAndObject(); |
144 | |||
145 | // Get the pointer to the physical body for this object. | ||
146 | // At the moment, we're still letting BulletSim manage the creation and destruction | ||
147 | // of the object. Someday we'll move that into the C# code. | ||
148 | m_body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); | ||
141 | }); | 149 | }); |
142 | } | 150 | } |
143 | 151 | ||
@@ -161,7 +169,7 @@ public sealed class BSPrim : PhysicsActor | |||
161 | _parentPrim = null; | 169 | _parentPrim = null; |
162 | } | 170 | } |
163 | 171 | ||
164 | // make sure there are no possible children depending on me | 172 | // make sure there are no other prims are linked to me |
165 | UnlinkAllChildren(); | 173 | UnlinkAllChildren(); |
166 | 174 | ||
167 | // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. | 175 | // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. |
@@ -333,11 +341,11 @@ public sealed class BSPrim : PhysicsActor | |||
333 | _rotationalVelocity = OMV.Vector3.Zero; | 341 | _rotationalVelocity = OMV.Vector3.Zero; |
334 | 342 | ||
335 | // Zero some other properties directly into the physics engine | 343 | // Zero some other properties directly into the physics engine |
336 | IntPtr obj = BulletSimAPI.GetBodyHandleWorldID2(_scene.WorldID, LocalID); | 344 | BulletBody obj = new BulletBody(LocalID, BulletSimAPI.GetBodyHandleWorldID2(_scene.WorldID, LocalID)); |
337 | BulletSimAPI.SetVelocity2(obj, OMV.Vector3.Zero); | 345 | BulletSimAPI.SetVelocity2(obj.Ptr, OMV.Vector3.Zero); |
338 | BulletSimAPI.SetAngularVelocity2(obj, OMV.Vector3.Zero); | 346 | BulletSimAPI.SetAngularVelocity2(obj.Ptr, OMV.Vector3.Zero); |
339 | BulletSimAPI.SetInterpolation2(obj, OMV.Vector3.Zero, OMV.Vector3.Zero); | 347 | BulletSimAPI.SetInterpolation2(obj.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); |
340 | BulletSimAPI.ClearForces2(obj); | 348 | BulletSimAPI.ClearForces2(obj.Ptr); |
341 | } | 349 | } |
342 | 350 | ||
343 | public override void LockAngularMotion(OMV.Vector3 axis) | 351 | public override void LockAngularMotion(OMV.Vector3 axis) |
@@ -383,7 +391,8 @@ public sealed class BSPrim : PhysicsActor | |||
383 | _scene.TaintedObject(delegate() | 391 | _scene.TaintedObject(delegate() |
384 | { | 392 | { |
385 | DetailLog("{0},SetForce,taint,force={1}", LocalID, _force); | 393 | DetailLog("{0},SetForce,taint,force={1}", LocalID, _force); |
386 | BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); | 394 | // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); |
395 | BulletSimAPI.SetObjectForce2(Body.Ptr, _force); | ||
387 | }); | 396 | }); |
388 | } | 397 | } |
389 | } | 398 | } |
@@ -407,8 +416,7 @@ public sealed class BSPrim : PhysicsActor | |||
407 | _scene.TaintedObject(delegate() | 416 | _scene.TaintedObject(delegate() |
408 | { | 417 | { |
409 | // Tell the physics engine to clear state | 418 | // Tell the physics engine to clear state |
410 | IntPtr obj = BulletSimAPI.GetBodyHandleWorldID2(_scene.WorldID, LocalID); | 419 | BulletSimAPI.ClearForces2(this.Body.Ptr); |
411 | BulletSimAPI.ClearForces2(obj); | ||
412 | }); | 420 | }); |
413 | 421 | ||
414 | // make it so the scene will call us each tick to do vehicle things | 422 | // make it so the scene will call us each tick to do vehicle things |
@@ -420,7 +428,6 @@ public sealed class BSPrim : PhysicsActor | |||
420 | } | 428 | } |
421 | public override void VehicleFloatParam(int param, float value) | 429 | public override void VehicleFloatParam(int param, float value) |
422 | { | 430 | { |
423 | m_log.DebugFormat("{0} VehicleFloatParam. {1} <= {2}", LogHeader, param, value); | ||
424 | _scene.TaintedObject(delegate() | 431 | _scene.TaintedObject(delegate() |
425 | { | 432 | { |
426 | _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); | 433 | _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); |
@@ -428,7 +435,6 @@ public sealed class BSPrim : PhysicsActor | |||
428 | } | 435 | } |
429 | public override void VehicleVectorParam(int param, OMV.Vector3 value) | 436 | public override void VehicleVectorParam(int param, OMV.Vector3 value) |
430 | { | 437 | { |
431 | m_log.DebugFormat("{0} VehicleVectorParam. {1} <= {2}", LogHeader, param, value); | ||
432 | _scene.TaintedObject(delegate() | 438 | _scene.TaintedObject(delegate() |
433 | { | 439 | { |
434 | _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); | 440 | _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); |
@@ -436,7 +442,6 @@ public sealed class BSPrim : PhysicsActor | |||
436 | } | 442 | } |
437 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) | 443 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) |
438 | { | 444 | { |
439 | m_log.DebugFormat("{0} VehicleRotationParam. {1} <= {2}", LogHeader, param, rotation); | ||
440 | _scene.TaintedObject(delegate() | 445 | _scene.TaintedObject(delegate() |
441 | { | 446 | { |
442 | _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); | 447 | _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); |
@@ -444,7 +449,6 @@ public sealed class BSPrim : PhysicsActor | |||
444 | } | 449 | } |
445 | public override void VehicleFlags(int param, bool remove) | 450 | public override void VehicleFlags(int param, bool remove) |
446 | { | 451 | { |
447 | m_log.DebugFormat("{0} VehicleFlags. {1}. Remove={2}", LogHeader, param, remove); | ||
448 | _scene.TaintedObject(delegate() | 452 | _scene.TaintedObject(delegate() |
449 | { | 453 | { |
450 | _vehicle.ProcessVehicleFlags(param, remove); | 454 | _vehicle.ProcessVehicleFlags(param, remove); |
@@ -1296,7 +1300,7 @@ public sealed class BSPrim : PhysicsActor | |||
1296 | 1300 | ||
1297 | // remove any constraints that might be in place | 1301 | // remove any constraints that might be in place |
1298 | DebugLog("{0}: CreateLinkset: RemoveConstraints between me and any children", LogHeader, LocalID); | 1302 | DebugLog("{0}: CreateLinkset: RemoveConstraints between me and any children", LogHeader, LocalID); |
1299 | BulletSimAPI.RemoveConstraintByID(_scene.WorldID, LocalID); | 1303 | UnlinkAllChildren(); |
1300 | 1304 | ||
1301 | // create constraints between the root prim and each of the children | 1305 | // create constraints between the root prim and each of the children |
1302 | foreach (BSPrim prim in _childrenPrims) | 1306 | foreach (BSPrim prim in _childrenPrims) |
@@ -1323,6 +1327,7 @@ public sealed class BSPrim : PhysicsActor | |||
1323 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 | 1327 | // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 |
1324 | DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID); | 1328 | DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID); |
1325 | DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID); | 1329 | DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID); |
1330 | /* | ||
1326 | BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, childPrim.LocalID, | 1331 | BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, childPrim.LocalID, |
1327 | childRelativePosition, | 1332 | childRelativePosition, |
1328 | childRelativeRotation, | 1333 | childRelativeRotation, |
@@ -1330,6 +1335,20 @@ public sealed class BSPrim : PhysicsActor | |||
1330 | OMV.Quaternion.Identity, | 1335 | OMV.Quaternion.Identity, |
1331 | OMV.Vector3.Zero, OMV.Vector3.Zero, | 1336 | OMV.Vector3.Zero, OMV.Vector3.Zero, |
1332 | OMV.Vector3.Zero, OMV.Vector3.Zero); | 1337 | OMV.Vector3.Zero, OMV.Vector3.Zero); |
1338 | */ | ||
1339 | // BSConstraint constrain = new BSConstraint(_scene.World, this.Body, childPrim.Body, | ||
1340 | BSConstraint constrain = _scene.Constraints.CreateConstraint( | ||
1341 | _scene.World, this.Body, childPrim.Body, | ||
1342 | childRelativePosition, | ||
1343 | childRelativeRotation, | ||
1344 | OMV.Vector3.Zero, | ||
1345 | OMV.Quaternion.Identity); | ||
1346 | constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); | ||
1347 | constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); | ||
1348 | |||
1349 | // tweek the constraint to increase stability | ||
1350 | constrain.UseFrameOffset(true); | ||
1351 | constrain.TranslationalLimitMotor(true, 5f, 0.1f); | ||
1333 | } | 1352 | } |
1334 | 1353 | ||
1335 | // Remove linkage between myself and a particular child | 1354 | // Remove linkage between myself and a particular child |
@@ -1339,7 +1358,8 @@ public sealed class BSPrim : PhysicsActor | |||
1339 | DebugLog("{0}: UnlinkAChildFromMe: RemoveConstraint between root prim {1} and child prim {2}", | 1358 | DebugLog("{0}: UnlinkAChildFromMe: RemoveConstraint between root prim {1} and child prim {2}", |
1340 | LogHeader, LocalID, childPrim.LocalID); | 1359 | LogHeader, LocalID, childPrim.LocalID); |
1341 | DetailLog("{0},UnlinkAChildFromMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID); | 1360 | DetailLog("{0},UnlinkAChildFromMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID); |
1342 | BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, childPrim.LocalID); | 1361 | // BulletSimAPI.RemoveConstraint(_scene.WorldID, LocalID, childPrim.LocalID); |
1362 | _scene.Constraints.RemoveAndDestroyConstraint(this.Body, childPrim.Body); | ||
1343 | } | 1363 | } |
1344 | 1364 | ||
1345 | // Remove linkage between myself and any possible children I might have | 1365 | // Remove linkage between myself and any possible children I might have |
@@ -1348,7 +1368,8 @@ public sealed class BSPrim : PhysicsActor | |||
1348 | { | 1368 | { |
1349 | DebugLog("{0}: UnlinkAllChildren:", LogHeader); | 1369 | DebugLog("{0}: UnlinkAllChildren:", LogHeader); |
1350 | DetailLog("{0},UnlinkAllChildren,taint", LocalID); | 1370 | DetailLog("{0},UnlinkAllChildren,taint", LocalID); |
1351 | BulletSimAPI.RemoveConstraintByID(_scene.WorldID, LocalID); | 1371 | _scene.Constraints.RemoveAndDestroyConstraint(this.Body); |
1372 | // BulletSimAPI.RemoveConstraintByID(_scene.WorldID, LocalID); | ||
1352 | } | 1373 | } |
1353 | 1374 | ||
1354 | #endregion // Linkset creation and destruction | 1375 | #endregion // Linkset creation and destruction |