diff options
author | Robert Adams | 2012-08-01 15:04:09 -0700 |
---|---|---|
committer | Robert Adams | 2012-08-03 15:09:52 -0700 |
commit | ea36d4a4cf716442e83cc9cd1b419a43be5adc6e (patch) | |
tree | d0f24359e5f62ce4b112abe91e52e30ec5ce5f62 | |
parent | Consolidate PersistBakedTextures, DelayBeforeAppearanceSend and DelayBeforeAp... (diff) | |
download | opensim-SC_OLD-ea36d4a4cf716442e83cc9cd1b419a43be5adc6e.zip opensim-SC_OLD-ea36d4a4cf716442e83cc9cd1b419a43be5adc6e.tar.gz opensim-SC_OLD-ea36d4a4cf716442e83cc9cd1b419a43be5adc6e.tar.bz2 opensim-SC_OLD-ea36d4a4cf716442e83cc9cd1b419a43be5adc6e.tar.xz |
BulletSim: Add AddObjectForce to BulletSim API.
Add interface 2 enhancements to BSCharacter.
Modify AddForce and SetForce to use the new Bullet interface.
More DetailLog statements for character.
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 26 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 29 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | 3 |
3 files changed, 38 insertions, 20 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 09e1f0c..a5635ff 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -40,6 +40,7 @@ public class BSCharacter : PhysicsActor | |||
40 | private static readonly string LogHeader = "[BULLETS CHAR]"; | 40 | private static readonly string LogHeader = "[BULLETS CHAR]"; |
41 | 41 | ||
42 | private BSScene _scene; | 42 | private BSScene _scene; |
43 | public BSScene Scene { get { return _scene; } } | ||
43 | private String _avName; | 44 | private String _avName; |
44 | // private bool _stopped; | 45 | // private bool _stopped; |
45 | private Vector3 _size; | 46 | private Vector3 _size; |
@@ -73,6 +74,12 @@ public class BSCharacter : PhysicsActor | |||
73 | private bool _kinematic; | 74 | private bool _kinematic; |
74 | private float _buoyancy; | 75 | private float _buoyancy; |
75 | 76 | ||
77 | private BulletBody m_body; | ||
78 | public BulletBody Body { | ||
79 | get { return m_body; } | ||
80 | set { m_body = value; } | ||
81 | } | ||
82 | |||
76 | private int _subscribedEventsMs = 0; | 83 | private int _subscribedEventsMs = 0; |
77 | private int _nextCollisionOkTime = 0; | 84 | private int _nextCollisionOkTime = 0; |
78 | 85 | ||
@@ -116,6 +123,8 @@ public class BSCharacter : PhysicsActor | |||
116 | _scene.TaintedObject(delegate() | 123 | _scene.TaintedObject(delegate() |
117 | { | 124 | { |
118 | BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData); | 125 | BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData); |
126 | |||
127 | m_body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); | ||
119 | }); | 128 | }); |
120 | 129 | ||
121 | return; | 130 | return; |
@@ -124,6 +133,7 @@ public class BSCharacter : PhysicsActor | |||
124 | // called when this character is being destroyed and the resources should be released | 133 | // called when this character is being destroyed and the resources should be released |
125 | public void Destroy() | 134 | public void Destroy() |
126 | { | 135 | { |
136 | // DetailLog("{0},Destroy", LocalID); | ||
127 | _scene.TaintedObject(delegate() | 137 | _scene.TaintedObject(delegate() |
128 | { | 138 | { |
129 | BulletSimAPI.DestroyObject(_scene.WorldID, _localID); | 139 | BulletSimAPI.DestroyObject(_scene.WorldID, _localID); |
@@ -174,6 +184,7 @@ public class BSCharacter : PhysicsActor | |||
174 | _position = value; | 184 | _position = value; |
175 | _scene.TaintedObject(delegate() | 185 | _scene.TaintedObject(delegate() |
176 | { | 186 | { |
187 | DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | ||
177 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 188 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); |
178 | }); | 189 | }); |
179 | } | 190 | } |
@@ -188,9 +199,10 @@ public class BSCharacter : PhysicsActor | |||
188 | set { | 199 | set { |
189 | _force = value; | 200 | _force = value; |
190 | // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); | 201 | // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); |
191 | _scene.TaintedObject(delegate() | 202 | Scene.TaintedObject(delegate() |
192 | { | 203 | { |
193 | BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); | 204 | DetailLog("{0},setForce,taint,force={1}", LocalID, _force); |
205 | BulletSimAPI.SetObjectForce(Scene.WorldID, LocalID, _force); | ||
194 | }); | 206 | }); |
195 | } | 207 | } |
196 | } | 208 | } |
@@ -216,6 +228,7 @@ public class BSCharacter : PhysicsActor | |||
216 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); | 228 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); |
217 | _scene.TaintedObject(delegate() | 229 | _scene.TaintedObject(delegate() |
218 | { | 230 | { |
231 | DetailLog("{0},setVelocity,taint,vel={1}", LocalID, _velocity); | ||
219 | BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity); | 232 | BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity); |
220 | }); | 233 | }); |
221 | } | 234 | } |
@@ -305,6 +318,7 @@ public class BSCharacter : PhysicsActor | |||
305 | set { _buoyancy = value; | 318 | set { _buoyancy = value; |
306 | _scene.TaintedObject(delegate() | 319 | _scene.TaintedObject(delegate() |
307 | { | 320 | { |
321 | DetailLog("{0},setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | ||
308 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _buoyancy); | 322 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _buoyancy); |
309 | }); | 323 | }); |
310 | } | 324 | } |
@@ -351,7 +365,8 @@ public class BSCharacter : PhysicsActor | |||
351 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); | 365 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); |
352 | _scene.TaintedObject(delegate() | 366 | _scene.TaintedObject(delegate() |
353 | { | 367 | { |
354 | BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); | 368 | DetailLog("{0},setAddForce,taint,addedForce={1}", LocalID, _force); |
369 | BulletSimAPI.AddObjectForce2(Body.Ptr, _force); | ||
355 | }); | 370 | }); |
356 | } | 371 | } |
357 | else | 372 | else |
@@ -480,5 +495,10 @@ public class BSCharacter : PhysicsActor | |||
480 | // End kludge | 495 | // End kludge |
481 | } | 496 | } |
482 | 497 | ||
498 | // Invoke the detailed logger and output something if it's enabled. | ||
499 | private void DetailLog(string msg, params Object[] args) | ||
500 | { | ||
501 | Scene.PhysicsLogging.Write(msg, args); | ||
502 | } | ||
483 | } | 503 | } |
484 | } | 504 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index ebfd85b..22f5995 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -187,7 +187,7 @@ public sealed class BSPrim : PhysicsActor | |||
187 | { | 187 | { |
188 | _mass = CalculateMass(); // changing size changes the mass | 188 | _mass = CalculateMass(); // changing size changes the mass |
189 | BulletSimAPI.SetObjectScaleMass(_scene.WorldID, _localID, _scale, (IsPhysical ? _mass : 0f), IsPhysical); | 189 | BulletSimAPI.SetObjectScaleMass(_scene.WorldID, _localID, _scale, (IsPhysical ? _mass : 0f), IsPhysical); |
190 | DetailLog("{0}: setSize: size={1}, mass={2}, physical={3}", LocalID, _size, _mass, IsPhysical); | 190 | // DetailLog("{0}: setSize: size={1}, mass={2}, physical={3}", LocalID, _size, _mass, IsPhysical); |
191 | RecreateGeomAndObject(); | 191 | RecreateGeomAndObject(); |
192 | }); | 192 | }); |
193 | } | 193 | } |
@@ -318,7 +318,7 @@ public sealed class BSPrim : PhysicsActor | |||
318 | _force = value; | 318 | _force = value; |
319 | _scene.TaintedObject(delegate() | 319 | _scene.TaintedObject(delegate() |
320 | { | 320 | { |
321 | DetailLog("{0},SetForce,taint,force={1}", LocalID, _force); | 321 | DetailLog("{0},setForce,taint,force={1}", LocalID, _force); |
322 | // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); | 322 | // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); |
323 | BulletSimAPI.SetObjectForce2(Body.Ptr, _force); | 323 | BulletSimAPI.SetObjectForce2(Body.Ptr, _force); |
324 | }); | 324 | }); |
@@ -443,7 +443,7 @@ public sealed class BSPrim : PhysicsActor | |||
443 | _scene.TaintedObject(delegate() | 443 | _scene.TaintedObject(delegate() |
444 | { | 444 | { |
445 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); | 445 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); |
446 | DetailLog("{0},SetOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 446 | DetailLog("{0},setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
447 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 447 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); |
448 | }); | 448 | }); |
449 | } | 449 | } |
@@ -487,10 +487,8 @@ public sealed class BSPrim : PhysicsActor | |||
487 | // Maybe a VerifyCorrectPhysicalShape() routine? | 487 | // Maybe a VerifyCorrectPhysicalShape() routine? |
488 | // RecreateGeomAndObject(); | 488 | // RecreateGeomAndObject(); |
489 | 489 | ||
490 | float mass = _mass; | 490 | // Bullet wants static objects to have a mass of zero |
491 | // Bullet wants static objects have a mass of zero | 491 | float mass = IsStatic ? 0f : _mass; |
492 | if (IsStatic) | ||
493 | mass = 0f; | ||
494 | 492 | ||
495 | DetailLog("{0},SetObjectDynamic,taint,static={1},solid={2},mass={3}", LocalID, IsStatic, IsSolid, mass); | 493 | DetailLog("{0},SetObjectDynamic,taint,static={1},solid={2},mass={3}", LocalID, IsStatic, IsSolid, mass); |
496 | BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); | 494 | BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); |
@@ -607,6 +605,7 @@ public sealed class BSPrim : PhysicsActor | |||
607 | 605 | ||
608 | private List<OMV.Vector3> m_accumulatedForces = new List<OMV.Vector3>(); | 606 | private List<OMV.Vector3> m_accumulatedForces = new List<OMV.Vector3>(); |
609 | public override void AddForce(OMV.Vector3 force, bool pushforce) { | 607 | public override void AddForce(OMV.Vector3 force, bool pushforce) { |
608 | // for an object, doesn't matter if force is a pushforce or not | ||
610 | if (force.IsFinite()) | 609 | if (force.IsFinite()) |
611 | { | 610 | { |
612 | // _force += force; | 611 | // _force += force; |
@@ -620,21 +619,17 @@ public sealed class BSPrim : PhysicsActor | |||
620 | } | 619 | } |
621 | _scene.TaintedObject(delegate() | 620 | _scene.TaintedObject(delegate() |
622 | { | 621 | { |
622 | OMV.Vector3 fSum = OMV.Vector3.Zero; | ||
623 | lock (m_accumulatedForces) | 623 | lock (m_accumulatedForces) |
624 | { | 624 | { |
625 | if (m_accumulatedForces.Count > 0) | 625 | foreach (OMV.Vector3 v in m_accumulatedForces) |
626 | { | 626 | { |
627 | OMV.Vector3 fSum = OMV.Vector3.Zero; | 627 | fSum += v; |
628 | foreach (OMV.Vector3 v in m_accumulatedForces) | ||
629 | { | ||
630 | fSum += v; | ||
631 | } | ||
632 | m_accumulatedForces.Clear(); | ||
633 | |||
634 | DetailLog("{0},SetObjectForce,taint,force={1}", LocalID, fSum); | ||
635 | BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, fSum); | ||
636 | } | 628 | } |
629 | m_accumulatedForces.Clear(); | ||
637 | } | 630 | } |
631 | DetailLog("{0},AddObjectForce,taint,force={1}", LocalID, _force); | ||
632 | BulletSimAPI.AddObjectForce2(Body.Ptr, fSum); | ||
638 | }); | 633 | }); |
639 | } | 634 | } |
640 | 635 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index 0ffbc94..1881e41 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | |||
@@ -448,6 +448,9 @@ public static extern bool SetAngularVelocity2(IntPtr obj, Vector3 angularVelocit | |||
448 | public static extern bool SetObjectForce2(IntPtr obj, Vector3 force); | 448 | public static extern bool SetObjectForce2(IntPtr obj, Vector3 force); |
449 | 449 | ||
450 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 450 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |
451 | public static extern bool AddObjectForce2(IntPtr obj, Vector3 force); | ||
452 | |||
453 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | ||
451 | public static extern bool SetCcdMotionThreshold2(IntPtr obj, float val); | 454 | public static extern bool SetCcdMotionThreshold2(IntPtr obj, float val); |
452 | 455 | ||
453 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] | 456 | [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] |