aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSScene.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSScene.cs114
1 files changed, 67 insertions, 47 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
index 7998b08..c6e8bc4 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs
@@ -795,7 +795,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
795 795
796 delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val); 796 delegate void ParamUser(BSScene scene, IConfig conf, string paramName, float val);
797 delegate float ParamGet(BSScene scene); 797 delegate float ParamGet(BSScene scene);
798 delegate void ParamSet(BSScene scene, string paramName, uint localID, float val); 798 delegate void ParamSet(BSScene scene, string paramName, uint localID, float val);
799 delegate void SetOnObject(BSScene scene, BSPhysObject obj, float val);
799 800
800 private struct ParameterDefn 801 private struct ParameterDefn
801 { 802 {
@@ -804,7 +805,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
804 public float defaultValue; // default value if not specified anywhere else 805 public float defaultValue; // default value if not specified anywhere else
805 public ParamUser userParam; // get the value from the configuration file 806 public ParamUser userParam; // get the value from the configuration file
806 public ParamGet getter; // return the current value stored for this parameter 807 public ParamGet getter; // return the current value stored for this parameter
807 public ParamSet setter; // set the current value for this parameter 808 public ParamSet setter; // set the current value for this parameter
809 public SetOnObject onObject; // set the value on an object in the physical domain
808 public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s) 810 public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s)
809 { 811 {
810 name = n; 812 name = n;
@@ -812,7 +814,18 @@ public class BSScene : PhysicsScene, IPhysicsParameters
812 defaultValue = v; 814 defaultValue = v;
813 userParam = u; 815 userParam = u;
814 getter = g; 816 getter = g;
815 setter = s; 817 setter = s;
818 onObject = null;
819 }
820 public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s, SetOnObject o)
821 {
822 name = n;
823 desc = d;
824 defaultValue = v;
825 userParam = u;
826 getter = g;
827 setter = s;
828 onObject = o;
816 } 829 }
817 } 830 }
818 831
@@ -834,6 +847,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters
834 // 847 //
835 // The single letter parameters for the delegates are: 848 // The single letter parameters for the delegates are:
836 // s = BSScene 849 // s = BSScene
850 // o = BSPhysObject
837 // p = string parameter name 851 // p = string parameter name
838 // l = localID of referenced object 852 // l = localID of referenced object
839 // v = float value 853 // v = float value
@@ -943,65 +957,74 @@ public class BSScene : PhysicsScene, IPhysicsParameters
943 -9.80665f, 957 -9.80665f,
944 (s,cf,p,v) => { s.m_params[0].gravity = cf.GetFloat(p, v); }, 958 (s,cf,p,v) => { s.m_params[0].gravity = cf.GetFloat(p, v); },
945 (s) => { return s.m_params[0].gravity; }, 959 (s) => { return s.m_params[0].gravity; },
946 (s,p,l,v) => { s.m_params[0].gravity = v; s.TaintedUpdateParameter(p,l,v); } ), 960 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].gravity, p, PhysParameterEntry.APPLY_TO_NONE, v); },
961 (s,o,v) => { BulletSimAPI.SetGravity2(s.World.ptr, new Vector3(0f,0f,v)); } ),
947 962
948 963
949 new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)", 964 new ParameterDefn("LinearDamping", "Factor to damp linear movement per second (0.0 - 1.0)",
950 0f, 965 0f,
951 (s,cf,p,v) => { s.m_params[0].linearDamping = cf.GetFloat(p, v); }, 966 (s,cf,p,v) => { s.m_params[0].linearDamping = cf.GetFloat(p, v); },
952 (s) => { return s.m_params[0].linearDamping; }, 967 (s) => { return s.m_params[0].linearDamping; },
953 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].linearDamping, p, l, v); } ), 968 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].linearDamping, p, l, v); },
969 (s,o,v) => { BulletSimAPI.SetDamping2(o.BSBody.ptr, v, v); } ),
954 new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)", 970 new ParameterDefn("AngularDamping", "Factor to damp angular movement per second (0.0 - 1.0)",
955 0f, 971 0f,
956 (s,cf,p,v) => { s.m_params[0].angularDamping = cf.GetFloat(p, v); }, 972 (s,cf,p,v) => { s.m_params[0].angularDamping = cf.GetFloat(p, v); },
957 (s) => { return s.m_params[0].angularDamping; }, 973 (s) => { return s.m_params[0].angularDamping; },
958 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].angularDamping, p, l, v); } ), 974 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].angularDamping, p, l, v); },
975 (s,o,v) => { BulletSimAPI.SetDamping2(o.BSBody.ptr, v, v); } ),
959 new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static", 976 new ParameterDefn("DeactivationTime", "Seconds before considering an object potentially static",
960 0.2f, 977 0.2f,
961 (s,cf,p,v) => { s.m_params[0].deactivationTime = cf.GetFloat(p, v); }, 978 (s,cf,p,v) => { s.m_params[0].deactivationTime = cf.GetFloat(p, v); },
962 (s) => { return s.m_params[0].deactivationTime; }, 979 (s) => { return s.m_params[0].deactivationTime; },
963 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].deactivationTime, p, l, v); } ), 980 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].deactivationTime, p, l, v); },
981 (s,o,v) => { BulletSimAPI.SetDeactivationTime2(o.BSBody.ptr, v); } ),
964 new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static", 982 new ParameterDefn("LinearSleepingThreshold", "Seconds to measure linear movement before considering static",
965 0.8f, 983 0.8f,
966 (s,cf,p,v) => { s.m_params[0].linearSleepingThreshold = cf.GetFloat(p, v); }, 984 (s,cf,p,v) => { s.m_params[0].linearSleepingThreshold = cf.GetFloat(p, v); },
967 (s) => { return s.m_params[0].linearSleepingThreshold; }, 985 (s) => { return s.m_params[0].linearSleepingThreshold; },
968 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].linearSleepingThreshold, p, l, v); } ), 986 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].linearSleepingThreshold, p, l, v); },
987 (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.BSBody.ptr, v, v); } ),
969 new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static", 988 new ParameterDefn("AngularSleepingThreshold", "Seconds to measure angular movement before considering static",
970 1.0f, 989 1.0f,
971 (s,cf,p,v) => { s.m_params[0].angularSleepingThreshold = cf.GetFloat(p, v); }, 990 (s,cf,p,v) => { s.m_params[0].angularSleepingThreshold = cf.GetFloat(p, v); },
972 (s) => { return s.m_params[0].angularSleepingThreshold; }, 991 (s) => { return s.m_params[0].angularSleepingThreshold; },
973 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].angularSleepingThreshold, p, l, v); } ), 992 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].angularSleepingThreshold, p, l, v); },
993 (s,o,v) => { BulletSimAPI.SetSleepingThresholds2(o.BSBody.ptr, v, v); } ),
974 new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" , 994 new ParameterDefn("CcdMotionThreshold", "Continuious collision detection threshold (0 means no CCD)" ,
975 0f, // set to zero to disable 995 0f, // set to zero to disable
976 (s,cf,p,v) => { s.m_params[0].ccdMotionThreshold = cf.GetFloat(p, v); }, 996 (s,cf,p,v) => { s.m_params[0].ccdMotionThreshold = cf.GetFloat(p, v); },
977 (s) => { return s.m_params[0].ccdMotionThreshold; }, 997 (s) => { return s.m_params[0].ccdMotionThreshold; },
978 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].ccdMotionThreshold, p, l, v); } ), 998 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].ccdMotionThreshold, p, l, v); },
999 (s,o,v) => { BulletSimAPI.SetCcdMotionThreshold2(o.BSBody.ptr, v); } ),
979 new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" , 1000 new ParameterDefn("CcdSweptSphereRadius", "Continuious collision detection test radius" ,
980 0f, 1001 0f,
981 (s,cf,p,v) => { s.m_params[0].ccdSweptSphereRadius = cf.GetFloat(p, v); }, 1002 (s,cf,p,v) => { s.m_params[0].ccdSweptSphereRadius = cf.GetFloat(p, v); },
982 (s) => { return s.m_params[0].ccdSweptSphereRadius; }, 1003 (s) => { return s.m_params[0].ccdSweptSphereRadius; },
983 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].ccdSweptSphereRadius, p, l, v); } ), 1004 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].ccdSweptSphereRadius, p, l, v); },
1005 (s,o,v) => { BulletSimAPI.SetCcdSweepSphereRadius2(o.BSBody.ptr, v); } ),
984 new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" , 1006 new ParameterDefn("ContactProcessingThreshold", "Distance between contacts before doing collision check" ,
985 0.1f, 1007 0.1f,
986 (s,cf,p,v) => { s.m_params[0].contactProcessingThreshold = cf.GetFloat(p, v); }, 1008 (s,cf,p,v) => { s.m_params[0].contactProcessingThreshold = cf.GetFloat(p, v); },
987 (s) => { return s.m_params[0].contactProcessingThreshold; }, 1009 (s) => { return s.m_params[0].contactProcessingThreshold; },
988 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].contactProcessingThreshold, p, l, v); } ), 1010 (s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].contactProcessingThreshold, p, l, v); },
1011 (s,o,v) => { BulletSimAPI.SetContactProcessingThreshold2(o.BSBody.ptr, v); } ),
989 1012
990 new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" , 1013 new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" ,
991 0.5f, 1014 0.5f,
992 (s,cf,p,v) => { s.m_params[0].terrainFriction = cf.GetFloat(p, v); }, 1015 (s,cf,p,v) => { s.m_params[0].terrainFriction = cf.GetFloat(p, v); },
993 (s) => { return s.m_params[0].terrainFriction; }, 1016 (s) => { return s.m_params[0].terrainFriction; },
994 (s,p,l,v) => { s.m_params[0].terrainFriction = v; s.TaintedUpdateParameter(p,l,v); } ), 1017 (s,p,l,v) => { s.m_params[0].terrainFriction = v; /* TODO: set on real terrain */} ),
995 new ParameterDefn("TerrainHitFraction", "Distance to measure hit collisions" , 1018 new ParameterDefn("TerrainHitFraction", "Distance to measure hit collisions" ,
996 0.8f, 1019 0.8f,
997 (s,cf,p,v) => { s.m_params[0].terrainHitFraction = cf.GetFloat(p, v); }, 1020 (s,cf,p,v) => { s.m_params[0].terrainHitFraction = cf.GetFloat(p, v); },
998 (s) => { return s.m_params[0].terrainHitFraction; }, 1021 (s) => { return s.m_params[0].terrainHitFraction; },
999 (s,p,l,v) => { s.m_params[0].terrainHitFraction = v; s.TaintedUpdateParameter(p,l,v); } ), 1022 (s,p,l,v) => { s.m_params[0].terrainHitFraction = v; /* TODO: set on real terrain */ } ),
1000 new ParameterDefn("TerrainRestitution", "Bouncyness" , 1023 new ParameterDefn("TerrainRestitution", "Bouncyness" ,
1001 0f, 1024 0f,
1002 (s,cf,p,v) => { s.m_params[0].terrainRestitution = cf.GetFloat(p, v); }, 1025 (s,cf,p,v) => { s.m_params[0].terrainRestitution = cf.GetFloat(p, v); },
1003 (s) => { return s.m_params[0].terrainRestitution; }, 1026 (s) => { return s.m_params[0].terrainRestitution; },
1004 (s,p,l,v) => { s.m_params[0].terrainRestitution = v; s.TaintedUpdateParameter(p,l,v); } ), 1027 (s,p,l,v) => { s.m_params[0].terrainRestitution = v; /* TODO: set on real terrain */ } ),
1005 new ParameterDefn("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.", 1028 new ParameterDefn("AvatarFriction", "Factor to reduce movement against an avatar. Changed on avatar recreation.",
1006 0.2f, 1029 0.2f,
1007 (s,cf,p,v) => { s.m_params[0].avatarFriction = cf.GetFloat(p, v); }, 1030 (s,cf,p,v) => { s.m_params[0].avatarFriction = cf.GetFloat(p, v); },
@@ -1228,58 +1251,55 @@ public class BSScene : PhysicsScene, IPhysicsParameters
1228 return ret; 1251 return ret;
1229 } 1252 }
1230 1253
1231 // check to see if we are updating a parameter for a particular or all of the prims
1232 protected void UpdateParameterObject(ref float loc, string parm, uint localID, float val)
1233 {
1234 List<uint> operateOn;
1235 lock (PhysObjects) operateOn = new List<uint>(PhysObjects.Keys);
1236 UpdateParameterSet(operateOn, ref loc, parm, localID, val);
1237 }
1238
1239 // update all the localIDs specified 1254 // update all the localIDs specified
1240 // If the local ID is APPLY_TO_NONE, just change the default value 1255 // If the local ID is APPLY_TO_NONE, just change the default value
1241 // If the localID is APPLY_TO_ALL change the default value and apply the new value to all the lIDs 1256 // If the localID is APPLY_TO_ALL change the default value and apply the new value to all the lIDs
1242 // If the localID is a specific object, apply the parameter change to only that object 1257 // If the localID is a specific object, apply the parameter change to only that object
1243 protected void UpdateParameterSet(List<uint> lIDs, ref float defaultLoc, string parm, uint localID, float val) 1258 protected void UpdateParameterObject(ref float defaultLoc, string parm, uint localID, float val)
1244 { 1259 {
1260 List<uint> objectIDs = new List<uint>();
1245 switch (localID) 1261 switch (localID)
1246 { 1262 {
1247 case PhysParameterEntry.APPLY_TO_NONE: 1263 case PhysParameterEntry.APPLY_TO_NONE:
1248 defaultLoc = val; // setting only the default value 1264 defaultLoc = val; // setting only the default value
1265 // This will cause a call into the physical world if some operation is specified (SetOnObject).
1266 objectIDs.Add(TERRAIN_ID);
1267 TaintedUpdateParameter(parm, objectIDs, val);
1249 break; 1268 break;
1250 case PhysParameterEntry.APPLY_TO_ALL: 1269 case PhysParameterEntry.APPLY_TO_ALL:
1251 defaultLoc = val; // setting ALL also sets the default value 1270 defaultLoc = val; // setting ALL also sets the default value
1252 /* 1271 lock (PhysObjects) objectIDs = new List<uint>(PhysObjects.Keys);
1253 List<uint> objectIDs = lIDs; 1272 TaintedUpdateParameter(parm, objectIDs, val);
1254 string xparm = parm.ToLower();
1255 float xval = val;
1256 TaintedObject("BSScene.UpdateParameterSet", delegate() {
1257 foreach (uint lID in objectIDs)
1258 {
1259 BulletSimAPI.UpdateParameter(WorldID, lID, xparm, xval);
1260 }
1261 });
1262 */
1263 break; 1273 break;
1264 default: 1274 default:
1265 // setting only one localID 1275 // setting only one localID
1266 TaintedUpdateParameter(parm, localID, val); 1276 objectIDs.Add(localID);
1277 TaintedUpdateParameter(parm, objectIDs, val);
1267 break; 1278 break;
1268 } 1279 }
1269 } 1280 }
1270 1281
1271 // schedule the actual updating of the paramter to when the phys engine is not busy 1282 // schedule the actual updating of the paramter to when the phys engine is not busy
1272 protected void TaintedUpdateParameter(string parm, uint localID, float val) 1283 protected void TaintedUpdateParameter(string parm, List<uint> lIDs, float val)
1273 { 1284 {
1274 /* Settings in the C++ code are not working at the moment. TODO: fix the settings. 1285 float xval = val;
1275 m_log.ErrorFormat("{0} Cannot change parameters of base objects. Someday it will be added.", LogHeader); 1286 List<uint> xlIDs = lIDs;
1276 uint xlocalID = localID; 1287 string xparm = parm;
1277 string xparm = parm.ToLower(); 1288 TaintedObject("BSScene.UpdateParameterSet", delegate() {
1278 float xval = val; 1289 ParameterDefn thisParam;
1279 TaintedObject("BSScene.TaintedUpdateParameter", delegate() { 1290 if (TryGetParameter(xparm, out thisParam))
1280 BulletSimAPI.UpdateParameter(WorldID, xlocalID, xparm, xval); 1291 {
1292 if (thisParam.onObject != null)
1293 {
1294 foreach (uint lID in xlIDs)
1295 {
1296 BSPhysObject theObject = null;
1297 PhysObjects.TryGetValue(lID, out theObject);
1298 thisParam.onObject(this, theObject, xval);
1299 }
1300 }
1301 }
1281 }); 1302 });
1282 */
1283 } 1303 }
1284 1304
1285 // Get parameter. 1305 // Get parameter.