aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
diff options
context:
space:
mode:
authorteravus2012-12-18 15:00:10 -0500
committerteravus2012-12-18 15:00:10 -0500
commit29cdf0f3dd99605192f29fc83bbacdf8ecb0ea8d (patch)
tree9b8eda52bcd2022e47b0b0688eb9d548b4161f36 /OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
parentBulletSim: scale the force for external AddForce by the simulation (diff)
downloadopensim-SC-29cdf0f3dd99605192f29fc83bbacdf8ecb0ea8d.zip
opensim-SC-29cdf0f3dd99605192f29fc83bbacdf8ecb0ea8d.tar.gz
opensim-SC-29cdf0f3dd99605192f29fc83bbacdf8ecb0ea8d.tar.bz2
opensim-SC-29cdf0f3dd99605192f29fc83bbacdf8ecb0ea8d.tar.xz
* Merges BulletSim Updates to BulletSimN(BulletSNPlugin)
Diffstat (limited to 'OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs87
1 files changed, 59 insertions, 28 deletions
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
index a889c24..9c4ba30 100644
--- a/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSNPlugin/BSPrim.cs
@@ -115,6 +115,8 @@ public sealed class BSPrim : BSPhysObject
115 PhysBody = new BulletBody(LocalID); 115 PhysBody = new BulletBody(LocalID);
116 PhysShape = new BulletShape(); 116 PhysShape = new BulletShape();
117 117
118 Linkset.Refresh(this);
119
118 DetailLog("{0},BSPrim.constructor,call", LocalID); 120 DetailLog("{0},BSPrim.constructor,call", LocalID);
119 // do the actual object creation at taint time 121 // do the actual object creation at taint time
120 PhysicsScene.TaintedObject("BSPrim.create", delegate() 122 PhysicsScene.TaintedObject("BSPrim.create", delegate()
@@ -384,13 +386,13 @@ public sealed class BSPrim : BSPhysObject
384 } 386 }
385 387
386 // Return the effective mass of the object. 388 // Return the effective mass of the object.
387 // If there are multiple items in the linkset, add them together for the root 389 // The definition of this call is to return the mass of the prim.
390 // If the simulator cares about the mass of the linkset, it will sum it itself.
388 public override float Mass 391 public override float Mass
389 { 392 {
390 get 393 get
391 { 394 {
392 return Linkset.LinksetMass; 395 return _mass;
393 // return _mass;
394 } 396 }
395 } 397 }
396 398
@@ -400,22 +402,45 @@ public sealed class BSPrim : BSPhysObject
400 } 402 }
401 // Set the physical mass to the passed mass. 403 // Set the physical mass to the passed mass.
402 // Note that this does not change _mass! 404 // Note that this does not change _mass!
403 public override void UpdatePhysicalMassProperties(float physMass) 405 public override void UpdatePhysicalMassProperties(float physMass, bool inWorld)
404 { 406 {
405 if (IsStatic) 407 if (PhysBody.HasPhysicalBody)
406 { 408 {
407 Inertia = OMV.Vector3.Zero; 409 if (IsStatic)
408 BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); 410 {
409 BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); 411 Inertia = OMV.Vector3.Zero;
410 } 412 BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia);
411 else 413 BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
412 { 414 }
413 Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); 415 else
414 BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); 416 {
415 BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); 417 if (inWorld)
416 // center of mass is at the zero of the object 418 {
417 // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); 419 // Changing interesting properties doesn't change proxy and collision cache
418 DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia); 420 // information. The Bullet solution is to re-add the object to the world
421 // after parameters are changed.
422 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
423 }
424
425 Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
426 BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia);
427 BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr);
428
429 // center of mass is at the zero of the object
430 // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation);
431 DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},inWorld={3}", LocalID, physMass, Inertia, inWorld);
432
433 if (inWorld)
434 {
435 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr,_position,_orientation);
436 }
437
438 // Must set gravity after it has been added to the world because, for unknown reasons,
439 // adding the object resets the object's gravity to world gravity
440 OMV.Vector3 grav = PhysicsScene.DefaultGravity * (1f - Buoyancy);
441 BulletSimAPI.SetGravity2(PhysBody.ptr, grav);
442
443 }
419 } 444 }
420 } 445 }
421 446
@@ -714,7 +739,7 @@ public sealed class BSPrim : BSPhysObject
714 Linkset.Refresh(this); 739 Linkset.Refresh(this);
715 740
716 DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", 741 DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}",
717 LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape); 742 LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape);
718 } 743 }
719 744
720 // "Making dynamic" means changing to and from static. 745 // "Making dynamic" means changing to and from static.
@@ -737,7 +762,7 @@ public sealed class BSPrim : BSPhysObject
737 BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); 762 BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution);
738 763
739 // Mass is zero which disables a bunch of physics stuff in Bullet 764 // Mass is zero which disables a bunch of physics stuff in Bullet
740 UpdatePhysicalMassProperties(0f); 765 UpdatePhysicalMassProperties(0f, false);
741 // Set collision detection parameters 766 // Set collision detection parameters
742 if (BSParam.CcdMotionThreshold > 0f) 767 if (BSParam.CcdMotionThreshold > 0f)
743 { 768 {
@@ -777,7 +802,7 @@ public sealed class BSPrim : BSPhysObject
777 // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); 802 // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation);
778 803
779 // A dynamic object has mass 804 // A dynamic object has mass
780 UpdatePhysicalMassProperties(RawMass); 805 UpdatePhysicalMassProperties(RawMass, false);
781 806
782 // Set collision detection parameters 807 // Set collision detection parameters
783 if (BSParam.CcdMotionThreshold > 0f) 808 if (BSParam.CcdMotionThreshold > 0f)
@@ -950,13 +975,9 @@ public sealed class BSPrim : BSPhysObject
950 set { 975 set {
951 _buoyancy = value; 976 _buoyancy = value;
952 // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 977 // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
953 // Buoyancy is faked by changing the gravity applied to the object 978 // Force the recalculation of the various inertia,etc variables in the object
954 if (PhysBody.HasPhysicalBody) 979 UpdatePhysicalMassProperties(_mass, true);
955 { 980 ActivateIfPhysical(false);
956 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
957 BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav));
958 ActivateIfPhysical(false);
959 }
960 } 981 }
961 } 982 }
962 983
@@ -993,7 +1014,9 @@ public sealed class BSPrim : BSPhysObject
993 public override float APIDDamping { set { return; } } 1014 public override float APIDDamping { set { return; } }
994 1015
995 public override void AddForce(OMV.Vector3 force, bool pushforce) { 1016 public override void AddForce(OMV.Vector3 force, bool pushforce) {
996 AddForce(force, pushforce, false); 1017 // Since this force is being applied in only one step, make this a force per second.
1018 OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep;
1019 AddForce(addForce, pushforce, false);
997 } 1020 }
998 // Applying a force just adds this to the total force on the object. 1021 // Applying a force just adds this to the total force on the object.
999 // This added force will only last the next simulation tick. 1022 // This added force will only last the next simulation tick.
@@ -1001,8 +1024,16 @@ public sealed class BSPrim : BSPhysObject
1001 // for an object, doesn't matter if force is a pushforce or not 1024 // for an object, doesn't matter if force is a pushforce or not
1002 if (force.IsFinite()) 1025 if (force.IsFinite())
1003 { 1026 {
1027 float magnitude = force.Length();
1028 if (magnitude > 20000f)
1029 {
1030 // Force has a limit
1031 force = force / magnitude * 20000f;
1032 }
1033
1004 OMV.Vector3 addForce = force; 1034 OMV.Vector3 addForce = force;
1005 DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); 1035 DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce);
1036
1006 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() 1037 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate()
1007 { 1038 {
1008 // Bullet adds this central force to the total force for this tick 1039 // Bullet adds this central force to the total force for this tick