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.cs95
1 files changed, 44 insertions, 51 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index b2947c6..d43448e 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -51,12 +51,8 @@ public class BSPrim : BSPhysObject
51 private bool _isSelected; 51 private bool _isSelected;
52 private bool _isVolumeDetect; 52 private bool _isVolumeDetect;
53 53
54 // _position is what the simulator thinks the positions of the prim is.
55 private OMV.Vector3 _position;
56
57 private float _mass; // the mass of this object 54 private float _mass; // the mass of this object
58 private OMV.Vector3 _acceleration; 55 private OMV.Vector3 _acceleration;
59 private OMV.Quaternion _orientation;
60 private int _physicsActorType; 56 private int _physicsActorType;
61 private bool _isPhysical; 57 private bool _isPhysical;
62 private bool _flying; 58 private bool _flying;
@@ -88,10 +84,10 @@ public class BSPrim : BSPhysObject
88 { 84 {
89 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); 85 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
90 _physicsActorType = (int)ActorTypes.Prim; 86 _physicsActorType = (int)ActorTypes.Prim;
91 _position = pos; 87 RawPosition = pos;
92 _size = size; 88 _size = size;
93 Scale = size; // prims are the size the user wants them to be (different for BSCharactes). 89 Scale = size; // prims are the size the user wants them to be (different for BSCharactes).
94 _orientation = rotation; 90 RawOrientation = rotation;
95 _buoyancy = 0f; 91 _buoyancy = 0f;
96 RawVelocity = OMV.Vector3.Zero; 92 RawVelocity = OMV.Vector3.Zero;
97 _rotationalVelocity = OMV.Vector3.Zero; 93 _rotationalVelocity = OMV.Vector3.Zero;
@@ -270,46 +266,42 @@ public class BSPrim : BSPhysObject
270 return; 266 return;
271 } 267 }
272 268
273 public override OMV.Vector3 RawPosition
274 {
275 get { return _position; }
276 set { _position = value; }
277 }
278 public override OMV.Vector3 Position { 269 public override OMV.Vector3 Position {
279 get { 270 get {
280 // don't do the GetObjectPosition for root elements because this function is called a zillion times. 271 // don't do the GetObjectPosition for root elements because this function is called a zillion times.
281 // _position = ForcePosition; 272 // RawPosition = ForcePosition;
282 return _position; 273 return RawPosition;
283 } 274 }
284 set { 275 set {
285 // If the position must be forced into the physics engine, use ForcePosition. 276 // If the position must be forced into the physics engine, use ForcePosition.
286 // All positions are given in world positions. 277 // All positions are given in world positions.
287 if (_position == value) 278 if (RawPosition == value)
288 { 279 {
289 DetailLog("{0},BSPrim.setPosition,call,positionNotChanging,pos={1},orient={2}", LocalID, _position, _orientation); 280 DetailLog("{0},BSPrim.setPosition,call,positionNotChanging,pos={1},orient={2}", LocalID, RawPosition, RawOrientation);
290 return; 281 return;
291 } 282 }
292 _position = value; 283 RawPosition = value;
293 PositionSanityCheck(false); 284 PositionSanityCheck(false);
294 285
295 PhysScene.TaintedObject("BSPrim.setPosition", delegate() 286 PhysScene.TaintedObject("BSPrim.setPosition", delegate()
296 { 287 {
297 DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 288 DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, RawPosition, RawOrientation);
298 ForcePosition = _position; 289 ForcePosition = RawPosition;
299 }); 290 });
300 } 291 }
301 } 292 }
302 293
294 // NOTE: overloaded by BSPrimDisplaced to handle offset for center-of-gravity.
303 public override OMV.Vector3 ForcePosition { 295 public override OMV.Vector3 ForcePosition {
304 get { 296 get {
305 _position = PhysScene.PE.GetPosition(PhysBody); 297 RawPosition = PhysScene.PE.GetPosition(PhysBody);
306 return _position; 298 return RawPosition;
307 } 299 }
308 set { 300 set {
309 _position = value; 301 RawPosition = value;
310 if (PhysBody.HasPhysicalBody) 302 if (PhysBody.HasPhysicalBody)
311 { 303 {
312 PhysScene.PE.SetTranslation(PhysBody, _position, _orientation); 304 PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation);
313 ActivateIfPhysical(false); 305 ActivateIfPhysical(false);
314 } 306 }
315 } 307 }
@@ -343,10 +335,10 @@ public class BSPrim : BSPhysObject
343 float targetHeight = terrainHeight + (Size.Z / 2f); 335 float targetHeight = terrainHeight + (Size.Z / 2f);
344 // If the object is below ground it just has to be moved up because pushing will 336 // If the object is below ground it just has to be moved up because pushing will
345 // not get it through the terrain 337 // not get it through the terrain
346 _position.Z = targetHeight; 338 RawPosition = new OMV.Vector3(RawPosition.X, RawPosition.Y, targetHeight);
347 if (inTaintTime) 339 if (inTaintTime)
348 { 340 {
349 ForcePosition = _position; 341 ForcePosition = RawPosition;
350 } 342 }
351 // If we are throwing the object around, zero its other forces 343 // If we are throwing the object around, zero its other forces
352 ZeroMotion(inTaintTime); 344 ZeroMotion(inTaintTime);
@@ -355,7 +347,7 @@ public class BSPrim : BSPhysObject
355 347
356 if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) 348 if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0)
357 { 349 {
358 float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(_position); 350 float waterHeight = PhysScene.TerrainManager.GetWaterLevelAtXYZ(RawPosition);
359 // TODO: a floating motor so object will bob in the water 351 // TODO: a floating motor so object will bob in the water
360 if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f) 352 if (Math.Abs(RawPosition.Z - waterHeight) > 0.1f)
361 { 353 {
@@ -364,7 +356,7 @@ public class BSPrim : BSPhysObject
364 356
365 // Apply upforce and overcome gravity. 357 // Apply upforce and overcome gravity.
366 OMV.Vector3 correctionForce = upForce - PhysScene.DefaultGravity; 358 OMV.Vector3 correctionForce = upForce - PhysScene.DefaultGravity;
367 DetailLog("{0},BSPrim.PositionSanityCheck,applyForce,pos={1},upForce={2},correctionForce={3}", LocalID, _position, upForce, correctionForce); 359 DetailLog("{0},BSPrim.PositionSanityCheck,applyForce,pos={1},upForce={2},correctionForce={3}", LocalID, RawPosition, upForce, correctionForce);
368 AddForce(correctionForce, false, inTaintTime); 360 AddForce(correctionForce, false, inTaintTime);
369 ret = true; 361 ret = true;
370 } 362 }
@@ -383,11 +375,11 @@ public class BSPrim : BSPhysObject
383 uint wayOutThere = Constants.RegionSize * Constants.RegionSize; 375 uint wayOutThere = Constants.RegionSize * Constants.RegionSize;
384 // There have been instances of objects getting thrown way out of bounds and crashing 376 // There have been instances of objects getting thrown way out of bounds and crashing
385 // the border crossing code. 377 // the border crossing code.
386 if ( _position.X < -Constants.RegionSize || _position.X > wayOutThere 378 if ( RawPosition.X < -Constants.RegionSize || RawPosition.X > wayOutThere
387 || _position.Y < -Constants.RegionSize || _position.Y > wayOutThere 379 || RawPosition.Y < -Constants.RegionSize || RawPosition.Y > wayOutThere
388 || _position.Z < -Constants.RegionSize || _position.Z > wayOutThere) 380 || RawPosition.Z < -Constants.RegionSize || RawPosition.Z > wayOutThere)
389 { 381 {
390 _position = new OMV.Vector3(10, 10, 50); 382 RawPosition = new OMV.Vector3(10, 10, 50);
391 ZeroMotion(inTaintTime); 383 ZeroMotion(inTaintTime);
392 ret = true; 384 ret = true;
393 } 385 }
@@ -713,23 +705,19 @@ public class BSPrim : BSPhysObject
713 get { return _acceleration; } 705 get { return _acceleration; }
714 set { _acceleration = value; } 706 set { _acceleration = value; }
715 } 707 }
716 public override OMV.Quaternion RawOrientation 708
717 {
718 get { return _orientation; }
719 set { _orientation = value; }
720 }
721 public override OMV.Quaternion Orientation { 709 public override OMV.Quaternion Orientation {
722 get { 710 get {
723 return _orientation; 711 return RawOrientation;
724 } 712 }
725 set { 713 set {
726 if (_orientation == value) 714 if (RawOrientation == value)
727 return; 715 return;
728 _orientation = value; 716 RawOrientation = value;
729 717
730 PhysScene.TaintedObject("BSPrim.setOrientation", delegate() 718 PhysScene.TaintedObject("BSPrim.setOrientation", delegate()
731 { 719 {
732 ForceOrientation = _orientation; 720 ForceOrientation = RawOrientation;
733 }); 721 });
734 } 722 }
735 } 723 }
@@ -738,14 +726,14 @@ public class BSPrim : BSPhysObject
738 { 726 {
739 get 727 get
740 { 728 {
741 _orientation = PhysScene.PE.GetOrientation(PhysBody); 729 RawOrientation = PhysScene.PE.GetOrientation(PhysBody);
742 return _orientation; 730 return RawOrientation;
743 } 731 }
744 set 732 set
745 { 733 {
746 _orientation = value; 734 RawOrientation = value;
747 if (PhysBody.HasPhysicalBody) 735 if (PhysBody.HasPhysicalBody)
748 PhysScene.PE.SetTranslation(PhysBody, _position, _orientation); 736 PhysScene.PE.SetTranslation(PhysBody, RawPosition, RawOrientation);
749 } 737 }
750 } 738 }
751 public override int PhysicsActorType { 739 public override int PhysicsActorType {
@@ -802,6 +790,7 @@ public class BSPrim : BSPhysObject
802 // isSolid: other objects bounce off of this object 790 // isSolid: other objects bounce off of this object
803 // isVolumeDetect: other objects pass through but can generate collisions 791 // isVolumeDetect: other objects pass through but can generate collisions
804 // collisionEvents: whether this object returns collision events 792 // collisionEvents: whether this object returns collision events
793 // NOTE: overloaded by BSPrimLinkable to also update linkset physical parameters.
805 public virtual void UpdatePhysicalParameters() 794 public virtual void UpdatePhysicalParameters()
806 { 795 {
807 if (!PhysBody.HasPhysicalBody) 796 if (!PhysBody.HasPhysicalBody)
@@ -888,7 +877,7 @@ public class BSPrim : BSPhysObject
888 // PhysicsScene.PE.ClearAllForces(BSBody); 877 // PhysicsScene.PE.ClearAllForces(BSBody);
889 878
890 // For good measure, make sure the transform is set through to the motion state 879 // For good measure, make sure the transform is set through to the motion state
891 ForcePosition = _position; 880 ForcePosition = RawPosition;
892 ForceVelocity = RawVelocity; 881 ForceVelocity = RawVelocity;
893 ForceRotationalVelocity = _rotationalVelocity; 882 ForceRotationalVelocity = _rotationalVelocity;
894 883
@@ -1125,7 +1114,9 @@ public class BSPrim : BSPhysObject
1125 OMV.Vector3 addForce = force; 1114 OMV.Vector3 addForce = force;
1126 PhysScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() 1115 PhysScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate()
1127 { 1116 {
1128 // Bullet adds this central force to the total force for this tick 1117 // Bullet adds this central force to the total force for this tick.
1118 // Deep down in Bullet:
1119 // linearVelocity += totalForce / mass * timeStep;
1129 DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce); 1120 DetailLog("{0},BSPrim.addForce,taint,force={1}", LocalID, addForce);
1130 if (PhysBody.HasPhysicalBody) 1121 if (PhysBody.HasPhysicalBody)
1131 { 1122 {
@@ -1493,6 +1484,8 @@ public class BSPrim : BSPhysObject
1493 1484
1494 returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass); 1485 returnMass = Util.Clamp(returnMass, BSParam.MinimumObjectMass, BSParam.MaximumObjectMass);
1495 // DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3}", LocalID, Density, volume, returnMass); 1486 // DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3}", LocalID, Density, volume, returnMass);
1487 DetailLog("{0},BSPrim.CalculateMass,den={1},vol={2},mass={3},pathB={4},pathE={5},profB={6},profE={7},siz={8}",
1488 LocalID, Density, volume, returnMass, pathBegin, pathEnd, profileBegin, profileEnd, _size);
1496 1489
1497 return returnMass; 1490 return returnMass;
1498 }// end CalculateMass 1491 }// end CalculateMass
@@ -1528,6 +1521,8 @@ public class BSPrim : BSPhysObject
1528 1521
1529 // The physics engine says that properties have updated. Update same and inform 1522 // The physics engine says that properties have updated. Update same and inform
1530 // the world that things have changed. 1523 // the world that things have changed.
1524 // NOTE: BSPrim.UpdateProperties is overloaded by BSPrimLinkable which modifies updates from root and children prims.
1525 // NOTE: BSPrim.UpdateProperties is overloaded by BSPrimDisplaced which handles mapping physical position to simulator position.
1531 public override void UpdateProperties(EntityProperties entprop) 1526 public override void UpdateProperties(EntityProperties entprop)
1532 { 1527 {
1533 // Let anyone (like the actors) modify the updated properties before they are pushed into the object and the simulator. 1528 // Let anyone (like the actors) modify the updated properties before they are pushed into the object and the simulator.
@@ -1536,8 +1531,8 @@ public class BSPrim : BSPhysObject
1536 // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG 1531 // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG
1537 1532
1538 // Assign directly to the local variables so the normal set actions do not happen 1533 // Assign directly to the local variables so the normal set actions do not happen
1539 _position = entprop.Position; 1534 RawPosition = entprop.Position;
1540 _orientation = entprop.Rotation; 1535 RawOrientation = entprop.Rotation;
1541 // DEBUG DEBUG DEBUG -- smooth velocity changes a bit. The simulator seems to be 1536 // DEBUG DEBUG DEBUG -- smooth velocity changes a bit. The simulator seems to be
1542 // very sensitive to velocity changes. 1537 // very sensitive to velocity changes.
1543 if (entprop.Velocity == OMV.Vector3.Zero || !entprop.Velocity.ApproxEquals(RawVelocity, BSParam.UpdateVelocityChangeThreshold)) 1538 if (entprop.Velocity == OMV.Vector3.Zero || !entprop.Velocity.ApproxEquals(RawVelocity, BSParam.UpdateVelocityChangeThreshold))
@@ -1550,21 +1545,19 @@ public class BSPrim : BSPhysObject
1550 // The sanity check can change the velocity and/or position. 1545 // The sanity check can change the velocity and/or position.
1551 if (PositionSanityCheck(true /* inTaintTime */ )) 1546 if (PositionSanityCheck(true /* inTaintTime */ ))
1552 { 1547 {
1553 entprop.Position = _position; 1548 entprop.Position = RawPosition;
1554 entprop.Velocity = RawVelocity; 1549 entprop.Velocity = RawVelocity;
1555 entprop.RotationalVelocity = _rotationalVelocity; 1550 entprop.RotationalVelocity = _rotationalVelocity;
1556 entprop.Acceleration = _acceleration; 1551 entprop.Acceleration = _acceleration;
1557 } 1552 }
1558 1553
1559 OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG 1554 OMV.Vector3 direction = OMV.Vector3.UnitX * RawOrientation; // DEBUG DEBUG DEBUG
1560 DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction); 1555 DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction);
1561 1556
1562 // remember the current and last set values 1557 // remember the current and last set values
1563 LastEntityProperties = CurrentEntityProperties; 1558 LastEntityProperties = CurrentEntityProperties;
1564 CurrentEntityProperties = entprop; 1559 CurrentEntityProperties = entprop;
1565 1560
1566 // Note that BSPrim can be overloaded by BSPrimLinkable which controls updates from root and children prims.
1567
1568 PhysScene.PostUpdate(this); 1561 PhysScene.PostUpdate(this);
1569 } 1562 }
1570} 1563}