diff options
author | Robert Adams | 2012-10-29 11:30:47 -0700 |
---|---|---|
committer | Robert Adams | 2012-11-03 21:13:35 -0700 |
commit | e20bad12cc0584c6368e46e0f326e6b616133e8f (patch) | |
tree | 9eb7db09bdb82036ebfe3623f27dc97868de4c02 | |
parent | BulletSim: rename constraint classes so they show up together alphabetically. (diff) | |
download | opensim-SC_OLD-e20bad12cc0584c6368e46e0f326e6b616133e8f.zip opensim-SC_OLD-e20bad12cc0584c6368e46e0f326e6b616133e8f.tar.gz opensim-SC_OLD-e20bad12cc0584c6368e46e0f326e6b616133e8f.tar.bz2 opensim-SC_OLD-e20bad12cc0584c6368e46e0f326e6b616133e8f.tar.xz |
BulletSim: centralize mass/inertia computation with UpdatePhysicalMassProperties() function. Didn't add setMassRaw because assignment with side effect is dirty.
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 15 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 2 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 39 |
3 files changed, 38 insertions, 18 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 8bb4b21..b9013ab 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -155,8 +155,7 @@ public sealed class BSCharacter : BSPhysObject | |||
155 | BulletSimAPI.SetCcdSweptSphereRadius2(BSBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); | 155 | BulletSimAPI.SetCcdSweptSphereRadius2(BSBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); |
156 | } | 156 | } |
157 | 157 | ||
158 | OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, MassRaw); | 158 | UpdatePhysicalMassProperties(MassRaw); |
159 | BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia); | ||
160 | 159 | ||
161 | // Make so capsule does not fall over | 160 | // Make so capsule does not fall over |
162 | BulletSimAPI.SetAngularFactorV2(BSBody.ptr, OMV.Vector3.Zero); | 161 | BulletSimAPI.SetAngularFactorV2(BSBody.ptr, OMV.Vector3.Zero); |
@@ -201,8 +200,7 @@ public sealed class BSCharacter : BSPhysObject | |||
201 | PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() | 200 | PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() |
202 | { | 201 | { |
203 | BulletSimAPI.SetLocalScaling2(BSShape.ptr, Scale); | 202 | BulletSimAPI.SetLocalScaling2(BSShape.ptr, Scale); |
204 | OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, MassRaw); | 203 | UpdatePhysicalMassProperties(MassRaw); |
205 | BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia); | ||
206 | }); | 204 | }); |
207 | 205 | ||
208 | } | 206 | } |
@@ -329,7 +327,14 @@ public sealed class BSCharacter : BSPhysObject | |||
329 | public override float Mass { get { return _mass; } } | 327 | public override float Mass { get { return _mass; } } |
330 | 328 | ||
331 | // used when we only want this prim's mass and not the linkset thing | 329 | // used when we only want this prim's mass and not the linkset thing |
332 | public override float MassRaw { get {return _mass; } } | 330 | public override float MassRaw { |
331 | get {return _mass; } | ||
332 | } | ||
333 | public override void UpdatePhysicalMassProperties(float physMass) | ||
334 | { | ||
335 | OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, physMass); | ||
336 | BulletSimAPI.SetMassProps2(BSBody.ptr, physMass, localInertia); | ||
337 | } | ||
333 | 338 | ||
334 | public override OMV.Vector3 Force { | 339 | public override OMV.Vector3 Force { |
335 | get { return _force; } | 340 | get { return _force; } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 538f905..be8d64b 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -64,6 +64,8 @@ public abstract class BSPhysObject : PhysicsActor | |||
64 | 64 | ||
65 | // Return the object mass without calculating it or having side effects | 65 | // Return the object mass without calculating it or having side effects |
66 | public abstract float MassRaw { get; } | 66 | public abstract float MassRaw { get; } |
67 | // Set the raw mass but also update physical mass properties (inertia, ...) | ||
68 | public abstract void UpdatePhysicalMassProperties(float mass); | ||
67 | 69 | ||
68 | // Reference to the physical body (btCollisionObject) of this object | 70 | // Reference to the physical body (btCollisionObject) of this object |
69 | public BulletBody BSBody; | 71 | public BulletBody BSBody; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 44937df..ad09a61 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -356,13 +356,32 @@ public sealed class BSPrim : BSPhysObject | |||
356 | { | 356 | { |
357 | get | 357 | get |
358 | { | 358 | { |
359 | // return Linkset.LinksetMass; | 359 | return Linkset.LinksetMass; |
360 | return _mass; | 360 | // return _mass; |
361 | } | 361 | } |
362 | } | 362 | } |
363 | 363 | ||
364 | // used when we only want this prim's mass and not the linkset thing | 364 | // used when we only want this prim's mass and not the linkset thing |
365 | public override float MassRaw { get { return _mass; } } | 365 | public override float MassRaw { |
366 | get { return _mass; } | ||
367 | } | ||
368 | // Set the physical mass to the passed mass. | ||
369 | // Note that this does not change _mass! | ||
370 | public override void UpdatePhysicalMassProperties(float physMass) | ||
371 | { | ||
372 | if (IsStatic) | ||
373 | { | ||
374 | BulletSimAPI.SetMassProps2(BSBody.ptr, 0f, OMV.Vector3.Zero); | ||
375 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); | ||
376 | } | ||
377 | else | ||
378 | { | ||
379 | OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, physMass); | ||
380 | BulletSimAPI.SetMassProps2(BSBody.ptr, physMass, localInertia); | ||
381 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); | ||
382 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, localInertia); | ||
383 | } | ||
384 | } | ||
366 | 385 | ||
367 | // Is this used? | 386 | // Is this used? |
368 | public override OMV.Vector3 CenterOfMass | 387 | public override OMV.Vector3 CenterOfMass |
@@ -613,7 +632,7 @@ public sealed class BSPrim : BSPhysObject | |||
613 | // Recompute any linkset parameters. | 632 | // Recompute any linkset parameters. |
614 | // When going from non-physical to physical, this re-enables the constraints that | 633 | // When going from non-physical to physical, this re-enables the constraints that |
615 | // had been automatically disabled when the mass was set to zero. | 634 | // had been automatically disabled when the mass was set to zero. |
616 | Linkset.Refresh(this, true); | 635 | Linkset.Refresh(this); |
617 | 636 | ||
618 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,exit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", | 637 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,exit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", |
619 | LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, BSBody, BSShape); | 638 | LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, BSBody, BSShape); |
@@ -635,9 +654,7 @@ public sealed class BSPrim : BSPhysObject | |||
635 | // Center of mass is at the center of the object | 654 | // Center of mass is at the center of the object |
636 | BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.BSBody.ptr, _position, _orientation); | 655 | BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.BSBody.ptr, _position, _orientation); |
637 | // Mass is zero which disables a bunch of physics stuff in Bullet | 656 | // Mass is zero which disables a bunch of physics stuff in Bullet |
638 | BulletSimAPI.SetMassProps2(BSBody.ptr, 0f, OMV.Vector3.Zero); | 657 | UpdatePhysicalMassProperties(0f); |
639 | // There is no inertia in a static object | ||
640 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); | ||
641 | // Set collision detection parameters | 658 | // Set collision detection parameters |
642 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) | 659 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) |
643 | { | 660 | { |
@@ -671,9 +688,7 @@ public sealed class BSPrim : BSPhysObject | |||
671 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); | 688 | BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); |
672 | 689 | ||
673 | // A dynamic object has mass | 690 | // A dynamic object has mass |
674 | OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, Mass); | 691 | UpdatePhysicalMassProperties(MassRaw); |
675 | BulletSimAPI.SetMassProps2(BSBody.ptr, _mass, inertia); | ||
676 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); | ||
677 | 692 | ||
678 | // Set collision detection parameters | 693 | // Set collision detection parameters |
679 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) | 694 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) |
@@ -1247,9 +1262,7 @@ public sealed class BSPrim : BSPhysObject | |||
1247 | 1262 | ||
1248 | returnMass = _density * volume; | 1263 | returnMass = _density * volume; |
1249 | 1264 | ||
1250 | /* | 1265 | /* Comment out code that computes the mass of the linkset. That is done in the Linkset class. |
1251 | * This change means each object keeps its own mass and the Mass property | ||
1252 | * will return the sum if we're part of a linkset. | ||
1253 | if (IsRootOfLinkset) | 1266 | if (IsRootOfLinkset) |
1254 | { | 1267 | { |
1255 | foreach (BSPrim prim in _childrenPrims) | 1268 | foreach (BSPrim prim in _childrenPrims) |