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.cs83
1 files changed, 54 insertions, 29 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 4d203ff..35d22c0 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -108,8 +108,8 @@ public sealed class BSPrim : BSPhysObject
108 _mass = CalculateMass(); 108 _mass = CalculateMass();
109 109
110 // No body or shape yet 110 // No body or shape yet
111 PhysBody = new BulletBody(LocalID, IntPtr.Zero); 111 PhysBody = new BulletBody(LocalID);
112 PhysShape = new BulletShape(IntPtr.Zero); 112 PhysShape = new BulletShape();
113 113
114 DetailLog("{0},BSPrim.constructor,call", LocalID); 114 DetailLog("{0},BSPrim.constructor,call", LocalID);
115 // do the actual object creation at taint time 115 // do the actual object creation at taint time
@@ -143,7 +143,9 @@ public sealed class BSPrim : BSPhysObject
143 DetailLog("{0},BSPrim.Destroy,taint,", LocalID); 143 DetailLog("{0},BSPrim.Destroy,taint,", LocalID);
144 // If there are physical body and shape, release my use of same. 144 // If there are physical body and shape, release my use of same.
145 PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null); 145 PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null);
146 PhysBody.Clear();
146 PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null); 147 PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null);
148 PhysShape.Clear();
147 }); 149 });
148 } 150 }
149 151
@@ -189,7 +191,8 @@ public sealed class BSPrim : BSPhysObject
189 } 191 }
190 } 192 }
191 public override bool Selected { 193 public override bool Selected {
192 set { 194 set
195 {
193 if (value != _isSelected) 196 if (value != _isSelected)
194 { 197 {
195 _isSelected = value; 198 _isSelected = value;
@@ -247,7 +250,8 @@ public sealed class BSPrim : BSPhysObject
247 // Zero some other properties in the physics engine 250 // Zero some other properties in the physics engine
248 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() 251 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate()
249 { 252 {
250 BulletSimAPI.ClearAllForces2(PhysBody.ptr); 253 if (PhysBody.HasPhysicalBody)
254 BulletSimAPI.ClearAllForces2(PhysBody.ptr);
251 }); 255 });
252 } 256 }
253 public override void ZeroAngularMotion(bool inTaintTime) 257 public override void ZeroAngularMotion(bool inTaintTime)
@@ -257,8 +261,11 @@ public sealed class BSPrim : BSPhysObject
257 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate() 261 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ZeroMotion", delegate()
258 { 262 {
259 // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); 263 // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity);
260 BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity); 264 if (PhysBody.HasPhysicalBody)
261 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); 265 {
266 BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
267 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
268 }
262 }); 269 });
263 } 270 }
264 271
@@ -295,8 +302,11 @@ public sealed class BSPrim : BSPhysObject
295 PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() 302 PhysicsScene.TaintedObject("BSPrim.setPosition", delegate()
296 { 303 {
297 // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 304 // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
298 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 305 if (PhysBody.HasPhysicalBody)
299 ActivateIfPhysical(false); 306 {
307 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
308 ActivateIfPhysical(false);
309 }
300 }); 310 });
301 } 311 }
302 } 312 }
@@ -322,12 +332,12 @@ public sealed class BSPrim : BSPhysObject
322 332
323 float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); 333 float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position);
324 OMV.Vector3 upForce = OMV.Vector3.Zero; 334 OMV.Vector3 upForce = OMV.Vector3.Zero;
325 if (Position.Z < terrainHeight) 335 if (RawPosition.Z < terrainHeight)
326 { 336 {
327 DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); 337 DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight);
328 float targetHeight = terrainHeight + (Size.Z / 2f); 338 float targetHeight = terrainHeight + (Size.Z / 2f);
329 // Upforce proportional to the distance away from the terrain. Correct the error in 1 sec. 339 // Upforce proportional to the distance away from the terrain. Correct the error in 1 sec.
330 upForce.Z = (terrainHeight - Position.Z) * 1f; 340 upForce.Z = (terrainHeight - RawPosition.Z) * 1f;
331 ret = true; 341 ret = true;
332 } 342 }
333 343
@@ -335,10 +345,10 @@ public sealed class BSPrim : BSPhysObject
335 { 345 {
336 float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position); 346 float waterHeight = PhysicsScene.TerrainManager.GetWaterLevelAtXYZ(_position);
337 // TODO: a floating motor so object will bob in the water 347 // TODO: a floating motor so object will bob in the water
338 if (Math.Abs(Position.Z - waterHeight) > 0.1f) 348 if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f)
339 { 349 {
340 // Upforce proportional to the distance away from the water. Correct the error in 1 sec. 350 // Upforce proportional to the distance away from the water. Correct the error in 1 sec.
341 upForce.Z = (waterHeight - Position.Z) * 1f; 351 upForce.Z = (waterHeight - RawPosition.Z) * 1f;
342 ret = true; 352 ret = true;
343 } 353 }
344 } 354 }
@@ -413,7 +423,8 @@ public sealed class BSPrim : BSPhysObject
413 PhysicsScene.TaintedObject("BSPrim.setForce", delegate() 423 PhysicsScene.TaintedObject("BSPrim.setForce", delegate()
414 { 424 {
415 // DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); 425 // DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force);
416 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force); 426 if (PhysBody.HasPhysicalBody)
427 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force);
417 }); 428 });
418 } 429 }
419 } 430 }
@@ -507,7 +518,8 @@ public sealed class BSPrim : BSPhysObject
507 PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() 518 PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate()
508 { 519 {
509 // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); 520 // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity);
510 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); 521 if (PhysBody.HasPhysicalBody)
522 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
511 }); 523 });
512 } 524 }
513 } 525 }
@@ -556,9 +568,12 @@ public sealed class BSPrim : BSPhysObject
556 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? 568 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint?
557 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() 569 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate()
558 { 570 {
559 // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); 571 if (PhysBody.HasPhysicalBody)
560 // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); 572 {
561 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); 573 // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr);
574 // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation);
575 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
576 }
562 }); 577 });
563 } 578 }
564 } 579 }
@@ -683,8 +698,9 @@ public sealed class BSPrim : BSPhysObject
683 ZeroMotion(true); 698 ZeroMotion(true);
684 699
685 // Set various physical properties so other object interact properly 700 // Set various physical properties so other object interact properly
686 BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction); 701 MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false);
687 BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution); 702 BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction);
703 BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution);
688 704
689 // Mass is zero which disables a bunch of physics stuff in Bullet 705 // Mass is zero which disables a bunch of physics stuff in Bullet
690 UpdatePhysicalMassProperties(0f); 706 UpdatePhysicalMassProperties(0f);
@@ -711,9 +727,10 @@ public sealed class BSPrim : BSPhysObject
711 // Not a Bullet static object 727 // Not a Bullet static object
712 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); 728 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
713 729
714 // Set various physical properties so internal dynamic properties will get computed correctly as they are set 730 // Set various physical properties so other object interact properly
715 BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction); 731 MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true);
716 BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution); 732 BulletSimAPI.SetFriction2(PhysBody.ptr, matAttrib.friction);
733 BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution);
717 734
718 // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 735 // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382
719 // Since this can be called multiple times, only zero forces when becoming physical 736 // Since this can be called multiple times, only zero forces when becoming physical
@@ -861,7 +878,8 @@ public sealed class BSPrim : BSPhysObject
861 PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() 878 PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate()
862 { 879 {
863 DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); 880 DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity);
864 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity); 881 if (PhysBody.HasPhysicalBody)
882 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, _rotationalVelocity);
865 }); 883 });
866 } 884 }
867 } 885 }
@@ -896,8 +914,11 @@ public sealed class BSPrim : BSPhysObject
896 _buoyancy = value; 914 _buoyancy = value;
897 // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 915 // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
898 // Buoyancy is faked by changing the gravity applied to the object 916 // Buoyancy is faked by changing the gravity applied to the object
899 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); 917 if (PhysBody.HasPhysicalBody)
900 BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); 918 {
919 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
920 BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav));
921 }
901 } 922 }
902 } 923 }
903 924
@@ -965,7 +986,8 @@ public sealed class BSPrim : BSPhysObject
965 } 986 }
966 DetailLog("{0},BSPrim.AddForce,taint,force={1}", LocalID, fSum); 987 DetailLog("{0},BSPrim.AddForce,taint,force={1}", LocalID, fSum);
967 if (fSum != OMV.Vector3.Zero) 988 if (fSum != OMV.Vector3.Zero)
968 BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum); 989 if (PhysBody.HasPhysicalBody)
990 BulletSimAPI.ApplyCentralForce2(PhysBody.ptr, fSum);
969 }); 991 });
970 } 992 }
971 993
@@ -976,7 +998,8 @@ public sealed class BSPrim : BSPhysObject
976 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyForceImpulse", delegate() 998 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyForceImpulse", delegate()
977 { 999 {
978 DetailLog("{0},BSPrim.ApplyForceImpulse,taint,tImpulse={1}", LocalID, applyImpulse); 1000 DetailLog("{0},BSPrim.ApplyForceImpulse,taint,tImpulse={1}", LocalID, applyImpulse);
979 BulletSimAPI.ApplyCentralImpulse2(PhysBody.ptr, applyImpulse); 1001 if (PhysBody.HasPhysicalBody)
1002 BulletSimAPI.ApplyCentralImpulse2(PhysBody.ptr, applyImpulse);
980 }); 1003 });
981 } 1004 }
982 1005
@@ -1012,7 +1035,8 @@ public sealed class BSPrim : BSPhysObject
1012 DetailLog("{0},BSPrim.AddAngularForce,taint,aForce={1}", LocalID, fSum); 1035 DetailLog("{0},BSPrim.AddAngularForce,taint,aForce={1}", LocalID, fSum);
1013 if (fSum != OMV.Vector3.Zero) 1036 if (fSum != OMV.Vector3.Zero)
1014 { 1037 {
1015 BulletSimAPI.ApplyTorque2(PhysBody.ptr, fSum); 1038 if (PhysBody.HasPhysicalBody)
1039 BulletSimAPI.ApplyTorque2(PhysBody.ptr, fSum);
1016 _torque = fSum; 1040 _torque = fSum;
1017 } 1041 }
1018 }); 1042 });
@@ -1026,7 +1050,8 @@ public sealed class BSPrim : BSPhysObject
1026 OMV.Vector3 applyImpulse = impulse; 1050 OMV.Vector3 applyImpulse = impulse;
1027 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate() 1051 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.ApplyTorqueImpulse", delegate()
1028 { 1052 {
1029 BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse); 1053 if (PhysBody.HasPhysicalBody)
1054 BulletSimAPI.ApplyTorqueImpulse2(PhysBody.ptr, applyImpulse);
1030 }); 1055 });
1031 } 1056 }
1032 1057