diff options
author | Robert Adams | 2012-07-20 14:08:29 -0700 |
---|---|---|
committer | Robert Adams | 2012-07-20 14:08:29 -0700 |
commit | ca3b6b1f90f89ab3be4a43863da81f9df0993e2f (patch) | |
tree | 3100b50cd2f7aba86edec7ed9600b1e434cc2672 /OpenSim/Region | |
parent | Remove an added but unnecessary dependency in prebuild.xml (diff) | |
download | opensim-SC-ca3b6b1f90f89ab3be4a43863da81f9df0993e2f.zip opensim-SC-ca3b6b1f90f89ab3be4a43863da81f9df0993e2f.tar.gz opensim-SC-ca3b6b1f90f89ab3be4a43863da81f9df0993e2f.tar.bz2 opensim-SC-ca3b6b1f90f89ab3be4a43863da81f9df0993e2f.tar.xz |
BulletSim: more detail logging for vehicle and general physics debugging.
Physical linksets are fully functional.
Tweeking of the vehicle code to make it semi-work.
Utilize the new API2 for some setting operations.
Add GetOrientation() API call for proper reporting of children of linksets.
Changes the interface between C# and C++ code so old DLLs won't work!
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 52 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 168 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 48 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | 51 |
4 files changed, 244 insertions, 75 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 4c5bc85..c197e61 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -613,23 +613,30 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
613 | MoveAngular(pTimestep); | 613 | MoveAngular(pTimestep); |
614 | LimitRotation(pTimestep); | 614 | LimitRotation(pTimestep); |
615 | 615 | ||
616 | DetailLog("{0},step,done,pos={1},force={2},velocity={3},angvel={4}", | 616 | DetailLog("{0},Dynamics,done,pos={1},force={2},velocity={3},angvel={4}", |
617 | m_prim.LocalID, m_prim.Position, m_prim.Force, m_prim.Velocity, m_prim.RotationalVelocity); | 617 | m_prim.LocalID, m_prim.Position, m_prim.Force, m_prim.Velocity, m_prim.RotationalVelocity); |
618 | }// end Step | 618 | }// end Step |
619 | 619 | ||
620 | private void MoveLinear(float pTimestep) | 620 | private void MoveLinear(float pTimestep) |
621 | { | 621 | { |
622 | if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) // requested m_linearMotorDirection is significant | 622 | // requested m_linearMotorDirection is significant |
623 | // if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) | ||
624 | if (m_linearMotorDirection.LengthSquared() > 0.0001f) | ||
623 | { | 625 | { |
624 | Vector3 origDir = m_linearMotorDirection; | 626 | Vector3 origDir = m_linearMotorDirection; |
625 | Vector3 origVel = m_lastLinearVelocityVector; | 627 | Vector3 origVel = m_lastLinearVelocityVector; |
626 | 628 | ||
627 | // add drive to body | 629 | // add drive to body |
628 | Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep); | 630 | // Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep); |
629 | m_lastLinearVelocityVector += (addAmount*10); // lastLinearVelocityVector is the current body velocity vector? | 631 | Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale); |
632 | // lastLinearVelocityVector is the current body velocity vector? | ||
633 | // RA: Not sure what the *10 is for. A correction for pTimestep? | ||
634 | // m_lastLinearVelocityVector += (addAmount*10); | ||
635 | m_lastLinearVelocityVector += addAmount; | ||
630 | 636 | ||
631 | // This will work temporarily, but we really need to compare speed on an axis | 637 | // This will work temporarily, but we really need to compare speed on an axis |
632 | // KF: Limit body velocity to applied velocity? | 638 | // KF: Limit body velocity to applied velocity? |
639 | // Limit the velocity vector to less than the last set linear motor direction | ||
633 | if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X)) | 640 | if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X)) |
634 | m_lastLinearVelocityVector.X = m_linearMotorDirectionLASTSET.X; | 641 | m_lastLinearVelocityVector.X = m_linearMotorDirectionLASTSET.X; |
635 | if (Math.Abs(m_lastLinearVelocityVector.Y) > Math.Abs(m_linearMotorDirectionLASTSET.Y)) | 642 | if (Math.Abs(m_lastLinearVelocityVector.Y) > Math.Abs(m_linearMotorDirectionLASTSET.Y)) |
@@ -641,19 +648,30 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
641 | Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep))); | 648 | Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep))); |
642 | m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f; | 649 | m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f; |
643 | 650 | ||
651 | /* | ||
652 | Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/m_linearMotorTimescale; | ||
653 | m_lastLinearVelocityVector += addAmount; | ||
654 | |||
655 | float decayfraction = (1.0f - 1.0f / m_linearMotorDecayTimescale); | ||
656 | m_linearMotorDirection *= decayfraction; | ||
657 | |||
658 | */ | ||
659 | |||
644 | DetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},add={3},decay={4},dir={5},vel={6}", | 660 | DetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},add={3},decay={4},dir={5},vel={6}", |
645 | m_prim.LocalID, origDir, origVel, addAmount, decayfraction, m_linearMotorDirection, m_lastLinearVelocityVector); | 661 | m_prim.LocalID, origDir, origVel, addAmount, decayfraction, m_linearMotorDirection, m_lastLinearVelocityVector); |
646 | } | 662 | } |
647 | else | 663 | else |
648 | { // requested is not significant | 664 | { |
649 | // if what remains of applied is small, zero it. | 665 | // if what remains of applied is small, zero it. |
650 | if (m_lastLinearVelocityVector.ApproxEquals(Vector3.Zero, 0.01f)) | 666 | // if (m_lastLinearVelocityVector.ApproxEquals(Vector3.Zero, 0.01f)) |
651 | m_lastLinearVelocityVector = Vector3.Zero; | 667 | // m_lastLinearVelocityVector = Vector3.Zero; |
668 | m_linearMotorDirection = Vector3.Zero; | ||
669 | m_lastLinearVelocityVector = Vector3.Zero; | ||
652 | } | 670 | } |
653 | 671 | ||
654 | // convert requested object velocity to world-referenced vector | 672 | // convert requested object velocity to world-referenced vector |
655 | m_dir = m_lastLinearVelocityVector; | 673 | Quaternion rotq = m_prim.Orientation; |
656 | m_dir *= m_prim.Orientation; | 674 | m_dir = m_lastLinearVelocityVector * rotq; |
657 | 675 | ||
658 | // Add the various forces into m_dir which will be our new direction vector (velocity) | 676 | // Add the various forces into m_dir which will be our new direction vector (velocity) |
659 | 677 | ||
@@ -708,9 +726,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
708 | m_prim.LocalID, m_BlockingEndPoint, posChange, pos); | 726 | m_prim.LocalID, m_BlockingEndPoint, posChange, pos); |
709 | } | 727 | } |
710 | } | 728 | } |
711 | if (pos.Z < m_prim.Scene.GetTerrainHeightAtXY(pos.X, pos.Y)) | 729 | |
730 | // If below the terrain, move us above the ground a little. | ||
731 | if (pos.Z < m_prim.Scene.GetTerrainHeightAtXYZ(pos)) | ||
712 | { | 732 | { |
713 | pos.Z = m_prim.Scene.GetTerrainHeightAtXY(pos.X, pos.Y) + 2; | 733 | pos.Z = m_prim.Scene.GetTerrainHeightAtXYZ(pos) + 2; |
714 | m_prim.Position = pos; | 734 | m_prim.Position = pos; |
715 | DetailLog("{0},MoveLinear,terrainHeight,pos={1}", m_prim.LocalID, pos); | 735 | DetailLog("{0},MoveLinear,terrainHeight,pos={1}", m_prim.LocalID, pos); |
716 | } | 736 | } |
@@ -816,8 +836,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
816 | // Apply velocity | 836 | // Apply velocity |
817 | m_prim.Velocity = m_dir; | 837 | m_prim.Velocity = m_dir; |
818 | // apply gravity force | 838 | // apply gravity force |
819 | m_prim.Force = grav; | 839 | // Why is this set here? The physics engine already does gravity. |
820 | 840 | // m_prim.AddForce(grav, false); | |
841 | // m_prim.Force = grav; | ||
821 | 842 | ||
822 | // Apply friction | 843 | // Apply friction |
823 | Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep); | 844 | Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep); |
@@ -990,7 +1011,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
990 | // Invoke the detailed logger and output something if it's enabled. | 1011 | // Invoke the detailed logger and output something if it's enabled. |
991 | private void DetailLog(string msg, params Object[] args) | 1012 | private void DetailLog(string msg, params Object[] args) |
992 | { | 1013 | { |
993 | m_prim.Scene.VehicleLogging.Write(msg, args); | 1014 | if (m_prim.Scene.VehicleLoggingEnabled) |
1015 | m_prim.Scene.PhysicsLogging.Write(msg, args); | ||
994 | } | 1016 | } |
995 | } | 1017 | } |
996 | } | 1018 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 5911897..71a4303 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -148,6 +148,7 @@ public sealed class BSPrim : PhysicsActor | |||
148 | public void Destroy() | 148 | public void Destroy() |
149 | { | 149 | { |
150 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); | 150 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); |
151 | // DetailLog("{0},Destroy", LocalID); | ||
151 | // Undo any vehicle properties | 152 | // Undo any vehicle properties |
152 | _vehicle.ProcessTypeChange(Vehicle.TYPE_NONE); | 153 | _vehicle.ProcessTypeChange(Vehicle.TYPE_NONE); |
153 | _scene.RemoveVehiclePrim(this); // just to make sure | 154 | _scene.RemoveVehiclePrim(this); // just to make sure |
@@ -215,6 +216,7 @@ public sealed class BSPrim : PhysicsActor | |||
215 | public override void link(PhysicsActor obj) { | 216 | public override void link(PhysicsActor obj) { |
216 | BSPrim parent = obj as BSPrim; | 217 | BSPrim parent = obj as BSPrim; |
217 | DebugLog("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, obj.LocalID); | 218 | DebugLog("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, obj.LocalID); |
219 | DetailLog("{0},link,parent={1}", LocalID, obj.LocalID); | ||
218 | // TODO: decide if this parent checking needs to happen at taint time | 220 | // TODO: decide if this parent checking needs to happen at taint time |
219 | if (_parentPrim == null) | 221 | if (_parentPrim == null) |
220 | { | 222 | { |
@@ -250,6 +252,7 @@ public sealed class BSPrim : PhysicsActor | |||
250 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen | 252 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen |
251 | DebugLog("{0}: delink {1}/{2}. Parent={3}", LogHeader, _avName, _localID, | 253 | DebugLog("{0}: delink {1}/{2}. Parent={3}", LogHeader, _avName, _localID, |
252 | (_parentPrim==null ? "NULL" : _parentPrim._avName+"/"+_parentPrim.LocalID.ToString())); | 254 | (_parentPrim==null ? "NULL" : _parentPrim._avName+"/"+_parentPrim.LocalID.ToString())); |
255 | DetailLog("{0},delink,parent={1}", LocalID, (_parentPrim==null ? "NULL" : _parentPrim.LocalID.ToString())); | ||
253 | if (_parentPrim != null) | 256 | if (_parentPrim != null) |
254 | { | 257 | { |
255 | _parentPrim.RemoveChildFromLinkset(this); | 258 | _parentPrim.RemoveChildFromLinkset(this); |
@@ -266,6 +269,7 @@ public sealed class BSPrim : PhysicsActor | |||
266 | if (!_childrenPrims.Contains(child)) | 269 | if (!_childrenPrims.Contains(child)) |
267 | { | 270 | { |
268 | DebugLog("{0}: AddChildToLinkset: adding child {1} to {2}", LogHeader, child.LocalID, this.LocalID); | 271 | DebugLog("{0}: AddChildToLinkset: adding child {1} to {2}", LogHeader, child.LocalID, this.LocalID); |
272 | DetailLog("{0},AddChildToLinkset,child={1}", LocalID, pchild.LocalID); | ||
269 | _childrenPrims.Add(child); | 273 | _childrenPrims.Add(child); |
270 | child._parentPrim = this; // the child has gained a parent | 274 | child._parentPrim = this; // the child has gained a parent |
271 | RecreateGeomAndObject(); // rebuild my shape with the new child added | 275 | RecreateGeomAndObject(); // rebuild my shape with the new child added |
@@ -284,6 +288,7 @@ public sealed class BSPrim : PhysicsActor | |||
284 | if (_childrenPrims.Contains(child)) | 288 | if (_childrenPrims.Contains(child)) |
285 | { | 289 | { |
286 | DebugLog("{0}: RemoveChildFromLinkset: Removing constraint to {1}", LogHeader, child.LocalID); | 290 | DebugLog("{0}: RemoveChildFromLinkset: Removing constraint to {1}", LogHeader, child.LocalID); |
291 | DetailLog("{0},RemoveChildToLinkset,child={1}", LocalID, pchild.LocalID); | ||
287 | if (!BulletSimAPI.RemoveConstraintByID(_scene.WorldID, child.LocalID)) | 292 | if (!BulletSimAPI.RemoveConstraintByID(_scene.WorldID, child.LocalID)) |
288 | { | 293 | { |
289 | m_log.ErrorFormat("{0}: RemoveChildFromLinkset: Failed remove constraint for {1}", LogHeader, child.LocalID); | 294 | m_log.ErrorFormat("{0}: RemoveChildFromLinkset: Failed remove constraint for {1}", LogHeader, child.LocalID); |
@@ -317,20 +322,28 @@ public sealed class BSPrim : PhysicsActor | |||
317 | base.RequestPhysicsterseUpdate(); | 322 | base.RequestPhysicsterseUpdate(); |
318 | } | 323 | } |
319 | 324 | ||
320 | public override void LockAngularMotion(OMV.Vector3 axis) { return; } | 325 | public override void LockAngularMotion(OMV.Vector3 axis) |
326 | { | ||
327 | DetailLog("{0},LockAngularMotion,call,axis={1}", LocalID, axis); | ||
328 | return; | ||
329 | } | ||
321 | 330 | ||
322 | public override OMV.Vector3 Position { | 331 | public override OMV.Vector3 Position { |
323 | get { | 332 | get { |
324 | // don't do the following GetObjectPosition because this function is called a zillion times | 333 | // child prims move around based on their parent. Need to get the latest location |
334 | if (_parentPrim != null) | ||
335 | _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); | ||
336 | // don't do the GetObjectPosition for root elements because this function is called a zillion times | ||
325 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); | 337 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); |
326 | return _position; | 338 | return _position; |
327 | } | 339 | } |
328 | set { | 340 | set { |
329 | _position = value; | 341 | _position = value; |
342 | // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? | ||
330 | _scene.TaintedObject(delegate() | 343 | _scene.TaintedObject(delegate() |
331 | { | 344 | { |
345 | DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | ||
332 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 346 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); |
333 | // m_log.DebugFormat("{0}: setPosition: id={1}, position={2}", LogHeader, _localID, _position); | ||
334 | }); | 347 | }); |
335 | } | 348 | } |
336 | } | 349 | } |
@@ -343,6 +356,7 @@ public sealed class BSPrim : PhysicsActor | |||
343 | _force = value; | 356 | _force = value; |
344 | _scene.TaintedObject(delegate() | 357 | _scene.TaintedObject(delegate() |
345 | { | 358 | { |
359 | DetailLog("{0},SetForce,taint,force={1}", LocalID, _force); | ||
346 | BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); | 360 | BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); |
347 | }); | 361 | }); |
348 | } | 362 | } |
@@ -354,15 +368,23 @@ public sealed class BSPrim : PhysicsActor | |||
354 | } | 368 | } |
355 | set { | 369 | set { |
356 | Vehicle type = (Vehicle)value; | 370 | Vehicle type = (Vehicle)value; |
357 | _vehicle.ProcessTypeChange(type); | ||
358 | _scene.TaintedObject(delegate() | 371 | _scene.TaintedObject(delegate() |
359 | { | 372 | { |
373 | DetailLog("{0},SetVehicleType,taint,type={1}", LocalID, type); | ||
374 | _vehicle.ProcessTypeChange(type); | ||
360 | if (type == Vehicle.TYPE_NONE) | 375 | if (type == Vehicle.TYPE_NONE) |
361 | { | 376 | { |
362 | _scene.RemoveVehiclePrim(this); | 377 | _scene.RemoveVehiclePrim(this); |
363 | } | 378 | } |
364 | else | 379 | else |
365 | { | 380 | { |
381 | _scene.TaintedObject(delegate() | ||
382 | { | ||
383 | // Tell the physics engine to clear state | ||
384 | IntPtr obj = BulletSimAPI.GetBodyHandleWorldID2(_scene.WorldID, LocalID); | ||
385 | BulletSimAPI.ClearForces2(obj); | ||
386 | }); | ||
387 | |||
366 | // make it so the scene will call us each tick to do vehicle things | 388 | // make it so the scene will call us each tick to do vehicle things |
367 | _scene.AddVehiclePrim(this); | 389 | _scene.AddVehiclePrim(this); |
368 | } | 390 | } |
@@ -372,21 +394,39 @@ public sealed class BSPrim : PhysicsActor | |||
372 | } | 394 | } |
373 | public override void VehicleFloatParam(int param, float value) | 395 | public override void VehicleFloatParam(int param, float value) |
374 | { | 396 | { |
375 | _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); | 397 | m_log.DebugFormat("{0} VehicleFloatParam. {1} <= {2}", LogHeader, param, value); |
398 | _scene.TaintedObject(delegate() | ||
399 | { | ||
400 | _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); | ||
401 | }); | ||
376 | } | 402 | } |
377 | public override void VehicleVectorParam(int param, OMV.Vector3 value) | 403 | public override void VehicleVectorParam(int param, OMV.Vector3 value) |
378 | { | 404 | { |
379 | _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); | 405 | m_log.DebugFormat("{0} VehicleVectorParam. {1} <= {2}", LogHeader, param, value); |
406 | _scene.TaintedObject(delegate() | ||
407 | { | ||
408 | _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); | ||
409 | }); | ||
380 | } | 410 | } |
381 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) | 411 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) |
382 | { | 412 | { |
383 | _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); | 413 | m_log.DebugFormat("{0} VehicleRotationParam. {1} <= {2}", LogHeader, param, rotation); |
414 | _scene.TaintedObject(delegate() | ||
415 | { | ||
416 | _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); | ||
417 | }); | ||
384 | } | 418 | } |
385 | public override void VehicleFlags(int param, bool remove) | 419 | public override void VehicleFlags(int param, bool remove) |
386 | { | 420 | { |
387 | _vehicle.ProcessVehicleFlags(param, remove); | 421 | m_log.DebugFormat("{0} VehicleFlags. {1}. Remove={2}", LogHeader, param, remove); |
422 | _scene.TaintedObject(delegate() | ||
423 | { | ||
424 | _vehicle.ProcessVehicleFlags(param, remove); | ||
425 | }); | ||
388 | } | 426 | } |
389 | // Called each simulation step to advance vehicle characteristics | 427 | |
428 | // Called each simulation step to advance vehicle characteristics. | ||
429 | // Called from Scene when doing simulation step so we're in taint processing time. | ||
390 | public void StepVehicle(float timeStep) | 430 | public void StepVehicle(float timeStep) |
391 | { | 431 | { |
392 | _vehicle.Step(timeStep); | 432 | _vehicle.Step(timeStep); |
@@ -395,14 +435,11 @@ public sealed class BSPrim : PhysicsActor | |||
395 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more | 435 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more |
396 | public override void SetVolumeDetect(int param) { | 436 | public override void SetVolumeDetect(int param) { |
397 | bool newValue = (param != 0); | 437 | bool newValue = (param != 0); |
398 | if (_isVolumeDetect != newValue) | 438 | _isVolumeDetect = newValue; |
439 | _scene.TaintedObject(delegate() | ||
399 | { | 440 | { |
400 | _isVolumeDetect = newValue; | 441 | SetObjectDynamic(); |
401 | _scene.TaintedObject(delegate() | 442 | }); |
402 | { | ||
403 | SetObjectDynamic(); | ||
404 | }); | ||
405 | } | ||
406 | return; | 443 | return; |
407 | } | 444 | } |
408 | 445 | ||
@@ -410,9 +447,11 @@ public sealed class BSPrim : PhysicsActor | |||
410 | public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } | 447 | public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } |
411 | public override OMV.Vector3 Velocity { | 448 | public override OMV.Vector3 Velocity { |
412 | get { return _velocity; } | 449 | get { return _velocity; } |
413 | set { _velocity = value; | 450 | set { |
451 | _velocity = value; | ||
414 | _scene.TaintedObject(delegate() | 452 | _scene.TaintedObject(delegate() |
415 | { | 453 | { |
454 | DetailLog("{0},SetVelocity,taint,vel={1}", LocalID, _velocity); | ||
416 | BulletSimAPI.SetObjectVelocity(_scene.WorldID, LocalID, _velocity); | 455 | BulletSimAPI.SetObjectVelocity(_scene.WorldID, LocalID, _velocity); |
417 | }); | 456 | }); |
418 | } | 457 | } |
@@ -420,6 +459,7 @@ public sealed class BSPrim : PhysicsActor | |||
420 | public override OMV.Vector3 Torque { | 459 | public override OMV.Vector3 Torque { |
421 | get { return _torque; } | 460 | get { return _torque; } |
422 | set { _torque = value; | 461 | set { _torque = value; |
462 | DetailLog("{0},SetTorque,call,torque={1}", LocalID, _torque); | ||
423 | } | 463 | } |
424 | } | 464 | } |
425 | public override float CollisionScore { | 465 | public override float CollisionScore { |
@@ -432,13 +472,21 @@ public sealed class BSPrim : PhysicsActor | |||
432 | set { _acceleration = value; } | 472 | set { _acceleration = value; } |
433 | } | 473 | } |
434 | public override OMV.Quaternion Orientation { | 474 | public override OMV.Quaternion Orientation { |
435 | get { return _orientation; } | 475 | get { |
476 | if (_parentPrim != null) | ||
477 | { | ||
478 | // children move around because tied to parent. Get a fresh value. | ||
479 | _orientation = BulletSimAPI.GetObjectOrientation(_scene.WorldID, LocalID); | ||
480 | } | ||
481 | return _orientation; | ||
482 | } | ||
436 | set { | 483 | set { |
437 | _orientation = value; | 484 | _orientation = value; |
438 | // m_log.DebugFormat("{0}: set orientation: id={1}, ori={2}", LogHeader, LocalID, _orientation); | 485 | // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? |
439 | _scene.TaintedObject(delegate() | 486 | _scene.TaintedObject(delegate() |
440 | { | 487 | { |
441 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); | 488 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); |
489 | DetailLog("{0},SetOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); | ||
442 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 490 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); |
443 | }); | 491 | }); |
444 | } | 492 | } |
@@ -471,8 +519,9 @@ public sealed class BSPrim : PhysicsActor | |||
471 | get { return !IsPhantom && !_isVolumeDetect; } | 519 | get { return !IsPhantom && !_isVolumeDetect; } |
472 | } | 520 | } |
473 | 521 | ||
474 | // make gravity work if the object is physical and not selected | 522 | // Make gravity work if the object is physical and not selected |
475 | // no locking here because only called when it is safe | 523 | // No locking here because only called when it is safe |
524 | // Only called at taint time so it is save to call into Bullet. | ||
476 | private void SetObjectDynamic() | 525 | private void SetObjectDynamic() |
477 | { | 526 | { |
478 | // m_log.DebugFormat("{0}: ID={1}, SetObjectDynamic: IsStatic={2}, IsSolid={3}", LogHeader, _localID, IsStatic, IsSolid); | 527 | // m_log.DebugFormat("{0}: ID={1}, SetObjectDynamic: IsStatic={2}, IsSolid={3}", LogHeader, _localID, IsStatic, IsSolid); |
@@ -489,6 +538,7 @@ public sealed class BSPrim : PhysicsActor | |||
489 | RecreateGeomAndObject(); | 538 | RecreateGeomAndObject(); |
490 | 539 | ||
491 | } | 540 | } |
541 | DetailLog("{0},SetObjectDynamic,taint,static={1},solid={2},mass={3}", LocalID, IsStatic, IsSolid, _mass); | ||
492 | BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), _mass); | 542 | BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), _mass); |
493 | } | 543 | } |
494 | 544 | ||
@@ -529,11 +579,24 @@ public sealed class BSPrim : PhysicsActor | |||
529 | set { _floatOnWater = value; } | 579 | set { _floatOnWater = value; } |
530 | } | 580 | } |
531 | public override OMV.Vector3 RotationalVelocity { | 581 | public override OMV.Vector3 RotationalVelocity { |
532 | get { return _rotationalVelocity; } | 582 | get { |
533 | set { _rotationalVelocity = value; | 583 | /* |
584 | OMV.Vector3 pv = OMV.Vector3.Zero; | ||
585 | // if close to zero, report zero | ||
586 | // This is copied from ODE but I'm not sure why it returns zero but doesn't | ||
587 | // zero the property in the physics engine. | ||
588 | if (_rotationalVelocity.ApproxEquals(pv, 0.2f)) | ||
589 | return pv; | ||
590 | */ | ||
591 | |||
592 | return _rotationalVelocity; | ||
593 | } | ||
594 | set { | ||
595 | _rotationalVelocity = value; | ||
534 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); | 596 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); |
535 | _scene.TaintedObject(delegate() | 597 | _scene.TaintedObject(delegate() |
536 | { | 598 | { |
599 | DetailLog("{0},SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | ||
537 | BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity); | 600 | BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity); |
538 | }); | 601 | }); |
539 | } | 602 | } |
@@ -546,11 +609,13 @@ public sealed class BSPrim : PhysicsActor | |||
546 | } | 609 | } |
547 | public override float Buoyancy { | 610 | public override float Buoyancy { |
548 | get { return _buoyancy; } | 611 | get { return _buoyancy; } |
549 | set { _buoyancy = value; | 612 | set { |
550 | _scene.TaintedObject(delegate() | 613 | _buoyancy = value; |
551 | { | 614 | _scene.TaintedObject(delegate() |
552 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy); | 615 | { |
553 | }); | 616 | DetailLog("{0},SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
617 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy); | ||
618 | }); | ||
554 | } | 619 | } |
555 | } | 620 | } |
556 | 621 | ||
@@ -586,27 +651,45 @@ public sealed class BSPrim : PhysicsActor | |||
586 | public override float APIDStrength { set { return; } } | 651 | public override float APIDStrength { set { return; } } |
587 | public override float APIDDamping { set { return; } } | 652 | public override float APIDDamping { set { return; } } |
588 | 653 | ||
654 | private List<OMV.Vector3> m_accumulatedForces = new List<OMV.Vector3>(); | ||
589 | public override void AddForce(OMV.Vector3 force, bool pushforce) { | 655 | public override void AddForce(OMV.Vector3 force, bool pushforce) { |
590 | if (force.IsFinite()) | 656 | if (force.IsFinite()) |
591 | { | 657 | { |
592 | _force.X += force.X; | 658 | // _force += force; |
593 | _force.Y += force.Y; | 659 | lock (m_accumulatedForces) |
594 | _force.Z += force.Z; | 660 | m_accumulatedForces.Add(new OMV.Vector3(force)); |
595 | } | 661 | } |
596 | else | 662 | else |
597 | { | 663 | { |
598 | m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader); | 664 | m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader); |
665 | return; | ||
599 | } | 666 | } |
600 | _scene.TaintedObject(delegate() | 667 | _scene.TaintedObject(delegate() |
601 | { | 668 | { |
602 | BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); | 669 | lock (m_accumulatedForces) |
670 | { | ||
671 | if (m_accumulatedForces.Count > 0) | ||
672 | { | ||
673 | OMV.Vector3 fSum = OMV.Vector3.Zero; | ||
674 | foreach (OMV.Vector3 v in m_accumulatedForces) | ||
675 | { | ||
676 | fSum += v; | ||
677 | } | ||
678 | m_accumulatedForces.Clear(); | ||
679 | |||
680 | DetailLog("{0},SetObjectForce,taint,force={1}", LocalID, fSum); | ||
681 | BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, fSum); | ||
682 | } | ||
683 | } | ||
603 | }); | 684 | }); |
604 | } | 685 | } |
605 | 686 | ||
606 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { | 687 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { |
688 | DetailLog("{0},AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce); | ||
607 | // m_log.DebugFormat("{0}: AddAngularForce. f={1}, push={2}", LogHeader, force, pushforce); | 689 | // m_log.DebugFormat("{0}: AddAngularForce. f={1}, push={2}", LogHeader, force, pushforce); |
608 | } | 690 | } |
609 | public override void SetMomentum(OMV.Vector3 momentum) { | 691 | public override void SetMomentum(OMV.Vector3 momentum) { |
692 | DetailLog("{0},SetMomentum,call,mom={1}", LocalID, momentum); | ||
610 | } | 693 | } |
611 | public override void SubscribeEvents(int ms) { | 694 | public override void SubscribeEvents(int ms) { |
612 | _subscribedEventsMs = ms; | 695 | _subscribedEventsMs = ms; |
@@ -931,6 +1014,7 @@ public sealed class BSPrim : PhysicsActor | |||
931 | { | 1014 | { |
932 | // m_log.DebugFormat("{0}: CreateGeom: Defaulting to sphere of size {1}", LogHeader, _size); | 1015 | // m_log.DebugFormat("{0}: CreateGeom: Defaulting to sphere of size {1}", LogHeader, _size); |
933 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_SPHERE; | 1016 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_SPHERE; |
1017 | DetailLog("{0},CreateGeom,sphere", LocalID); | ||
934 | // Bullet native objects are scaled by the Bullet engine so pass the size in | 1018 | // Bullet native objects are scaled by the Bullet engine so pass the size in |
935 | _scale = _size; | 1019 | _scale = _size; |
936 | } | 1020 | } |
@@ -938,6 +1022,7 @@ public sealed class BSPrim : PhysicsActor | |||
938 | else | 1022 | else |
939 | { | 1023 | { |
940 | // m_log.DebugFormat("{0}: CreateGeom: Defaulting to box. lid={1}, size={2}", LogHeader, LocalID, _size); | 1024 | // m_log.DebugFormat("{0}: CreateGeom: Defaulting to box. lid={1}, size={2}", LogHeader, LocalID, _size); |
1025 | DetailLog("{0},CreateGeom,box", LocalID); | ||
941 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX; | 1026 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX; |
942 | _scale = _size; | 1027 | _scale = _size; |
943 | } | 1028 | } |
@@ -974,10 +1059,12 @@ public sealed class BSPrim : PhysicsActor | |||
974 | // if this new shape is the same as last time, don't recreate the mesh | 1059 | // if this new shape is the same as last time, don't recreate the mesh |
975 | if (_meshKey == newMeshKey) return; | 1060 | if (_meshKey == newMeshKey) return; |
976 | 1061 | ||
1062 | DetailLog("{0},CreateGeomMesh,create,key={1}", LocalID, _meshKey); | ||
977 | // Since we're recreating new, get rid of any previously generated shape | 1063 | // Since we're recreating new, get rid of any previously generated shape |
978 | if (_meshKey != 0) | 1064 | if (_meshKey != 0) |
979 | { | 1065 | { |
980 | // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey); | 1066 | // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey); |
1067 | DetailLog("{0},CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey); | ||
981 | BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); | 1068 | BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); |
982 | _mesh = null; | 1069 | _mesh = null; |
983 | _meshKey = 0; | 1070 | _meshKey = 0; |
@@ -1007,6 +1094,7 @@ public sealed class BSPrim : PhysicsActor | |||
1007 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH; | 1094 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH; |
1008 | // meshes are already scaled by the meshmerizer | 1095 | // meshes are already scaled by the meshmerizer |
1009 | _scale = new OMV.Vector3(1f, 1f, 1f); | 1096 | _scale = new OMV.Vector3(1f, 1f, 1f); |
1097 | DetailLog("{0},CreateGeomMesh,done", LocalID); | ||
1010 | return; | 1098 | return; |
1011 | } | 1099 | } |
1012 | 1100 | ||
@@ -1020,13 +1108,17 @@ public sealed class BSPrim : PhysicsActor | |||
1020 | // if the hull hasn't changed, don't rebuild it | 1108 | // if the hull hasn't changed, don't rebuild it |
1021 | if (newHullKey == _hullKey) return; | 1109 | if (newHullKey == _hullKey) return; |
1022 | 1110 | ||
1111 | DetailLog("{0},CreateGeomHull,create,key={1}", LocalID, _meshKey); | ||
1112 | |||
1023 | // Since we're recreating new, get rid of any previously generated shape | 1113 | // Since we're recreating new, get rid of any previously generated shape |
1024 | if (_hullKey != 0) | 1114 | if (_hullKey != 0) |
1025 | { | 1115 | { |
1026 | // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey); | 1116 | // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey); |
1117 | DetailLog("{0},CreateGeomHull,deleteOldHull,key={1}", LocalID, _meshKey); | ||
1027 | BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey); | 1118 | BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey); |
1028 | _hullKey = 0; | 1119 | _hullKey = 0; |
1029 | _hulls.Clear(); | 1120 | _hulls.Clear(); |
1121 | DetailLog("{0},CreateGeomHull,deleteOldMesh,key={1}", LocalID, _meshKey); | ||
1030 | BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); | 1122 | BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); |
1031 | _mesh = null; // the mesh cannot match either | 1123 | _mesh = null; // the mesh cannot match either |
1032 | _meshKey = 0; | 1124 | _meshKey = 0; |
@@ -1123,6 +1215,7 @@ public sealed class BSPrim : PhysicsActor | |||
1123 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; | 1215 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; |
1124 | // meshes are already scaled by the meshmerizer | 1216 | // meshes are already scaled by the meshmerizer |
1125 | _scale = new OMV.Vector3(1f, 1f, 1f); | 1217 | _scale = new OMV.Vector3(1f, 1f, 1f); |
1218 | DetailLog("{0},CreateGeomHull,done", LocalID); | ||
1126 | return; | 1219 | return; |
1127 | } | 1220 | } |
1128 | 1221 | ||
@@ -1310,6 +1403,7 @@ public sealed class BSPrim : PhysicsActor | |||
1310 | */ | 1403 | */ |
1311 | 1404 | ||
1312 | // Don't check for damping here -- it's done in BulletSim and SceneObjectPart. | 1405 | // Don't check for damping here -- it's done in BulletSim and SceneObjectPart. |
1406 | |||
1313 | // Updates only for individual prims and for the root object of a linkset. | 1407 | // Updates only for individual prims and for the root object of a linkset. |
1314 | if (this._parentPrim == null) | 1408 | if (this._parentPrim == null) |
1315 | { | 1409 | { |
@@ -1319,8 +1413,12 @@ public sealed class BSPrim : PhysicsActor | |||
1319 | _velocity = entprop.Velocity; | 1413 | _velocity = entprop.Velocity; |
1320 | _acceleration = entprop.Acceleration; | 1414 | _acceleration = entprop.Acceleration; |
1321 | _rotationalVelocity = entprop.RotationalVelocity; | 1415 | _rotationalVelocity = entprop.RotationalVelocity; |
1416 | |||
1322 | // m_log.DebugFormat("{0}: RequestTerseUpdate. id={1}, ch={2}, pos={3}, rot={4}, vel={5}, acc={6}, rvel={7}", | 1417 | // m_log.DebugFormat("{0}: RequestTerseUpdate. id={1}, ch={2}, pos={3}, rot={4}, vel={5}, acc={6}, rvel={7}", |
1323 | // LogHeader, LocalID, changed, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); | 1418 | // LogHeader, LocalID, changed, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); |
1419 | DetailLog("{0},UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | ||
1420 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); | ||
1421 | |||
1324 | base.RequestPhysicsterseUpdate(); | 1422 | base.RequestPhysicsterseUpdate(); |
1325 | } | 1423 | } |
1326 | } | 1424 | } |
@@ -1361,5 +1459,11 @@ public sealed class BSPrim : PhysicsActor | |||
1361 | collisionCollection.Clear(); | 1459 | collisionCollection.Clear(); |
1362 | } | 1460 | } |
1363 | } | 1461 | } |
1462 | |||
1463 | // Invoke the detailed logger and output something if it's enabled. | ||
1464 | private void DetailLog(string msg, params Object[] args) | ||
1465 | { | ||
1466 | Scene.PhysicsLogging.Write(msg, args); | ||
1467 | } | ||
1364 | } | 1468 | } |
1365 | } | 1469 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index c4b4332..9d41ce8 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | |||
@@ -30,9 +30,9 @@ using System.Runtime.InteropServices; | |||
30 | using System.Text; | 30 | using System.Text; |
31 | using System.Threading; | 31 | using System.Threading; |
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Region.CoreModules.Framework.Statistics.Logging; | ||
34 | using OpenSim.Region.Framework; | 33 | using OpenSim.Region.Framework; |
35 | using OpenSim.Region.Physics.Manager; | 34 | using OpenSim.Region.Physics.Manager; |
35 | using Logging = OpenSim.Region.CoreModules.Framework.Statistics.Logging; | ||
36 | using Nini.Config; | 36 | using Nini.Config; |
37 | using log4net; | 37 | using log4net; |
38 | using OpenMetaverse; | 38 | using OpenMetaverse; |
@@ -45,15 +45,17 @@ using OpenMetaverse; | |||
45 | // Compute physics FPS reasonably | 45 | // Compute physics FPS reasonably |
46 | // Based on material, set density and friction | 46 | // Based on material, set density and friction |
47 | // More efficient memory usage when passing hull information from BSPrim to BulletSim | 47 | // More efficient memory usage when passing hull information from BSPrim to BulletSim |
48 | // Move all logic out of the C++ code and into the C# code for easier future modifications. | ||
48 | // Four states of prim: Physical, regular, phantom and selected. Are we modeling these correctly? | 49 | // Four states of prim: Physical, regular, phantom and selected. Are we modeling these correctly? |
49 | // In SL one can set both physical and phantom (gravity, does not effect others, makes collisions with ground) | 50 | // In SL one can set both physical and phantom (gravity, does not effect others, makes collisions with ground) |
50 | // At the moment, physical and phantom causes object to drop through the terrain | 51 | // At the moment, physical and phantom causes object to drop through the terrain |
51 | // Physical phantom objects and related typing (collision options ) | 52 | // Physical phantom objects and related typing (collision options ) |
53 | // Use collision masks for collision with terrain and phantom objects | ||
52 | // Check out llVolumeDetect. Must do something for that. | 54 | // Check out llVolumeDetect. Must do something for that. |
53 | // Should prim.link() and prim.delink() membership checking happen at taint time? | 55 | // Should prim.link() and prim.delink() membership checking happen at taint time? |
56 | // changing the position and orientation of a linked prim must rebuild the constraint with the root. | ||
54 | // Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once | 57 | // Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once |
55 | // Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect | 58 | // Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect |
56 | // Use collision masks for collision with terrain and phantom objects | ||
57 | // Implement the genCollisions feature in BulletSim::SetObjectProperties (don't pass up unneeded collisions) | 59 | // Implement the genCollisions feature in BulletSim::SetObjectProperties (don't pass up unneeded collisions) |
58 | // Implement LockAngularMotion | 60 | // Implement LockAngularMotion |
59 | // Decide if clearing forces is the right thing to do when setting position (BulletSim::SetObjectTranslation) | 61 | // Decide if clearing forces is the right thing to do when setting position (BulletSim::SetObjectTranslation) |
@@ -61,9 +63,6 @@ using OpenMetaverse; | |||
61 | // Remove mesh and Hull stuff. Use mesh passed to bullet and use convexdecom from bullet. | 63 | // Remove mesh and Hull stuff. Use mesh passed to bullet and use convexdecom from bullet. |
62 | // Add PID movement operations. What does ScenePresence.MoveToTarget do? | 64 | // Add PID movement operations. What does ScenePresence.MoveToTarget do? |
63 | // Check terrain size. 128 or 127? | 65 | // Check terrain size. 128 or 127? |
64 | // Multiple contact points on collision? | ||
65 | // See code in ode::near... calls to collision_accounting_events() | ||
66 | // (This might not be a problem. ODE collects all the collisions with one object in one tick.) | ||
67 | // Raycast | 66 | // Raycast |
68 | // | 67 | // |
69 | namespace OpenSim.Region.Physics.BulletSPlugin | 68 | namespace OpenSim.Region.Physics.BulletSPlugin |
@@ -160,17 +159,14 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
160 | private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; | 159 | private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; |
161 | 160 | ||
162 | // Sometimes you just have to log everything. | 161 | // Sometimes you just have to log everything. |
163 | public LogWriter PhysicsLogging; | 162 | public Logging.LogWriter PhysicsLogging; |
164 | private bool m_physicsLoggingEnabled; | 163 | private bool m_physicsLoggingEnabled; |
165 | private string m_physicsLoggingDir; | 164 | private string m_physicsLoggingDir; |
166 | private string m_physicsLoggingPrefix; | 165 | private string m_physicsLoggingPrefix; |
167 | private int m_physicsLoggingFileMinutes; | 166 | private int m_physicsLoggingFileMinutes; |
168 | 167 | ||
169 | public LogWriter VehicleLogging; | ||
170 | private bool m_vehicleLoggingEnabled; | 168 | private bool m_vehicleLoggingEnabled; |
171 | private string m_vehicleLoggingDir; | 169 | public bool VehicleLoggingEnabled { get { return m_vehicleLoggingEnabled; } } |
172 | private string m_vehicleLoggingPrefix; | ||
173 | private int m_vehicleLoggingFileMinutes; | ||
174 | 170 | ||
175 | public BSScene(string identifier) | 171 | public BSScene(string identifier) |
176 | { | 172 | { |
@@ -197,19 +193,11 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
197 | // can be left in and every call doesn't have to check for null. | 193 | // can be left in and every call doesn't have to check for null. |
198 | if (m_physicsLoggingEnabled) | 194 | if (m_physicsLoggingEnabled) |
199 | { | 195 | { |
200 | PhysicsLogging = new LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes); | 196 | PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes); |
201 | } | 197 | } |
202 | else | 198 | else |
203 | { | 199 | { |
204 | PhysicsLogging = new LogWriter(); | 200 | PhysicsLogging = new Logging.LogWriter(); |
205 | } | ||
206 | if (m_vehicleLoggingEnabled) | ||
207 | { | ||
208 | VehicleLogging = new LogWriter(m_vehicleLoggingDir, m_vehicleLoggingPrefix, m_vehicleLoggingFileMinutes); | ||
209 | } | ||
210 | else | ||
211 | { | ||
212 | VehicleLogging = new LogWriter(); | ||
213 | } | 201 | } |
214 | 202 | ||
215 | // Get the version of the DLL | 203 | // Get the version of the DLL |
@@ -218,11 +206,14 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
218 | // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion); | 206 | // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion); |
219 | 207 | ||
220 | // if Debug, enable logging from the unmanaged code | 208 | // if Debug, enable logging from the unmanaged code |
221 | if (m_log.IsDebugEnabled) | 209 | if (m_log.IsDebugEnabled || PhysicsLogging.Enabled) |
222 | { | 210 | { |
223 | m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader); | 211 | m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader); |
224 | // the handle is saved to it doesn't get freed after this call | 212 | if (PhysicsLogging.Enabled) |
225 | m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger); | 213 | m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog); |
214 | else | ||
215 | m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger); | ||
216 | // the handle is saved in a variable to make sure it doesn't get freed after this call | ||
226 | BulletSimAPI.SetDebugLogCallback(m_DebugLogCallbackHandle); | 217 | BulletSimAPI.SetDebugLogCallback(m_DebugLogCallbackHandle); |
227 | } | 218 | } |
228 | 219 | ||
@@ -363,9 +354,6 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
363 | m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5); | 354 | m_physicsLoggingFileMinutes = pConfig.GetInt("PhysicsLoggingFileMinutes", 5); |
364 | // Very detailed logging for vehicle debugging | 355 | // Very detailed logging for vehicle debugging |
365 | m_vehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false); | 356 | m_vehicleLoggingEnabled = pConfig.GetBoolean("VehicleLoggingEnabled", false); |
366 | m_vehicleLoggingDir = pConfig.GetString("VehicleLoggingDir", "."); | ||
367 | m_vehicleLoggingPrefix = pConfig.GetString("VehicleLoggingPrefix", "vehicle-"); | ||
368 | m_vehicleLoggingFileMinutes = pConfig.GetInt("VehicleLoggingFileMinutes", 5); | ||
369 | } | 357 | } |
370 | } | 358 | } |
371 | m_params[0] = parms; | 359 | m_params[0] = parms; |
@@ -386,12 +374,17 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
386 | return ret; | 374 | return ret; |
387 | } | 375 | } |
388 | 376 | ||
389 | |||
390 | // Called directly from unmanaged code so don't do much | 377 | // Called directly from unmanaged code so don't do much |
391 | private void BulletLogger(string msg) | 378 | private void BulletLogger(string msg) |
392 | { | 379 | { |
393 | m_log.Debug("[BULLETS UNMANAGED]:" + msg); | 380 | m_log.Debug("[BULLETS UNMANAGED]:" + msg); |
394 | } | 381 | } |
382 | |||
383 | // Called directly from unmanaged code so don't do much | ||
384 | private void BulletLoggerPhysLog(string msg) | ||
385 | { | ||
386 | PhysicsLogging.Write("[BULLETS UNMANAGED]:" + msg); | ||
387 | } | ||
395 | 388 | ||
396 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) | 389 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying) |
397 | { | 390 | { |
@@ -532,7 +525,6 @@ public class BSScene : PhysicsScene, IPhysicsParameters | |||
532 | for (int ii = 0; ii < updatedEntityCount; ii++) | 525 | for (int ii = 0; ii < updatedEntityCount; ii++) |
533 | { | 526 | { |
534 | EntityProperties entprop = m_updateArray[ii]; | 527 | EntityProperties entprop = m_updateArray[ii]; |
535 | // m_log.DebugFormat("{0}: entprop[{1}]: id={2}, pos={3}", LogHeader, ii, entprop.ID, entprop.Position); | ||
536 | BSPrim prim; | 528 | BSPrim prim; |
537 | if (m_prims.TryGetValue(entprop.ID, out prim)) | 529 | if (m_prims.TryGetValue(entprop.ID, out prim)) |
538 | { | 530 | { |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 086f0dc..babb707 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | |||
@@ -146,6 +146,22 @@ public struct ConfigurationParameters | |||
146 | public const float numericFalse = 0f; | 146 | public const float numericFalse = 0f; |
147 | } | 147 | } |
148 | 148 | ||
149 | // Values used by Bullet and BulletSim to control collisions | ||
150 | public enum CollisionFlags : uint | ||
151 | { | ||
152 | STATIC_OBJECT = 1 << 0, | ||
153 | KINEMATIC_OBJECT = 1 << 1, | ||
154 | NO_CONTACT_RESPONSE = 1 << 2, | ||
155 | CUSTOM_MATERIAL_CALLBACK = 1 << 3, | ||
156 | CHARACTER_OBJECT = 1 << 4, | ||
157 | DISABLE_VISUALIZE_OBJECT = 1 << 5, | ||
158 | DISABLE_SPU_COLLISION_PROCESS = 1 << 6, | ||
159 | // Following used by BulletSim to control collisions | ||
160 | VOLUME_DETECT_OBJECT = 1 << 10, | ||
161 | PHANTOM_OBJECT = 1 << 11, | ||
162 | PHYSICAL_OBJECT = 1 << 12, | ||
163 | }; | ||
164 | |||
149 | static class BulletSimAPI { | 165 | static class BulletSimAPI { |
150 | 166 | ||
151 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 167 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
@@ -214,6 +230,9 @@ public static extern bool RemoveConstraint(uint worldID, uint id1, uint id2); | |||
214 | public static extern Vector3 GetObjectPosition(uint WorldID, uint id); | 230 | public static extern Vector3 GetObjectPosition(uint WorldID, uint id); |
215 | 231 | ||
216 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 232 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
233 | public static extern Quaternion GetObjectOrientation(uint WorldID, uint id); | ||
234 | |||
235 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
217 | public static extern bool SetObjectTranslation(uint worldID, uint id, Vector3 position, Quaternion rotation); | 236 | public static extern bool SetObjectTranslation(uint worldID, uint id, Vector3 position, Quaternion rotation); |
218 | 237 | ||
219 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 238 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
@@ -268,5 +287,37 @@ public static extern void DumpBulletStatistics(); | |||
268 | public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); | 287 | public delegate void DebugLogCallback([MarshalAs(UnmanagedType.LPStr)]string msg); |
269 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 288 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
270 | public static extern void SetDebugLogCallback(DebugLogCallback callback); | 289 | public static extern void SetDebugLogCallback(DebugLogCallback callback); |
290 | |||
291 | // =============================================================================== | ||
292 | // =============================================================================== | ||
293 | // =============================================================================== | ||
294 | // A new version of the API that moves all the logic out of the C++ code and into | ||
295 | // the C# code. This will make modifications easier for the next person. | ||
296 | // This interface passes the actual pointers to the objects in the unmanaged | ||
297 | // address space. All the management (calls for creation/destruction/lookup) | ||
298 | // is done in the C# code. | ||
299 | // The names have a 2 tacked on. This will be removed as the code gets rebuilt | ||
300 | // and the old code is removed from the C# code. | ||
301 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
302 | public static extern IntPtr GetSimHandle2(uint worldID); | ||
303 | |||
304 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
305 | public static extern IntPtr GetBodyHandleWorldID2(uint worldID, uint id); | ||
306 | |||
307 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
308 | public static extern IntPtr GetBodyHandle2(IntPtr sim, uint id); | ||
309 | |||
310 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
311 | public static extern IntPtr ClearForces2(IntPtr obj); | ||
312 | |||
313 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
314 | public static extern IntPtr SetCollisionFlags2(IntPtr obj, uint flags); | ||
315 | |||
316 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
317 | public static extern IntPtr AddToCollisionFlags2(IntPtr obj, uint flags); | ||
318 | |||
319 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
320 | public static extern IntPtr RemoveFromCollisionFlags2(IntPtr obj, uint flags); | ||
321 | |||
271 | } | 322 | } |
272 | } | 323 | } |