aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
diff options
context:
space:
mode:
authorTeravus Ovares2009-04-10 06:01:29 +0000
committerTeravus Ovares2009-04-10 06:01:29 +0000
commit10f5615573cf087c20ae5eb967e5698d5b23d5da (patch)
treeb298ba3d00b21270837bab48831cb69703c03480 /OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
parent* Fixes a bug in MRM scripting whereby the Touch flag is never enabled for On... (diff)
downloadopensim-SC_OLD-10f5615573cf087c20ae5eb967e5698d5b23d5da.zip
opensim-SC_OLD-10f5615573cf087c20ae5eb967e5698d5b23d5da.tar.gz
opensim-SC_OLD-10f5615573cf087c20ae5eb967e5698d5b23d5da.tar.bz2
opensim-SC_OLD-10f5615573cf087c20ae5eb967e5698d5b23d5da.tar.xz
* Tweak the character controller some more
* Add cursory integration with script engine. * LLMoveToTarget, LLSetBouyancy, LLSetStatus (Physical only), LLApplyImpulse, LLApplyTorque, LLPushObject.. etc. * Still missing linked physical active and LLSetStatus with an axis lock.
Diffstat (limited to 'OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs537
1 files changed, 347 insertions, 190 deletions
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
index 061a620..bf44a0f 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
@@ -43,6 +43,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 44
45 private PhysicsVector _position; 45 private PhysicsVector _position;
46 private PhysicsVector m_zeroPosition;
46 private PhysicsVector _velocity; 47 private PhysicsVector _velocity;
47 private PhysicsVector _torque = new PhysicsVector(0, 0, 0); 48 private PhysicsVector _torque = new PhysicsVector(0, 0, 0);
48 private PhysicsVector m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f); 49 private PhysicsVector m_lastVelocity = new PhysicsVector(0.0f, 0.0f, 0.0f);
@@ -168,6 +169,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
168 private btVector3 tempAngularVelocity2; 169 private btVector3 tempAngularVelocity2;
169 private btVector3 tempInertia1; 170 private btVector3 tempInertia1;
170 private btVector3 tempInertia2; 171 private btVector3 tempInertia2;
172 private btVector3 tempAddForce;
171 private btQuaternion tempOrientation1; 173 private btQuaternion tempOrientation1;
172 private btQuaternion tempOrientation2; 174 private btQuaternion tempOrientation2;
173 private btMotionState tempMotionState1; 175 private btMotionState tempMotionState1;
@@ -870,16 +872,59 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
870 { 872 {
871 873
872 m_log.Debug("[PHYSICS]: _________ChangeMove"); 874 m_log.Debug("[PHYSICS]: _________ChangeMove");
873 tempTransform2 = Body.getWorldTransform(); 875 if (!m_isphysical)
874 btQuaternion quat = tempTransform2.getRotation(); 876 {
875 tempPosition2.setValue(_position.X, _position.Y, _position.Z); 877 tempTransform2 = Body.getWorldTransform();
876 tempTransform2.Dispose(); 878 btQuaternion quat = tempTransform2.getRotation();
877 tempTransform2 = new btTransform(quat, tempPosition2); 879 tempPosition2.setValue(_position.X, _position.Y, _position.Z);
878 Body.setWorldTransform(tempTransform2); 880 tempTransform2.Dispose();
881 tempTransform2 = new btTransform(quat, tempPosition2);
882 Body.setWorldTransform(tempTransform2);
879 883
880 changeSelectedStatus(timestep); 884 changeSelectedStatus(timestep);
881 885
882 resetCollisionAccounting(); 886 resetCollisionAccounting();
887 }
888 else
889 {
890 if (Body != null)
891 {
892 if (Body.Handle != IntPtr.Zero)
893 {
894 _parent_scene.removeFromWorld(this, Body);
895 //Body.Dispose();
896 }
897 //Body = null;
898 // TODO: dispose parts that make up body
899 }
900 /*
901 if (_parent_scene.needsMeshing(_pbs))
902 {
903 // Don't need to re-enable body.. it's done in SetMesh
904 float meshlod = _parent_scene.meshSculptLOD;
905
906 if (IsPhysical)
907 meshlod = _parent_scene.MeshSculptphysicalLOD;
908
909 IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
910 // createmesh returns null when it doesn't mesh.
911 CreateGeom(IntPtr.Zero, mesh);
912 }
913 else
914 {
915 _mesh = null;
916 CreateGeom(IntPtr.Zero, null);
917 }
918 SetCollisionShape(prim_geom);
919 */
920 if (m_isphysical)
921 SetBody(Mass);
922 else
923 SetBody(0);
924 changeSelectedStatus(timestep);
925
926 resetCollisionAccounting();
927 }
883 m_taintposition = _position; 928 m_taintposition = _position;
884 } 929 }
885 930
@@ -1090,17 +1135,88 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1090 1135
1091 private void changeAddForce(float timestep) 1136 private void changeAddForce(float timestep)
1092 { 1137 {
1093 // TODO: throw new NotImplementedException(); 1138 if (!m_isSelected)
1139 {
1140 lock (m_forcelist)
1141 {
1142 //m_log.Info("[PHYSICS]: dequeing forcelist");
1143 if (IsPhysical)
1144 {
1145 PhysicsVector iforce = new PhysicsVector();
1146 for (int i = 0; i < m_forcelist.Count; i++)
1147 {
1148 iforce = iforce + m_forcelist[i];
1149 }
1150
1151 if (Body != null && Body.Handle != IntPtr.Zero)
1152 {
1153 if (tempAddForce != null && tempAddForce.Handle != IntPtr.Zero)
1154 tempAddForce.Dispose();
1155 enableBodySoft();
1156 tempAddForce = new btVector3(iforce.X, iforce.Y, iforce.Z);
1157 Body.applyCentralImpulse(tempAddForce);
1158 }
1159 }
1160 m_forcelist.Clear();
1161 }
1162
1163 m_collisionscore = 0;
1164 m_interpenetrationcount = 0;
1165 }
1166
1167 m_taintforce = false;
1168
1094 } 1169 }
1095 1170
1096 private void changeAddAngularForce(float timestep) 1171 private void changeAddAngularForce(float timestep)
1097 { 1172 {
1098 // TODO: throw new NotImplementedException(); 1173 if (!m_isSelected)
1174 {
1175 lock (m_angularforcelist)
1176 {
1177 //m_log.Info("[PHYSICS]: dequeing forcelist");
1178 if (IsPhysical)
1179 {
1180 PhysicsVector iforce = new PhysicsVector();
1181 for (int i = 0; i < m_angularforcelist.Count; i++)
1182 {
1183 iforce = iforce + m_angularforcelist[i];
1184 }
1185
1186 if (Body != null && Body.Handle != IntPtr.Zero)
1187 {
1188 if (tempAddForce != null && tempAddForce.Handle != IntPtr.Zero)
1189 tempAddForce.Dispose();
1190 enableBodySoft();
1191 tempAddForce = new btVector3(iforce.X, iforce.Y, iforce.Z);
1192 Body.applyTorqueImpulse(tempAddForce);
1193 }
1194
1195 }
1196 m_angularforcelist.Clear();
1197 }
1198
1199 m_collisionscore = 0;
1200 m_interpenetrationcount = 0;
1201 }
1202
1203 m_taintaddangularforce = false;
1099 } 1204 }
1100 1205
1101 private void changeSetTorque(float timestep) 1206 private void changeSetTorque(float timestep)
1102 { 1207 {
1103 // TODO: throw new NotImplementedException(); 1208 if (!m_isSelected)
1209 {
1210 if (IsPhysical)
1211 {
1212 if (Body != null && Body.Handle != IntPtr.Zero)
1213 {
1214 tempAngularVelocity2.setValue(m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z);
1215 Body.applyTorque(tempAngularVelocity2);
1216 }
1217 }
1218 }
1219 m_taintTorque = new PhysicsVector(0, 0, 0);
1104 } 1220 }
1105 1221
1106 private void changedisable(float timestep) 1222 private void changedisable(float timestep)
@@ -1113,10 +1229,13 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1113 // TODO: throw new NotImplementedException(); 1229 // TODO: throw new NotImplementedException();
1114 if (m_taintselected) 1230 if (m_taintselected)
1115 { 1231 {
1232 Body.setCollisionFlags((int)ContactFlags.CF_NO_CONTACT_RESPONSE);
1116 disableBodySoft(); 1233 disableBodySoft();
1234
1117 } 1235 }
1118 else 1236 else
1119 { 1237 {
1238 Body.setCollisionFlags(0);
1120 enableBodySoft(); 1239 enableBodySoft();
1121 } 1240 }
1122 m_isSelected = m_taintselected; 1241 m_isSelected = m_taintselected;
@@ -1125,7 +1244,20 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1125 1244
1126 private void changevelocity(float timestep) 1245 private void changevelocity(float timestep)
1127 { 1246 {
1128 // TODO: throw new NotImplementedException(); 1247 if (!m_isSelected)
1248 {
1249 if (IsPhysical)
1250 {
1251 if (Body != null && Body.Handle != IntPtr.Zero)
1252 {
1253 tempLinearVelocity2.setValue(m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z);
1254 Body.setLinearVelocity(tempLinearVelocity2);
1255 }
1256 }
1257
1258 //resetCollisionAccounting();
1259 }
1260 m_taintVelocity = PhysicsVector.Zero;
1129 } 1261 }
1130 1262
1131 private void changelink(float timestep) 1263 private void changelink(float timestep)
@@ -1165,23 +1297,25 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1165 { 1297 {
1166 if (m_buoyancy > 0) 1298 if (m_buoyancy > 0)
1167 { 1299 {
1168 fz = (((-1 * _parent_scene.gravityz) * m_buoyancy) * m_mass); 1300 fz = (((-1 * _parent_scene.gravityz) * m_buoyancy) * m_mass) * 0.035f;
1169 1301
1170 //d.Vector3 l_velocity = d.BodyGetLinearVel(Body); 1302 //d.Vector3 l_velocity = d.BodyGetLinearVel(Body);
1171 //m_log.Info("Using Buoyancy: " + buoyancy + " G: " + (_parent_scene.gravityz * m_buoyancy) + "mass:" + m_mass + " Pos: " + Position.ToString()); 1303 //m_log.Info("Using Buoyancy: " + buoyancy + " G: " + (_parent_scene.gravityz * m_buoyancy) + "mass:" + m_mass + " Pos: " + Position.ToString());
1172 } 1304 }
1173 else 1305 else
1174 { 1306 {
1175 fz = (-1 * (((-1 * _parent_scene.gravityz) * (-1 * m_buoyancy)) * m_mass)); 1307 fz = (-1 * (((-1 * _parent_scene.gravityz) * (-1 * m_buoyancy)) * m_mass) * 0.035f);
1176 } 1308 }
1177 } 1309 }
1178 1310
1179 if (m_usePID) 1311 if (m_usePID)
1180 { 1312 {
1313 PID_D = 61f;
1314 PID_G = 65f;
1181 //if (!d.BodyIsEnabled(Body)) 1315 //if (!d.BodyIsEnabled(Body))
1182 //d.BodySetForce(Body, 0f, 0f, 0f); 1316 //d.BodySetForce(Body, 0f, 0f, 0f);
1183 // If we're using the PID controller, then we have no gravity 1317 // If we're using the PID controller, then we have no gravity
1184 fz = (-1 * _parent_scene.gravityz) * m_mass; 1318 fz = ((-1 * _parent_scene.gravityz) * m_mass) * 1.025f;
1185 1319
1186 // no lock; for now it's only called from within Simulate() 1320 // no lock; for now it's only called from within Simulate()
1187 1321
@@ -1202,8 +1336,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1202 // TODO: NEED btVector3 for Linear Velocity 1336 // TODO: NEED btVector3 for Linear Velocity
1203 // NEED btVector3 for Position 1337 // NEED btVector3 for Position
1204 1338
1205 PhysicsVector pos = new PhysicsVector(0, 0, 0); //TODO: Insert values gotten from bullet 1339 PhysicsVector pos = new PhysicsVector(_position.X, _position.Y, _position.Z); //TODO: Insert values gotten from bullet
1206 PhysicsVector vel = new PhysicsVector(0, 0, 0); 1340 PhysicsVector vel = new PhysicsVector(_velocity.X, _velocity.Y, _velocity.Z);
1207 1341
1208 _target_velocity = 1342 _target_velocity =
1209 new PhysicsVector( 1343 new PhysicsVector(
@@ -1301,6 +1435,11 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1301 d.BodySetLinearVel(Body, vel.X, vel.Y, 0); 1435 d.BodySetLinearVel(Body, vel.X, vel.Y, 0);
1302 d.BodyAddForce(Body, 0, 0, fz); 1436 d.BodyAddForce(Body, 0, 0, fz);
1303 */ 1437 */
1438 if (Body != null && Body.Handle != IntPtr.Zero)
1439 {
1440 Body.setLinearVelocity(_parent_scene.VectorZero);
1441 Body.clearForces();
1442 }
1304 return; 1443 return;
1305 } 1444 }
1306 else 1445 else
@@ -1349,11 +1488,22 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1349 1488
1350 // TODO: Do Bullet Equiv 1489 // TODO: Do Bullet Equiv
1351 // d.BodyAddForce(Body, fx, fy, fz); 1490 // d.BodyAddForce(Body, fx, fy, fz);
1491 if (Body != null && Body.Handle != IntPtr.Zero)
1492 {
1493 Body.activate(true);
1494 if (tempAddForce != null && tempAddForce.Handle != IntPtr.Zero)
1495 tempAddForce.Dispose();
1496
1497 tempAddForce = new btVector3(fx * 0.01f, fy * 0.01f, fz * 0.01f);
1498 Body.applyCentralImpulse(tempAddForce);
1499 }
1352 } 1500 }
1353 } 1501 }
1354 else 1502 else
1355 { 1503 {
1356 // _zeroPosition = d.BodyGetPosition(Body); 1504 if (m_zeroPosition == null)
1505 m_zeroPosition = new PhysicsVector(0, 0, 0);
1506 m_zeroPosition.setValues(_position.X,_position.Y,_position.Z);
1357 return; 1507 return;
1358 } 1508 }
1359 } 1509 }
@@ -2066,212 +2216,219 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2066 2216
2067 public void UpdatePositionAndVelocity() 2217 public void UpdatePositionAndVelocity()
2068 { 2218 {
2069 if (_parent == null) 2219 if (!m_isSelected)
2070 { 2220 {
2071 PhysicsVector pv = new PhysicsVector(0, 0, 0); 2221 if (_parent == null)
2072 bool lastZeroFlag = _zeroFlag; 2222 {
2073 if (tempPosition3 != null && tempPosition3.Handle != IntPtr.Zero) 2223 PhysicsVector pv = new PhysicsVector(0, 0, 0);
2074 tempPosition3.Dispose(); 2224 bool lastZeroFlag = _zeroFlag;
2075 if (tempTransform3 != null && tempTransform3.Handle != IntPtr.Zero) 2225 if (tempPosition3 != null && tempPosition3.Handle != IntPtr.Zero)
2076 tempTransform3.Dispose(); 2226 tempPosition3.Dispose();
2077 2227 if (tempTransform3 != null && tempTransform3.Handle != IntPtr.Zero)
2078 if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero) 2228 tempTransform3.Dispose();
2079 tempOrientation2.Dispose(); 2229
2080 2230 if (tempOrientation2 != null && tempOrientation2.Handle != IntPtr.Zero)
2081 if (tempAngularVelocity1 != null && tempAngularVelocity1.Handle != IntPtr.Zero) 2231 tempOrientation2.Dispose();
2082 tempAngularVelocity1.Dispose(); 2232
2083 2233 if (tempAngularVelocity1 != null && tempAngularVelocity1.Handle != IntPtr.Zero)
2084 if (tempLinearVelocity1 != null && tempLinearVelocity1.Handle != IntPtr.Zero) 2234 tempAngularVelocity1.Dispose();
2085 tempLinearVelocity1.Dispose(); 2235
2236 if (tempLinearVelocity1 != null && tempLinearVelocity1.Handle != IntPtr.Zero)
2237 tempLinearVelocity1.Dispose();
2238
2239
2240
2241 tempTransform3 = Body.getInterpolationWorldTransform();
2242 tempPosition3 = tempTransform3.getOrigin(); // vec
2243 tempOrientation2 = tempTransform3.getRotation(); // ori
2244 tempAngularVelocity1 = Body.getInterpolationAngularVelocity(); //rotvel
2245 tempLinearVelocity1 = Body.getInterpolationLinearVelocity(); // vel
2246
2247 _torque.setValues(tempAngularVelocity1.getX(), tempAngularVelocity1.getX(),
2248 tempAngularVelocity1.getZ());
2249 PhysicsVector l_position = new PhysicsVector();
2250 Quaternion l_orientation = new Quaternion();
2251 m_lastposition = _position;
2252 m_lastorientation = _orientation;
2253
2254 l_position.X = tempPosition3.getX();
2255 l_position.Y = tempPosition3.getY();
2256 l_position.Z = tempPosition3.getZ();
2257 l_orientation.X = tempOrientation2.getX();
2258 l_orientation.Y = tempOrientation2.getY();
2259 l_orientation.Z = tempOrientation2.getZ();
2260 l_orientation.W = tempOrientation2.getW();
2261
2262 if (l_position.X > 255.95f || l_position.X < 0f || l_position.Y > 255.95f || l_position.Y < 0f)
2263 {
2264 //base.RaiseOutOfBounds(l_position);
2086 2265
2266 if (m_crossingfailures < _parent_scene.geomCrossingFailuresBeforeOutofbounds)
2267 {
2268 _position = l_position;
2269 //_parent_scene.remActivePrim(this);
2270 if (_parent == null)
2271 base.RequestPhysicsterseUpdate();
2272 return;
2273 }
2274 else
2275 {
2276 if (_parent == null)
2277 base.RaiseOutOfBounds(l_position);
2278 return;
2279 }
2280 }
2087 2281
2282 if (l_position.Z < -200000f)
2283 {
2284 // This is so prim that get lost underground don't fall forever and suck up
2285 //
2286 // Sim resources and memory.
2287 // Disables the prim's movement physics....
2288 // It's a hack and will generate a console message if it fails.
2289
2290 //IsPhysical = false;
2291 //if (_parent == null)
2292 //base.RaiseOutOfBounds(_position);
2088 2293
2089 tempTransform3 = Body.getInterpolationWorldTransform(); 2294 _acceleration.X = 0;
2090 tempPosition3 = tempTransform3.getOrigin(); // vec 2295 _acceleration.Y = 0;
2091 tempOrientation2 = tempTransform3.getRotation(); // ori 2296 _acceleration.Z = 0;
2092 tempAngularVelocity1 = Body.getInterpolationAngularVelocity(); //rotvel
2093 tempLinearVelocity1 = Body.getInterpolationLinearVelocity(); // vel
2094 2297
2095 _torque.setValues(tempAngularVelocity1.getX(), tempAngularVelocity1.getX(), tempAngularVelocity1.getZ()); 2298 _velocity.X = 0;
2096 PhysicsVector l_position = new PhysicsVector(); 2299 _velocity.Y = 0;
2097 Quaternion l_orientation = new Quaternion(); 2300 _velocity.Z = 0;
2098 m_lastposition = _position; 2301 m_rotationalVelocity.X = 0;
2099 m_lastorientation = _orientation; 2302 m_rotationalVelocity.Y = 0;
2303 m_rotationalVelocity.Z = 0;
2100 2304
2101 l_position.X = tempPosition3.getX(); 2305 if (_parent == null)
2102 l_position.Y = tempPosition3.getY(); 2306 base.RequestPhysicsterseUpdate();
2103 l_position.Z = tempPosition3.getZ();
2104 l_orientation.X = tempOrientation2.getX();
2105 l_orientation.Y = tempOrientation2.getY();
2106 l_orientation.Z = tempOrientation2.getZ();
2107 l_orientation.W = tempOrientation2.getW();
2108 2307
2109 if (l_position.X > 255.95f || l_position.X < 0f || l_position.Y > 255.95f || l_position.Y < 0f) 2308 m_throttleUpdates = false;
2110 { 2309 throttleCounter = 0;
2111 //base.RaiseOutOfBounds(l_position); 2310 _zeroFlag = true;
2311 //outofBounds = true;
2312 }
2112 2313
2113 if (m_crossingfailures < _parent_scene.geomCrossingFailuresBeforeOutofbounds) 2314 if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02)
2315 && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02)
2316 && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02)
2317 && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.01))
2114 { 2318 {
2115 _position = l_position; 2319 _zeroFlag = true;
2116 //_parent_scene.remActivePrim(this); 2320 m_throttleUpdates = false;
2117 if (_parent == null)
2118 base.RequestPhysicsterseUpdate();
2119 return;
2120 } 2321 }
2121 else 2322 else
2122 { 2323 {
2123 if (_parent == null) 2324 //m_log.Debug(Math.Abs(m_lastposition.X - l_position.X).ToString());
2124 base.RaiseOutOfBounds(l_position); 2325 _zeroFlag = false;
2125 return;
2126 } 2326 }
2127 }
2128 2327
2129 if (l_position.Z < -200000f) 2328 if (_zeroFlag)
2130 { 2329 {
2131 // This is so prim that get lost underground don't fall forever and suck up 2330 _velocity.X = 0.0f;
2132 // 2331 _velocity.Y = 0.0f;
2133 // Sim resources and memory. 2332 _velocity.Z = 0.0f;
2134 // Disables the prim's movement physics.... 2333
2135 // It's a hack and will generate a console message if it fails. 2334 _acceleration.X = 0;
2136 2335 _acceleration.Y = 0;
2137 //IsPhysical = false; 2336 _acceleration.Z = 0;
2138 //if (_parent == null) 2337
2139 //base.RaiseOutOfBounds(_position); 2338 //_orientation.w = 0f;
2339 //_orientation.X = 0f;
2340 //_orientation.Y = 0f;
2341 //_orientation.Z = 0f;
2342 m_rotationalVelocity.X = 0;
2343 m_rotationalVelocity.Y = 0;
2344 m_rotationalVelocity.Z = 0;
2345 if (!m_lastUpdateSent)
2346 {
2347 m_throttleUpdates = false;
2348 throttleCounter = 0;
2349 m_rotationalVelocity = pv;
2140 2350
2141 _acceleration.X = 0; 2351 if (_parent == null)
2142 _acceleration.Y = 0; 2352 base.RequestPhysicsterseUpdate();
2143 _acceleration.Z = 0;
2144 2353
2145 _velocity.X = 0; 2354 m_lastUpdateSent = true;
2146 _velocity.Y = 0; 2355 }
2147 _velocity.Z = 0; 2356 }
2148 m_rotationalVelocity.X = 0; 2357 else
2149 m_rotationalVelocity.Y = 0; 2358 {
2150 m_rotationalVelocity.Z = 0; 2359 if (lastZeroFlag != _zeroFlag)
2360 {
2361 if (_parent == null)
2362 base.RequestPhysicsterseUpdate();
2363 }
2151 2364
2152 if (_parent == null) 2365 m_lastVelocity = _velocity;
2153 base.RequestPhysicsterseUpdate();
2154 2366
2155 m_throttleUpdates = false; 2367 _position = l_position;
2156 throttleCounter = 0;
2157 _zeroFlag = true;
2158 //outofBounds = true;
2159 }
2160 2368
2161 if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) 2369 _velocity.X = tempLinearVelocity1.getX();
2162 && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) 2370 _velocity.Y = tempLinearVelocity1.getY();
2163 && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02) 2371 _velocity.Z = tempLinearVelocity1.getZ();
2164 && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.01 ))
2165 {
2166 _zeroFlag = true;
2167 m_throttleUpdates = false;
2168 }
2169 else
2170 {
2171 //m_log.Debug(Math.Abs(m_lastposition.X - l_position.X).ToString());
2172 _zeroFlag = false;
2173 }
2174 2372
2175 if (_zeroFlag) 2373 _acceleration = ((_velocity - m_lastVelocity)/0.1f);
2176 { 2374 _acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X/0.1f,
2177 _velocity.X = 0.0f; 2375 _velocity.Y - m_lastVelocity.Y/0.1f,
2178 _velocity.Y = 0.0f; 2376 _velocity.Z - m_lastVelocity.Z/0.1f);
2179 _velocity.Z = 0.0f; 2377 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
2180 2378
2181 _acceleration.X = 0; 2379 if (_velocity.IsIdentical(pv, 0.5f))
2182 _acceleration.Y = 0; 2380 {
2183 _acceleration.Z = 0; 2381 m_rotationalVelocity = pv;
2382 }
2383 else
2384 {
2184 2385
2185 //_orientation.w = 0f; 2386 m_rotationalVelocity.setValues(tempAngularVelocity1.getX(), tempAngularVelocity1.getY(),
2186 //_orientation.X = 0f; 2387 tempAngularVelocity1.getZ());
2187 //_orientation.Y = 0f; 2388 }
2188 //_orientation.Z = 0f;
2189 m_rotationalVelocity.X = 0;
2190 m_rotationalVelocity.Y = 0;
2191 m_rotationalVelocity.Z = 0;
2192 if (!m_lastUpdateSent)
2193 {
2194 m_throttleUpdates = false;
2195 throttleCounter = 0;
2196 m_rotationalVelocity = pv;
2197 2389
2198 if (_parent == null) 2390 //m_log.Debug("ODE: " + m_rotationalVelocity.ToString());
2199 base.RequestPhysicsterseUpdate();
2200 2391
2201 m_lastUpdateSent = true; 2392 _orientation.X = l_orientation.X;
2202 } 2393 _orientation.Y = l_orientation.Y;
2203 } 2394 _orientation.Z = l_orientation.Z;
2204 else 2395 _orientation.W = l_orientation.W;
2205 { 2396 m_lastUpdateSent = false;
2206 if (lastZeroFlag != _zeroFlag) 2397
2207 { 2398 //if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate)
2399 //{
2208 if (_parent == null) 2400 if (_parent == null)
2209 base.RequestPhysicsterseUpdate(); 2401 base.RequestPhysicsterseUpdate();
2210 } 2402 // }
2211 2403 // else
2212 m_lastVelocity = _velocity; 2404 // {
2405 // throttleCounter++;
2406 //}
2213 2407
2214 _position = l_position;
2215
2216 _velocity.X = tempLinearVelocity1.getX();
2217 _velocity.Y = tempLinearVelocity1.getY();
2218 _velocity.Z = tempLinearVelocity1.getZ();
2219
2220 _acceleration = ((_velocity - m_lastVelocity) / 0.1f);
2221 _acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f);
2222 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
2223
2224 if (_velocity.IsIdentical(pv, 0.5f))
2225 {
2226 m_rotationalVelocity = pv;
2227 } 2408 }
2228 else 2409 m_lastposition = l_position;
2410 if (forceenable)
2229 { 2411 {
2230 2412 Body.forceActivationState(1);
2231 m_rotationalVelocity.setValues(tempAngularVelocity1.getX(), tempAngularVelocity1.getY(), tempAngularVelocity1.getZ()); 2413 forceenable = false;
2232 } 2414 }
2233
2234 //m_log.Debug("ODE: " + m_rotationalVelocity.ToString());
2235
2236 _orientation.X = l_orientation.X;
2237 _orientation.Y = l_orientation.Y;
2238 _orientation.Z = l_orientation.Z;
2239 _orientation.W = l_orientation.W;
2240 m_lastUpdateSent = false;
2241
2242 //if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate)
2243 //{
2244 if (_parent == null)
2245 base.RequestPhysicsterseUpdate();
2246 // }
2247 // else
2248 // {
2249 // throttleCounter++;
2250 //}
2251
2252 } 2415 }
2253 m_lastposition = l_position; 2416 else
2254 if (forceenable)
2255 { 2417 {
2256 Body.forceActivationState(1); 2418 // Not a body.. so Make sure the client isn't interpolating
2257 forceenable = false; 2419 _velocity.X = 0;
2258 } 2420 _velocity.Y = 0;
2259 } 2421 _velocity.Z = 0;
2260 else
2261 {
2262 // Not a body.. so Make sure the client isn't interpolating
2263 _velocity.X = 0;
2264 _velocity.Y = 0;
2265 _velocity.Z = 0;
2266 2422
2267 _acceleration.X = 0; 2423 _acceleration.X = 0;
2268 _acceleration.Y = 0; 2424 _acceleration.Y = 0;
2269 _acceleration.Z = 0; 2425 _acceleration.Z = 0;
2270 2426
2271 m_rotationalVelocity.X = 0; 2427 m_rotationalVelocity.X = 0;
2272 m_rotationalVelocity.Y = 0; 2428 m_rotationalVelocity.Y = 0;
2273 m_rotationalVelocity.Z = 0; 2429 m_rotationalVelocity.Z = 0;
2274 _zeroFlag = true; 2430 _zeroFlag = true;
2431 }
2275 } 2432 }
2276 } 2433 }
2277 2434