aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs144
1 files changed, 117 insertions, 27 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
index 4ece1eb..7f94666 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs
@@ -33,14 +33,6 @@ using OMV = OpenMetaverse;
33namespace OpenSim.Region.Physics.BulletSPlugin 33namespace OpenSim.Region.Physics.BulletSPlugin
34{ 34{
35 35
36// A BSPrim can get individual information about its linkedness attached
37// to it through an instance of a subclass of LinksetInfo.
38// Each type of linkset will define the information needed for its type.
39public abstract class BSLinksetInfo
40{
41 public virtual void Clear() { }
42}
43
44public abstract class BSLinkset 36public abstract class BSLinkset
45{ 37{
46 // private static string LogHeader = "[BULLETSIM LINKSET]"; 38 // private static string LogHeader = "[BULLETSIM LINKSET]";
@@ -56,15 +48,15 @@ public abstract class BSLinkset
56 { 48 {
57 BSLinkset ret = null; 49 BSLinkset ret = null;
58 50
59 switch ((int)BSParam.LinksetImplementation) 51 switch (parent.LinksetType)
60 { 52 {
61 case (int)LinksetImplementation.Constraint: 53 case LinksetImplementation.Constraint:
62 ret = new BSLinksetConstraints(physScene, parent); 54 ret = new BSLinksetConstraints(physScene, parent);
63 break; 55 break;
64 case (int)LinksetImplementation.Compound: 56 case LinksetImplementation.Compound:
65 ret = new BSLinksetCompound(physScene, parent); 57 ret = new BSLinksetCompound(physScene, parent);
66 break; 58 break;
67 case (int)LinksetImplementation.Manual: 59 case LinksetImplementation.Manual:
68 // ret = new BSLinksetManual(physScene, parent); 60 // ret = new BSLinksetManual(physScene, parent);
69 break; 61 break;
70 default: 62 default:
@@ -80,7 +72,7 @@ public abstract class BSLinkset
80 72
81 public BSPrimLinkable LinksetRoot { get; protected set; } 73 public BSPrimLinkable LinksetRoot { get; protected set; }
82 74
83 public BSScene PhysicsScene { get; private set; } 75 protected BSScene m_physicsScene { get; private set; }
84 76
85 static int m_nextLinksetID = 1; 77 static int m_nextLinksetID = 1;
86 public int LinksetID { get; private set; } 78 public int LinksetID { get; private set; }
@@ -93,13 +85,6 @@ public abstract class BSLinkset
93 // to the physical representation is done via the tainting mechenism. 85 // to the physical representation is done via the tainting mechenism.
94 protected object m_linksetActivityLock = new Object(); 86 protected object m_linksetActivityLock = new Object();
95 87
96 // Some linksets have a preferred physical shape.
97 // Returns SHAPE_UNKNOWN if there is no preference. Causes the correct shape to be selected.
98 public virtual BSPhysicsShapeType PreferredPhysicalShape(BSPrimLinkable requestor)
99 {
100 return BSPhysicsShapeType.SHAPE_UNKNOWN;
101 }
102
103 // We keep the prim's mass in the linkset structure since it could be dependent on other prims 88 // We keep the prim's mass in the linkset structure since it could be dependent on other prims
104 public float LinksetMass { get; protected set; } 89 public float LinksetMass { get; protected set; }
105 90
@@ -122,7 +107,7 @@ public abstract class BSLinkset
122 // We create LOTS of linksets. 107 // We create LOTS of linksets.
123 if (m_nextLinksetID <= 0) 108 if (m_nextLinksetID <= 0)
124 m_nextLinksetID = 1; 109 m_nextLinksetID = 1;
125 PhysicsScene = scene; 110 m_physicsScene = scene;
126 LinksetRoot = parent; 111 LinksetRoot = parent;
127 m_children = new HashSet<BSPrimLinkable>(); 112 m_children = new HashSet<BSPrimLinkable>();
128 LinksetMass = parent.RawMass; 113 LinksetMass = parent.RawMass;
@@ -165,7 +150,7 @@ public abstract class BSLinkset
165 } 150 }
166 151
167 // The child is down to a linkset of just itself 152 // The child is down to a linkset of just itself
168 return BSLinkset.Factory(PhysicsScene, child); 153 return BSLinkset.Factory(m_physicsScene, child);
169 } 154 }
170 155
171 // Return 'true' if the passed object is the root object of this linkset 156 // Return 'true' if the passed object is the root object of this linkset
@@ -218,10 +203,37 @@ public abstract class BSLinkset
218 return ret; 203 return ret;
219 } 204 }
220 205
206 // Called after a simulation step to post a collision with this object.
207 // Return 'true' if linkset processed the collision. 'false' says the linkset didn't have
208 // anything to add for the collision and it should be passed through normal processing.
209 // Default processing for a linkset.
210 public virtual bool HandleCollide(uint collidingWith, BSPhysObject collidee,
211 OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
212 {
213 bool ret = false;
214
215 // prims in the same linkset cannot collide with each other
216 BSPrimLinkable convCollidee = collidee as BSPrimLinkable;
217 if (convCollidee != null && (LinksetID == convCollidee.Linkset.LinksetID))
218 {
219 // By returning 'true', we tell the caller the collision has been 'handled' so it won't
220 // do anything about this collision and thus, effectivily, ignoring the collision.
221 ret = true;
222 }
223 else
224 {
225 // Not a collision between members of the linkset. Must be a real collision.
226 // So the linkset root can know if there is a collision anywhere in the linkset.
227 LinksetRoot.SomeCollisionSimulationStep = m_physicsScene.SimulationStep;
228 }
229
230 return ret;
231 }
232
221 // I am the root of a linkset and a new child is being added 233 // I am the root of a linkset and a new child is being added
222 // Called while LinkActivity is locked. 234 // Called while LinkActivity is locked.
223 protected abstract void AddChildToLinkset(BSPrimLinkable child); 235 protected abstract void AddChildToLinkset(BSPrimLinkable child);
224 236
225 // I am the root of a linkset and one of my children is being removed. 237 // I am the root of a linkset and one of my children is being removed.
226 // Safe to call even if the child is not really in my linkset. 238 // Safe to call even if the child is not really in my linkset.
227 protected abstract void RemoveChildFromLinkset(BSPrimLinkable child); 239 protected abstract void RemoveChildFromLinkset(BSPrimLinkable child);
@@ -263,9 +275,88 @@ public abstract class BSLinkset
263 // This is called when the root body is changing. 275 // This is called when the root body is changing.
264 // Returns 'true' of something was actually removed and would need restoring 276 // Returns 'true' of something was actually removed and would need restoring
265 // Called at taint-time!! 277 // Called at taint-time!!
266 public abstract bool RemoveBodyDependencies(BSPrimLinkable child); 278 public abstract bool RemoveDependencies(BSPrimLinkable child);
267 279
268 // ================================================================ 280 // ================================================================
281 // Some physical setting happen to all members of the linkset
282 public virtual void SetPhysicalFriction(float friction)
283 {
284 ForEachMember((member) =>
285 {
286 if (member.PhysBody.HasPhysicalBody)
287 m_physicsScene.PE.SetFriction(member.PhysBody, friction);
288 return false; // 'false' says to continue looping
289 }
290 );
291 }
292 public virtual void SetPhysicalRestitution(float restitution)
293 {
294 ForEachMember((member) =>
295 {
296 if (member.PhysBody.HasPhysicalBody)
297 m_physicsScene.PE.SetRestitution(member.PhysBody, restitution);
298 return false; // 'false' says to continue looping
299 }
300 );
301 }
302 public virtual void SetPhysicalGravity(OMV.Vector3 gravity)
303 {
304 ForEachMember((member) =>
305 {
306 if (member.PhysBody.HasPhysicalBody)
307 m_physicsScene.PE.SetGravity(member.PhysBody, gravity);
308 return false; // 'false' says to continue looping
309 }
310 );
311 }
312 public virtual void ComputeAndSetLocalInertia(OMV.Vector3 inertiaFactor, float linksetMass)
313 {
314 ForEachMember((member) =>
315 {
316 if (member.PhysBody.HasPhysicalBody)
317 {
318 OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(member.PhysShape.physShapeInfo, linksetMass);
319 member.Inertia = inertia * inertiaFactor;
320 m_physicsScene.PE.SetMassProps(member.PhysBody, linksetMass, member.Inertia);
321 m_physicsScene.PE.UpdateInertiaTensor(member.PhysBody);
322 DetailLog("{0},BSLinkset.ComputeAndSetLocalInertia,m.mass={1}, inertia={2}", member.LocalID, linksetMass, member.Inertia);
323
324 }
325 return false; // 'false' says to continue looping
326 }
327 );
328 }
329 public virtual void SetPhysicalCollisionFlags(CollisionFlags collFlags)
330 {
331 ForEachMember((member) =>
332 {
333 if (member.PhysBody.HasPhysicalBody)
334 m_physicsScene.PE.SetCollisionFlags(member.PhysBody, collFlags);
335 return false; // 'false' says to continue looping
336 }
337 );
338 }
339 public virtual void AddToPhysicalCollisionFlags(CollisionFlags collFlags)
340 {
341 ForEachMember((member) =>
342 {
343 if (member.PhysBody.HasPhysicalBody)
344 m_physicsScene.PE.AddToCollisionFlags(member.PhysBody, collFlags);
345 return false; // 'false' says to continue looping
346 }
347 );
348 }
349 public virtual void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags)
350 {
351 ForEachMember((member) =>
352 {
353 if (member.PhysBody.HasPhysicalBody)
354 m_physicsScene.PE.RemoveFromCollisionFlags(member.PhysBody, collFlags);
355 return false; // 'false' says to continue looping
356 }
357 );
358 }
359 // ================================================================
269 protected virtual float ComputeLinksetMass() 360 protected virtual float ComputeLinksetMass()
270 { 361 {
271 float mass = LinksetRoot.RawMass; 362 float mass = LinksetRoot.RawMass;
@@ -323,9 +414,8 @@ public abstract class BSLinkset
323 // Invoke the detailed logger and output something if it's enabled. 414 // Invoke the detailed logger and output something if it's enabled.
324 protected void DetailLog(string msg, params Object[] args) 415 protected void DetailLog(string msg, params Object[] args)
325 { 416 {
326 if (PhysicsScene.PhysicsLogging.Enabled) 417 if (m_physicsScene.PhysicsLogging.Enabled)
327 PhysicsScene.DetailLog(msg, args); 418 m_physicsScene.DetailLog(msg, args);
328 } 419 }
329
330} 420}
331} 421}