aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs61
1 files changed, 45 insertions, 16 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index aaa0d93..14eb505 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -25,8 +25,6 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28// Uncomment this it enable code to do all shape an body memory management
29// in the C# code.
30using System; 28using System;
31using System.Reflection; 29using System.Reflection;
32using System.Collections.Generic; 30using System.Collections.Generic;
@@ -236,14 +234,27 @@ public sealed class BSPrim : BSPhysObject
236 // Do it to the properties so the values get set in the physics engine. 234 // Do it to the properties so the values get set in the physics engine.
237 // Push the setting of the values to the viewer. 235 // Push the setting of the values to the viewer.
238 // Called at taint time! 236 // Called at taint time!
239 public override void ZeroMotion() 237 public override void ZeroMotion(bool inTaintTime)
240 { 238 {
241 _velocity = OMV.Vector3.Zero; 239 _velocity = OMV.Vector3.Zero;
242 _acceleration = OMV.Vector3.Zero; 240 _acceleration = OMV.Vector3.Zero;
243 _rotationalVelocity = OMV.Vector3.Zero; 241 _rotationalVelocity = OMV.Vector3.Zero;
244 242
245 // Zero some other properties in the physics engine 243 // Zero some other properties in the physics engine
246 BulletSimAPI.ClearAllForces2(PhysBody.ptr); 244 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate()
245 {
246 BulletSimAPI.ClearAllForces2(PhysBody.ptr);
247 });
248 }
249 public override void ZeroAngularMotion(bool inTaintTime)
250 {
251 _rotationalVelocity = OMV.Vector3.Zero;
252 // Zero some other properties in the physics engine
253 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate()
254 {
255 BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero);
256 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero);
257 });
247 } 258 }
248 259
249 public override void LockAngularMotion(OMV.Vector3 axis) 260 public override void LockAngularMotion(OMV.Vector3 axis)
@@ -371,17 +382,18 @@ public sealed class BSPrim : BSPhysObject
371 { 382 {
372 if (IsStatic) 383 if (IsStatic)
373 { 384 {
374 BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, OMV.Vector3.Zero); 385 Inertia = OMV.Vector3.Zero;
386 BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia);
375 BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); 387 BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
376 } 388 }
377 else 389 else
378 { 390 {
379 OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); 391 Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
380 BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, localInertia); 392 BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia);
393 BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
381 // center of mass is at the zero of the object 394 // center of mass is at the zero of the object
382 BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); 395 // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation);
383 // BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); 396 DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia);
384 DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, localInertia);
385 } 397 }
386 } 398 }
387 399
@@ -582,7 +594,7 @@ public sealed class BSPrim : BSPhysObject
582 // DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); 594 // DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical);
583 SetObjectDynamic(true); 595 SetObjectDynamic(true);
584 // whether phys-to-static or static-to-phys, the object is not moving. 596 // whether phys-to-static or static-to-phys, the object is not moving.
585 ZeroMotion(); 597 ZeroMotion(true);
586 }); 598 });
587 } 599 }
588 } 600 }
@@ -648,6 +660,7 @@ public sealed class BSPrim : BSPhysObject
648 // Recompute any linkset parameters. 660 // Recompute any linkset parameters.
649 // When going from non-physical to physical, this re-enables the constraints that 661 // When going from non-physical to physical, this re-enables the constraints that
650 // had been automatically disabled when the mass was set to zero. 662 // had been automatically disabled when the mass was set to zero.
663 // For compound based linksets, this enables and disables interactions of the children.
651 Linkset.Refresh(this); 664 Linkset.Refresh(this);
652 665
653 DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", 666 DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}",
@@ -666,9 +679,9 @@ public sealed class BSPrim : BSPhysObject
666 // Become a Bullet 'static' object type 679 // Become a Bullet 'static' object type
667 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); 680 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
668 // Stop all movement 681 // Stop all movement
669 ZeroMotion(); 682 ZeroMotion(true);
670 // Center of mass is at the center of the object 683 // Center of mass is at the center of the object
671 BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); 684 // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation);
672 // Mass is zero which disables a bunch of physics stuff in Bullet 685 // Mass is zero which disables a bunch of physics stuff in Bullet
673 UpdatePhysicalMassProperties(0f); 686 UpdatePhysicalMassProperties(0f);
674 // Set collision detection parameters 687 // Set collision detection parameters
@@ -704,7 +717,7 @@ public sealed class BSPrim : BSPhysObject
704 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 717 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
705 718
706 // Center of mass is at the center of the object 719 // Center of mass is at the center of the object
707 BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); 720 // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation);
708 721
709 // A dynamic object has mass 722 // A dynamic object has mass
710 UpdatePhysicalMassProperties(RawMass); 723 UpdatePhysicalMassProperties(RawMass);
@@ -958,6 +971,16 @@ public sealed class BSPrim : BSPhysObject
958 }); 971 });
959 } 972 }
960 973
974 public void ApplyForceImpulse(OMV.Vector3 impulse, bool inTaintTime)
975 {
976 OMV.Vector3 applyImpulse = impulse;
977 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyForceImpulse", delegate()
978 {
979 DetailLog("{0},BSPrim.ApplyForceImpulse,taint,tImpulse={1}", LocalID, applyImpulse);
980 BulletSimAPI.ApplyCentralImpulse2(PhysBody.ptr, applyImpulse);
981 });
982 }
983
961 private List<OMV.Vector3> m_accumulatedAngularForces = new List<OMV.Vector3>(); 984 private List<OMV.Vector3> m_accumulatedAngularForces = new List<OMV.Vector3>();
962 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { 985 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) {
963 AddAngularForce(force, pushforce, false); 986 AddAngularForce(force, pushforce, false);
@@ -1001,7 +1024,6 @@ public sealed class BSPrim : BSPhysObject
1001 OMV.Vector3 applyImpulse = impulse; 1024 OMV.Vector3 applyImpulse = impulse;
1002 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate() 1025 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate()
1003 { 1026 {
1004 DetailLog("{0},BSPrim.ApplyTorqueImpulse,taint,tImpulse={1}", LocalID, applyImpulse);
1005 BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); 1027 BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse);
1006 }); 1028 });
1007 } 1029 }
@@ -1315,9 +1337,10 @@ public sealed class BSPrim : BSPhysObject
1315 // If this prim is part of a linkset, we must remove and restore the physical 1337 // If this prim is part of a linkset, we must remove and restore the physical
1316 // links if the body is rebuilt. 1338 // links if the body is rebuilt.
1317 bool needToRestoreLinkset = false; 1339 bool needToRestoreLinkset = false;
1340 bool needToRestoreVehicle = false;
1318 1341
1319 // Create the correct physical representation for this type of object. 1342 // Create the correct physical representation for this type of object.
1320 // Updates BSBody and BSShape with the new information. 1343 // Updates PhysBody and PhysShape with the new information.
1321 // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary. 1344 // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary.
1322 // Returns 'true' if either the body or the shape was changed. 1345 // Returns 'true' if either the body or the shape was changed.
1323 PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, null, delegate(BulletBody dBody) 1346 PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, null, delegate(BulletBody dBody)
@@ -1326,6 +1349,7 @@ public sealed class BSPrim : BSPhysObject
1326 // Remove all the physical dependencies on the old body. 1349 // Remove all the physical dependencies on the old body.
1327 // (Maybe someday make the changing of BSShape an event handled by BSLinkset.) 1350 // (Maybe someday make the changing of BSShape an event handled by BSLinkset.)
1328 needToRestoreLinkset = Linkset.RemoveBodyDependencies(this); 1351 needToRestoreLinkset = Linkset.RemoveBodyDependencies(this);
1352 needToRestoreVehicle = _vehicle.RemoveBodyDependencies(this);
1329 }); 1353 });
1330 1354
1331 if (needToRestoreLinkset) 1355 if (needToRestoreLinkset)
@@ -1333,6 +1357,11 @@ public sealed class BSPrim : BSPhysObject
1333 // If physical body dependencies were removed, restore them 1357 // If physical body dependencies were removed, restore them
1334 Linkset.RestoreBodyDependencies(this); 1358 Linkset.RestoreBodyDependencies(this);
1335 } 1359 }
1360 if (needToRestoreVehicle)
1361 {
1362 // If physical body dependencies were removed, restore them
1363 _vehicle.RestoreBodyDependencies(this);
1364 }
1336 1365
1337 // Make sure the properties are set on the new object 1366 // Make sure the properties are set on the new object
1338 UpdatePhysicalParameters(); 1367 UpdatePhysicalParameters();