aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
authorRobert Adams2011-08-05 11:01:27 -0700
committerMic Bowman2011-08-05 11:01:27 -0700
commit7640b5abf651e51ae2efd5f79f440768a595dbc9 (patch)
tree0b96cd6d2749f95888566f3e04f9798e04c21acd /OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
parentBulletSim: Update dlls (diff)
downloadopensim-SC-7640b5abf651e51ae2efd5f79f440768a595dbc9.zip
opensim-SC-7640b5abf651e51ae2efd5f79f440768a595dbc9.tar.gz
opensim-SC-7640b5abf651e51ae2efd5f79f440768a595dbc9.tar.bz2
opensim-SC-7640b5abf651e51ae2efd5f79f440768a595dbc9.tar.xz
BulletSim: Parameters settable from ini file. Linksets. Physical property value tuning
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs267
1 files changed, 154 insertions, 113 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index f2ab2d9..04cb452 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -71,6 +71,7 @@ public sealed class BSPrim : PhysicsActor
71 private bool _isPhysical; 71 private bool _isPhysical;
72 private bool _flying; 72 private bool _flying;
73 private float _friction; 73 private float _friction;
74 private float _restitution;
74 private bool _setAlwaysRun; 75 private bool _setAlwaysRun;
75 private bool _throttleUpdates; 76 private bool _throttleUpdates;
76 private bool _isColliding; 77 private bool _isColliding;
@@ -101,7 +102,7 @@ public sealed class BSPrim : PhysicsActor
101 private float _PIDHoverTao; 102 private float _PIDHoverTao;
102 103
103 public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, 104 public BSPrim(uint localID, String primName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size,
104 OMV.Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical) 105 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
105 { 106 {
106 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); 107 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
107 _localID = localID; 108 _localID = localID;
@@ -113,15 +114,16 @@ public sealed class BSPrim : PhysicsActor
113 _orientation = rotation; 114 _orientation = rotation;
114 _buoyancy = 1f; 115 _buoyancy = 1f;
115 _velocity = OMV.Vector3.Zero; 116 _velocity = OMV.Vector3.Zero;
117 _rotationalVelocity = OMV.Vector3.Zero;
116 _angularVelocity = OMV.Vector3.Zero; 118 _angularVelocity = OMV.Vector3.Zero;
117 _mesh = mesh;
118 _hullKey = 0; 119 _hullKey = 0;
119 _pbs = pbs; 120 _pbs = pbs;
120 _isPhysical = pisPhysical; 121 _isPhysical = pisPhysical;
121 _isVolumeDetect = false; 122 _isVolumeDetect = false;
122 _subscribedEventsMs = 0; 123 _subscribedEventsMs = 0;
123 _friction = _scene.DefaultFriction; // TODO: compute based on object material 124 _friction = _scene.Params.defaultFriction; // TODO: compute based on object material
124 _density = _scene.DefaultDensity; // TODO: compute based on object material 125 _density = _scene.Params.defaultDensity; // TODO: compute based on object material
126 _restitution = _scene.Params.defaultRestitution;
125 _parentPrim = null; // not a child or a parent 127 _parentPrim = null; // not a child or a parent
126 _vehicle = new BSDynamics(this); // add vehicleness 128 _vehicle = new BSDynamics(this); // add vehicleness
127 _childrenPrims = new List<BSPrim>(); 129 _childrenPrims = new List<BSPrim>();
@@ -132,8 +134,7 @@ public sealed class BSPrim : PhysicsActor
132 // do the actual object creation at taint time 134 // do the actual object creation at taint time
133 _scene.TaintedObject(delegate() 135 _scene.TaintedObject(delegate()
134 { 136 {
135 CreateGeom(); 137 RecreateGeomAndObject();
136 CreateObject();
137 }); 138 });
138 } 139 }
139 140
@@ -239,6 +240,7 @@ public sealed class BSPrim : PhysicsActor
239 return; 240 return;
240 } 241 }
241 242
243 // I am the root of a linkset and a new child is being added
242 public void AddChildToLinkset(BSPrim pchild) 244 public void AddChildToLinkset(BSPrim pchild)
243 { 245 {
244 BSPrim child = pchild; 246 BSPrim child = pchild;
@@ -254,6 +256,8 @@ public sealed class BSPrim : PhysicsActor
254 return; 256 return;
255 } 257 }
256 258
259 // I am the root of a linkset and one of my children is being removed.
260 // Safe to call even if the child is not really in my linkset.
257 public void RemoveChildFromLinkset(BSPrim pchild) 261 public void RemoveChildFromLinkset(BSPrim pchild)
258 { 262 {
259 BSPrim child = pchild; 263 BSPrim child = pchild;
@@ -290,6 +294,17 @@ public sealed class BSPrim : PhysicsActor
290 get { return (_parentPrim == null && _childrenPrims.Count != 0); } 294 get { return (_parentPrim == null && _childrenPrims.Count != 0); }
291 } 295 }
292 296
297 // Set motion values to zero.
298 // Do it to the properties so the values get set in the physics engine.
299 // Push the setting of the values to the viewer.
300 private void ZeroMotion()
301 {
302 Velocity = OMV.Vector3.Zero;
303 _acceleration = OMV.Vector3.Zero;
304 RotationalVelocity = OMV.Vector3.Zero;
305 base.RequestPhysicsterseUpdate();
306 }
307
293 public override void LockAngularMotion(OMV.Vector3 axis) { return; } 308 public override void LockAngularMotion(OMV.Vector3 axis) { return; }
294 309
295 public override OMV.Vector3 Position { 310 public override OMV.Vector3 Position {
@@ -390,18 +405,6 @@ public sealed class BSPrim : PhysicsActor
390 }); 405 });
391 } 406 }
392 } 407 }
393 public OMV.Vector3 AngularVelocity
394 {
395 get { return _angularVelocity; }
396 set
397 {
398 _angularVelocity = value;
399 _scene.TaintedObject(delegate()
400 {
401 BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _angularVelocity);
402 });
403 }
404 }
405 public override OMV.Vector3 Torque { 408 public override OMV.Vector3 Torque {
406 get { return _torque; } 409 get { return _torque; }
407 set { _torque = value; 410 set { _torque = value;
@@ -419,11 +422,11 @@ public sealed class BSPrim : PhysicsActor
419 get { return _orientation; } 422 get { return _orientation; }
420 set { 423 set {
421 _orientation = value; 424 _orientation = value;
425 // m_log.DebugFormat("{0}: set orientation: id={1}, ori={2}", LogHeader, LocalID, _orientation);
422 _scene.TaintedObject(delegate() 426 _scene.TaintedObject(delegate()
423 { 427 {
424 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); 428 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
425 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); 429 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
426 // m_log.DebugFormat("{0}: set orientation: {1}", LogHeader, _orientation);
427 }); 430 });
428 } 431 }
429 } 432 }
@@ -505,8 +508,16 @@ public sealed class BSPrim : PhysicsActor
505 get { return _rotationalVelocity; } 508 get { return _rotationalVelocity; }
506 set { _rotationalVelocity = value; 509 set { _rotationalVelocity = value;
507 // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); 510 // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity);
511 _scene.TaintedObject(delegate()
512 {
513 BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity);
514 });
508 } 515 }
509 } 516 }
517 public OMV.Vector3 AngularVelocity {
518 get { return _angularVelocity; }
519 set { _angularVelocity = value; }
520 }
510 public override bool Kinematic { 521 public override bool Kinematic {
511 get { return _kinematic; } 522 get { return _kinematic; }
512 set { _kinematic = value; 523 set { _kinematic = value;
@@ -866,9 +877,6 @@ public sealed class BSPrim : PhysicsActor
866 877
867 returnMass = _density * volume; 878 returnMass = _density * volume;
868 879
869 if (returnMass <= 0)
870 returnMass = 0.0001f;//ckrinke: Mass must be greater then zero.
871
872 if (IsRootOfLinkset) 880 if (IsRootOfLinkset)
873 { 881 {
874 foreach (BSPrim prim in _childrenPrims) 882 foreach (BSPrim prim in _childrenPrims)
@@ -877,8 +885,12 @@ public sealed class BSPrim : PhysicsActor
877 } 885 }
878 } 886 }
879 887
880 if (returnMass > _scene.maximumMassObject) 888 if (returnMass <= 0)
881 returnMass = _scene.maximumMassObject; 889 returnMass = 0.0001f;
890
891 if (returnMass > _scene.MaximumObjectMass)
892 returnMass = _scene.MaximumObjectMass;
893
882 return returnMass; 894 return returnMass;
883 }// end CalculateMass 895 }// end CalculateMass
884 #endregion Mass Calculation 896 #endregion Mass Calculation
@@ -887,6 +899,15 @@ public sealed class BSPrim : PhysicsActor
887 // No locking here because this is done when we know physics is not simulating 899 // No locking here because this is done when we know physics is not simulating
888 private void CreateGeom() 900 private void CreateGeom()
889 { 901 {
902 // Since we're recreating new, get rid of any previously generated shape
903 if (_hullKey != 0)
904 {
905 // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey);
906 BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey);
907 _hullKey = 0;
908 _hulls.Clear();
909 }
910
890 if (_mesh == null) 911 if (_mesh == null)
891 { 912 {
892 // the mesher thought this was too simple to mesh. Use a native Bullet collision shape. 913 // the mesher thought this was too simple to mesh. Use a native Bullet collision shape.
@@ -902,21 +923,13 @@ public sealed class BSPrim : PhysicsActor
902 } 923 }
903 else 924 else
904 { 925 {
905 // m_log.DebugFormat("{0}: CreateGeom: mesh null. Defaulting to box of size {1}", LogHeader, _size); 926 // m_log.DebugFormat("{0}: CreateGeom: mesh null. Defaulting to box. lid={1}, size={2}", LogHeader, LocalID, _size);
906 _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX; 927 _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX;
907 _scale = _size; 928 _scale = _size;
908 } 929 }
909 } 930 }
910 else 931 else
911 { 932 {
912 if (_hullKey != 0)
913 {
914 // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey);
915 BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey);
916 _hullKey = 0;
917 _hulls.Clear();
918 }
919
920 int[] indices = _mesh.getIndexListAsInt(); 933 int[] indices = _mesh.getIndexListAsInt();
921 List<OMV.Vector3> vertices = _mesh.getVertexList(); 934 List<OMV.Vector3> vertices = _mesh.getVertexList();
922 935
@@ -997,7 +1010,7 @@ public sealed class BSPrim : PhysicsActor
997 1010
998 // create the hull definition in Bullet 1011 // create the hull definition in Bullet
999 _hullKey = (ulong)_pbs.GetHashCode(); 1012 _hullKey = (ulong)_pbs.GetHashCode();
1000 // m_log.DebugFormat("{0}: CreateGeom: calling CreateHull. lid= {1}, key={2}, hulls={3}", LogHeader, _localID, _hullKey, hullCount); 1013 // m_log.DebugFormat("{0}: CreateGeom: calling CreateHull. lid={1}, key={2}, hulls={3}", LogHeader, _localID, _hullKey, hullCount);
1001 BulletSimAPI.CreateHull(_scene.WorldID, _hullKey, hullCount, convHulls); 1014 BulletSimAPI.CreateHull(_scene.WorldID, _hullKey, hullCount, convHulls);
1002 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; 1015 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL;
1003 // meshes are already scaled by the meshmerizer 1016 // meshes are already scaled by the meshmerizer
@@ -1006,6 +1019,8 @@ public sealed class BSPrim : PhysicsActor
1006 return; 1019 return;
1007 } 1020 }
1008 1021
1022 // Callback from convex hull creater with a newly created hull.
1023 // Just add it to the collection of hulls for this shape.
1009 private void HullReturn(ConvexResult result) 1024 private void HullReturn(ConvexResult result)
1010 { 1025 {
1011 _hulls.Add(result); 1026 _hulls.Add(result);
@@ -1019,13 +1034,12 @@ public sealed class BSPrim : PhysicsActor
1019 if (IsRootOfLinkset) 1034 if (IsRootOfLinkset)
1020 { 1035 {
1021 // Create a linkset around this object 1036 // Create a linkset around this object
1022 CreateLinksetWithCompoundHull(); 1037 // CreateLinksetWithCompoundHull();
1023 // CreateLinksetWithConstraints(); 1038 CreateLinksetWithConstraints();
1024 } 1039 }
1025 else 1040 else
1026 { 1041 {
1027 // simple object 1042 // simple object
1028 // m_log.DebugFormat("{0}: CreateObject. ID={1}", LogHeader, LocalID);
1029 ShapeData shape; 1043 ShapeData shape;
1030 FillShapeInfo(out shape); 1044 FillShapeInfo(out shape);
1031 BulletSimAPI.CreateObject(_scene.WorldID, shape); 1045 BulletSimAPI.CreateObject(_scene.WorldID, shape);
@@ -1034,6 +1048,7 @@ public sealed class BSPrim : PhysicsActor
1034 1048
1035 // Create a linkset by creating a compound hull at the root prim that consists of all 1049 // Create a linkset by creating a compound hull at the root prim that consists of all
1036 // the children. 1050 // the children.
1051 // NOTE: This does not allow proper collisions with the children prims so it is not a workable solution
1037 void CreateLinksetWithCompoundHull() 1052 void CreateLinksetWithCompoundHull()
1038 { 1053 {
1039 // If I am the root prim of a linkset, replace my physical shape with all the 1054 // If I am the root prim of a linkset, replace my physical shape with all the
@@ -1055,8 +1070,27 @@ public sealed class BSPrim : PhysicsActor
1055 BulletSimAPI.CreateLinkset(_scene.WorldID, totalPrimsInLinkset, shapes); 1070 BulletSimAPI.CreateLinkset(_scene.WorldID, totalPrimsInLinkset, shapes);
1056 } 1071 }
1057 1072
1073 // Copy prim's info into the BulletSim shape description structure
1074 public void FillShapeInfo(out ShapeData shape)
1075 {
1076 shape.ID = _localID;
1077 shape.Type = _shapeType;
1078 shape.Position = _position;
1079 shape.Rotation = _orientation;
1080 shape.Velocity = _velocity;
1081 shape.Scale = _scale;
1082 shape.Mass = _isPhysical ? _mass : 0f;
1083 shape.Buoyancy = _buoyancy;
1084 shape.MeshKey = _hullKey;
1085 shape.Friction = _friction;
1086 shape.Restitution = _restitution;
1087 shape.Collidable = (!IsPhantom) ? ShapeData.numericTrue : ShapeData.numericFalse;
1088 shape.Static = _isPhysical ? ShapeData.numericFalse : ShapeData.numericTrue;
1089 }
1090
1058 // Create the linkset by putting constraints between the objects of the set so they cannot move 1091 // Create the linkset by putting constraints between the objects of the set so they cannot move
1059 // relative to each other. 1092 // relative to each other.
1093 // TODO: make this more effeicient: a large linkset gets rebuilt over and over and prims are added
1060 void CreateLinksetWithConstraints() 1094 void CreateLinksetWithConstraints()
1061 { 1095 {
1062 // m_log.DebugFormat("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1); 1096 // m_log.DebugFormat("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1);
@@ -1070,76 +1104,48 @@ public sealed class BSPrim : PhysicsActor
1070 // create constraints between the root prim and each of the children 1104 // create constraints between the root prim and each of the children
1071 foreach (BSPrim prim in _childrenPrims) 1105 foreach (BSPrim prim in _childrenPrims)
1072 { 1106 {
1073 // this is a constraint that allows no freedom of movement between the two objects
1074 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
1075 // m_log.DebugFormat("{0}: CreateObject: AddConstraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID); 1107 // m_log.DebugFormat("{0}: CreateObject: AddConstraint between root prim {1} and child prim {2}", LogHeader, LocalID, prim.LocalID);
1076 1108
1109 // Zero motion for children so they don't interpolate
1110 prim.ZeroMotion();
1111
1077 // relative position normalized to the root prim 1112 // relative position normalized to the root prim
1078 OMV.Vector3 childRelativePosition = (prim._position - this._position) * OMV.Quaternion.Inverse(this._orientation); 1113 OMV.Vector3 childRelativePosition = (prim._position - this._position) * OMV.Quaternion.Inverse(this._orientation);
1079 // OMV.Quaternion relativeRotation = OMV.Quaternion.Identity;
1080 1114
1081 // rotation is pointing up the vector between the object centers 1115 // relative rotation of the child to the parent
1082 OMV.Quaternion relativeRotation = OMV.Quaternion.CreateFromAxisAngle(childRelativePosition, 0f); 1116 OMV.Quaternion relativeRotation = OMV.Quaternion.Inverse(prim._orientation) * this._orientation;
1083
1084 /* // the logic for relative rotation from http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=6391
1085 OMV.Vector3 rrn = childRelativePosition;
1086 rrn.Normalize();
1087 rrn /= rrn.X;
1088 OMV.Matrix4 rotmat = new OMV.Matrix4(rrn.X, rrn.Y, rrn.Z, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
1089 OMV.Quaternion relativeRotation = OMV.Quaternion.CreateFromRotationMatrix(rotmat);
1090 */
1091 1117
1118 // this is a constraint that allows no freedom of movement between the two objects
1119 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
1092 BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, prim.LocalID, 1120 BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, prim.LocalID,
1093 childRelativePosition / 2, 1121 childRelativePosition,
1094 relativeRotation,
1095 -childRelativePosition / 2,
1096 relativeRotation, 1122 relativeRotation,
1123 OMV.Vector3.Zero,
1124 OMV.Quaternion.Identity,
1097 OMV.Vector3.Zero, OMV.Vector3.Zero, 1125 OMV.Vector3.Zero, OMV.Vector3.Zero,
1098 OMV.Vector3.Zero, OMV.Vector3.Zero); 1126 OMV.Vector3.Zero, OMV.Vector3.Zero);
1099 } 1127 }
1100 } 1128 }
1101 1129
1102 // Copy prim's info into the BulletSim shape description structure
1103 public void FillShapeInfo(out ShapeData shape)
1104 {
1105 shape.ID = _localID;
1106 shape.Type = _shapeType;
1107 shape.Position = _position;
1108 shape.Rotation = _orientation;
1109 shape.Velocity = _velocity;
1110 shape.Scale = _scale;
1111 shape.Mass = _isPhysical ? _mass : 0f;
1112 shape.Buoyancy = _buoyancy;
1113 shape.MeshKey = _hullKey;
1114 shape.Collidable = (!IsPhantom) ? ShapeData.numericTrue : ShapeData.numericFalse;
1115 shape.Friction = _friction;
1116 shape.Static = _isPhysical ? ShapeData.numericFalse : ShapeData.numericTrue;
1117 }
1118
1119 // Rebuild the geometry and object. 1130 // Rebuild the geometry and object.
1120 // This is called when the shape changes so we need to recreate the mesh/hull. 1131 // This is called when the shape changes so we need to recreate the mesh/hull.
1121 // No locking here because this is done when the physics engine is not simulating 1132 // No locking here because this is done when the physics engine is not simulating
1122 private void RecreateGeomAndObject() 1133 private void RecreateGeomAndObject()
1123 { 1134 {
1124 if (_hullKey != 0)
1125 {
1126 // if a hull already exists, delete the old one
1127 BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey);
1128 _hullKey = 0;
1129 }
1130 // If this object is complex or we are the root of a linkset, build a mesh. 1135 // If this object is complex or we are the root of a linkset, build a mesh.
1131 // The root of a linkset must be a mesh so we can create the linked compound object. 1136 // The root of a linkset must be a mesh so we can create the linked compound object.
1132 if (_scene.NeedsMeshing(_pbs) || IsRootOfLinkset ) 1137 // if (_scene.NeedsMeshing(_pbs) || IsRootOfLinkset )
1138 if (_scene.NeedsMeshing(_pbs)) // linksets with constraints don't need a root mesh
1133 { 1139 {
1134 // m_log.DebugFormat("{0}: RecreateGeomAndObject: creating mesh", LogHeader); 1140 // m_log.DebugFormat("{0}: RecreateGeomAndObject: creating mesh", LogHeader);
1135 _mesh = _scene.mesher.CreateMesh(_avName, _pbs, _size, _scene.meshLOD, _isPhysical); 1141 _mesh = _scene.mesher.CreateMesh(_avName, _pbs, _size, _scene.MeshLOD, _isPhysical);
1136 } 1142 }
1137 else 1143 else
1138 { 1144 {
1139 // it's a BulletSim native shape. 1145 // implement the shape with a Bullet native shape.
1140 _mesh = null; 1146 _mesh = null;
1141 } 1147 }
1142 CreateGeom(); // create the geometry for this prim 1148 CreateGeom();
1143 CreateObject(); 1149 CreateObject();
1144 return; 1150 return;
1145 } 1151 }
@@ -1152,48 +1158,82 @@ public sealed class BSPrim : PhysicsActor
1152 Rotation = 1 << 1, 1158 Rotation = 1 << 1,
1153 Velocity = 1 << 2, 1159 Velocity = 1 << 2,
1154 Acceleration = 1 << 3, 1160 Acceleration = 1 << 3,
1155 AngularVel = 1 << 4 1161 RotationalVel = 1 << 4
1156 } 1162 }
1157 1163
1164 const float ROTATION_TOLERANCE = 0.01f;
1165 const float VELOCITY_TOLERANCE = 0.001f;
1166 const float POSITION_TOLERANCE = 0.05f;
1167 const float ACCELERATION_TOLERANCE = 0.01f;
1168 const float ROTATIONAL_VELOCITY_TOLERANCE = 0.01f;
1169 const bool SHOULD_DAMP_UPDATES = false;
1170
1158 public void UpdateProperties(EntityProperties entprop) 1171 public void UpdateProperties(EntityProperties entprop)
1159 { 1172 {
1160 UpdatedProperties changed = 0; 1173 UpdatedProperties changed = 0;
1161 // assign to the local variables so the normal set action does not happen 1174 if (SHOULD_DAMP_UPDATES)
1162 if (_position != entprop.Position)
1163 {
1164 _position = entprop.Position;
1165 // m_log.DebugFormat("{0}: UpdateProperties: position = {1}", LogHeader, _position);
1166 changed |= UpdatedProperties.Position;
1167 }
1168 if (_orientation != entprop.Rotation)
1169 {
1170 _orientation = entprop.Rotation;
1171 // m_log.DebugFormat("{0}: UpdateProperties: rotation = {1}", LogHeader, _orientation);
1172 changed |= UpdatedProperties.Rotation;
1173 }
1174 if (_velocity != entprop.Velocity)
1175 {
1176 _velocity = entprop.Velocity;
1177 // m_log.DebugFormat("{0}: UpdateProperties: velocity = {1}", LogHeader, _velocity);
1178 changed |= UpdatedProperties.Velocity;
1179 }
1180 if (_acceleration != entprop.Acceleration)
1181 {
1182 _acceleration = entprop.Acceleration;
1183 // m_log.DebugFormat("{0}: UpdateProperties: acceleration = {1}", LogHeader, _acceleration);
1184 changed |= UpdatedProperties.Acceleration;
1185 }
1186 if (_rotationalVelocity != entprop.AngularVelocity)
1187 { 1175 {
1188 _rotationalVelocity = entprop.AngularVelocity; 1176 // assign to the local variables so the normal set action does not happen
1189 // m_log.DebugFormat("{0}: UpdateProperties: rotationalVelocity = {1}", LogHeader, _rotationalVelocity); 1177 // if (_position != entprop.Position)
1190 changed |= UpdatedProperties.AngularVel; 1178 if (!_position.ApproxEquals(entprop.Position, POSITION_TOLERANCE))
1179 {
1180 _position = entprop.Position;
1181 // m_log.DebugFormat("{0}: UpdateProperties: id={1}, pos = {2}", LogHeader, LocalID, _position);
1182 changed |= UpdatedProperties.Position;
1183 }
1184 // if (_orientation != entprop.Rotation)
1185 if (!_orientation.ApproxEquals(entprop.Rotation, ROTATION_TOLERANCE))
1186 {
1187 _orientation = entprop.Rotation;
1188 // m_log.DebugFormat("{0}: UpdateProperties: id={1}, rot = {2}", LogHeader, LocalID, _orientation);
1189 changed |= UpdatedProperties.Rotation;
1190 }
1191 // if (_velocity != entprop.Velocity)
1192 if (!_velocity.ApproxEquals(entprop.Velocity, VELOCITY_TOLERANCE))
1193 {
1194 _velocity = entprop.Velocity;
1195 // m_log.DebugFormat("{0}: UpdateProperties: velocity = {1}", LogHeader, _velocity);
1196 changed |= UpdatedProperties.Velocity;
1197 }
1198 // if (_acceleration != entprop.Acceleration)
1199 if (!_acceleration.ApproxEquals(entprop.Acceleration, ACCELERATION_TOLERANCE))
1200 {
1201 _acceleration = entprop.Acceleration;
1202 // m_log.DebugFormat("{0}: UpdateProperties: acceleration = {1}", LogHeader, _acceleration);
1203 changed |= UpdatedProperties.Acceleration;
1204 }
1205 // if (_rotationalVelocity != entprop.RotationalVelocity)
1206 if (!_rotationalVelocity.ApproxEquals(entprop.RotationalVelocity, ROTATIONAL_VELOCITY_TOLERANCE))
1207 {
1208 _rotationalVelocity = entprop.RotationalVelocity;
1209 // m_log.DebugFormat("{0}: UpdateProperties: rotationalVelocity = {1}", LogHeader, _rotationalVelocity);
1210 changed |= UpdatedProperties.RotationalVel;
1211 }
1212 if (changed != 0)
1213 {
1214 // m_log.DebugFormat("{0}: UpdateProperties: id={1}, c={2}, pos={3}, rot={4}", LogHeader, LocalID, changed, _position, _orientation);
1215 // Only update the position of single objects and linkset roots
1216 if (this._parentPrim == null)
1217 {
1218 // m_log.DebugFormat("{0}: RequestTerseUpdate. id={1}, ch={2}, pos={3}, rot={4}", LogHeader, LocalID, changed, _position, _orientation);
1219 base.RequestPhysicsterseUpdate();
1220 }
1221 }
1191 } 1222 }
1192 if (changed != 0) 1223 else
1193 { 1224 {
1194 // m_log.DebugFormat("{0}: UpdateProperties: id={1}, c={2}, pos={3}, rot={4}", LogHeader, LocalID, changed, _position, _orientation); 1225 // Don't check for damping here -- it's done in BulletSim and SceneObjectPart.
1195 if (this._parentPrim == null) 1226 if (this._parentPrim == null)
1227 {
1228 // Assign to the local variables so the normal set action does not happen
1229 _position = entprop.Position;
1230 _orientation = entprop.Rotation;
1231 _velocity = entprop.Velocity;
1232 _acceleration = entprop.Acceleration;
1233 _rotationalVelocity = entprop.RotationalVelocity;
1234 // m_log.DebugFormat("{0}: RequestTerseUpdate. id={1}, ch={2}, pos={3}, rot={4}", LogHeader, LocalID, changed, _position, _orientation);
1196 base.RequestPhysicsterseUpdate(); 1235 base.RequestPhysicsterseUpdate();
1236 }
1197 } 1237 }
1198 } 1238 }
1199 1239
@@ -1201,7 +1241,8 @@ public sealed class BSPrim : PhysicsActor
1201 public void Collide(uint collidingWith, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) 1241 public void Collide(uint collidingWith, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
1202 { 1242 {
1203 // m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith); 1243 // m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith);
1204 // The following makes IsColliding() and IsCollidingGround() work 1244
1245 // The following lines make IsColliding() and IsCollidingGround() work
1205 _collidingStep = _scene.SimulationStep; 1246 _collidingStep = _scene.SimulationStep;
1206 if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID) 1247 if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID)
1207 { 1248 {