aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin
diff options
context:
space:
mode:
authorRobert Adams2012-07-25 10:33:36 -0700
committerRobert Adams2012-07-25 16:30:50 -0700
commit5707e171f4c231b58ff683d49fee55e4ccbb317f (patch)
tree95539e7115710f04f01b8521af83934de0052442 /OpenSim/Region/Physics/BulletSPlugin
parentMove Watchdog and MemoryWatchdog classes into OpenSim.Framework.Monitoring wi... (diff)
downloadopensim-SC-5707e171f4c231b58ff683d49fee55e4ccbb317f.zip
opensim-SC-5707e171f4c231b58ff683d49fee55e4ccbb317f.tar.gz
opensim-SC-5707e171f4c231b58ff683d49fee55e4ccbb317f.tar.bz2
opensim-SC-5707e171f4c231b58ff683d49fee55e4ccbb317f.tar.xz
BulletSim: Move constraint tracking from C++ code to C# code
for more flexibility.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs53
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs48
2 files changed, 83 insertions, 18 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
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
index 54a8cfd..89fd9b7 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -32,6 +32,28 @@ using OpenMetaverse;
32 32
33namespace OpenSim.Region.Physics.BulletSPlugin { 33namespace OpenSim.Region.Physics.BulletSPlugin {
34 34
35// Classes to allow some type checking for the API
36public struct BulletSim
37{
38 public BulletSim(uint id, IntPtr xx) { ID = id; Ptr = xx; }
39 public IntPtr Ptr;
40 public uint ID;
41}
42
43public struct BulletBody
44{
45 public BulletBody(uint id, IntPtr xx) { ID = id; Ptr = xx; }
46 public IntPtr Ptr;
47 public uint ID;
48}
49
50public struct BulletConstraint
51{
52 public BulletConstraint(IntPtr xx) { Ptr = xx; }
53 public IntPtr Ptr;
54}
55
56// ===============================================================================
35[StructLayout(LayoutKind.Sequential)] 57[StructLayout(LayoutKind.Sequential)]
36public struct ConvexHull 58public struct ConvexHull
37{ 59{
@@ -142,6 +164,11 @@ public struct ConfigurationParameters
142 public float shouldEnableFrictionCaching; 164 public float shouldEnableFrictionCaching;
143 public float numberOfSolverIterations; 165 public float numberOfSolverIterations;
144 166
167 public float linkConstraintUseFrameOffset;
168 public float linkConstraintEnableTransMotor;
169 public float linkConstraintTransMotorMaxVel;
170 public float linkConstraintTransMotorMaxForce;
171
145 public const float numericTrue = 1f; 172 public const float numericTrue = 1f;
146 public const float numericFalse = 0f; 173 public const float numericFalse = 0f;
147} 174}
@@ -162,6 +189,7 @@ public enum CollisionFlags : uint
162 PHYSICAL_OBJECT = 1 << 12, 189 PHYSICAL_OBJECT = 1 << 12,
163}; 190};
164 191
192// ===============================================================================
165static class BulletSimAPI { 193static class BulletSimAPI {
166 194
167[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 195[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -214,6 +242,7 @@ public static extern bool CreateObject(uint worldID, ShapeData shapeData);
214[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 242[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
215public static extern void CreateLinkset(uint worldID, int objectCount, ShapeData[] shapeDatas); 243public static extern void CreateLinkset(uint worldID, int objectCount, ShapeData[] shapeDatas);
216 244
245/* Remove old functionality
217[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 246[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
218public static extern void AddConstraint(uint worldID, uint id1, uint id2, 247public static extern void AddConstraint(uint worldID, uint id1, uint id2,
219 Vector3 frame1, Quaternion frame1rot, 248 Vector3 frame1, Quaternion frame1rot,
@@ -225,6 +254,7 @@ public static extern bool RemoveConstraintByID(uint worldID, uint id1);
225 254
226[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 255[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
227public static extern bool RemoveConstraint(uint worldID, uint id1, uint id2); 256public static extern bool RemoveConstraint(uint worldID, uint id1, uint id2);
257 */
228 258
229[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 259[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
230public static extern Vector3 GetObjectPosition(uint WorldID, uint id); 260public static extern Vector3 GetObjectPosition(uint WorldID, uint id);
@@ -350,8 +380,22 @@ public static extern IntPtr CreateObject2(IntPtr sim, ShapeData shapeData);
350[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 380[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
351public static extern IntPtr CreateConstraint2(IntPtr sim, IntPtr obj1, IntPtr obj2, 381public static extern IntPtr CreateConstraint2(IntPtr sim, IntPtr obj1, IntPtr obj2,
352 Vector3 frame1loc, Quaternion frame1rot, 382 Vector3 frame1loc, Quaternion frame1rot,
353 Vector3 frame2loc, Quaternion frame2rot, 383 Vector3 frame2loc, Quaternion frame2rot);
354 Vector3 lowLinear, Vector3 hiLinear, Vector3 lowAngular, Vector3 hiAngular); 384
385[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
386public static extern bool SetLinearLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
387
388[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
389public static extern bool SetAngularLimits2(IntPtr constrain, Vector3 low, Vector3 hi);
390
391[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
392public static extern bool UseFrameOffset2(IntPtr constrain, float enable);
393
394[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
395public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enable, float targetVel, float maxMotorForce);
396
397[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
398public static extern bool CalculateTransforms2(IntPtr constrain);
355 399
356[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 400[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
357public static extern bool DestroyConstraint2(IntPtr sim, IntPtr constrain); 401public static extern bool DestroyConstraint2(IntPtr sim, IntPtr constrain);