diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index 756faed..76c2187 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | |||
@@ -52,7 +52,7 @@ public abstract class BSLinkset | |||
52 | Manual = 2 // linkset tied together manually (code moves all the pieces) | 52 | Manual = 2 // linkset tied together manually (code moves all the pieces) |
53 | } | 53 | } |
54 | // Create the correct type of linkset for this child | 54 | // Create the correct type of linkset for this child |
55 | public static BSLinkset Factory(BSScene physScene, BSPhysObject parent) | 55 | public static BSLinkset Factory(BSScene physScene, BSPrimLinkable parent) |
56 | { | 56 | { |
57 | BSLinkset ret = null; | 57 | BSLinkset ret = null; |
58 | 58 | ||
@@ -71,31 +71,28 @@ public abstract class BSLinkset | |||
71 | ret = new BSLinksetCompound(physScene, parent); | 71 | ret = new BSLinksetCompound(physScene, parent); |
72 | break; | 72 | break; |
73 | } | 73 | } |
74 | if (ret == null) | ||
75 | { | ||
76 | physScene.Logger.ErrorFormat("[BULLETSIM LINKSET] Factory could not create linkset. Parent name={1}, ID={2}", parent.Name, parent.LocalID); | ||
77 | } | ||
74 | return ret; | 78 | return ret; |
75 | } | 79 | } |
76 | 80 | ||
77 | public BSPhysObject LinksetRoot { get; protected set; } | 81 | public BSPrimLinkable LinksetRoot { get; protected set; } |
78 | 82 | ||
79 | public BSScene PhysicsScene { get; private set; } | 83 | protected BSScene m_physicsScene { get; private set; } |
80 | 84 | ||
81 | static int m_nextLinksetID = 1; | 85 | static int m_nextLinksetID = 1; |
82 | public int LinksetID { get; private set; } | 86 | public int LinksetID { get; private set; } |
83 | 87 | ||
84 | // The children under the root in this linkset. | 88 | // The children under the root in this linkset. |
85 | protected HashSet<BSPhysObject> m_children; | 89 | protected HashSet<BSPrimLinkable> m_children; |
86 | 90 | ||
87 | // We lock the diddling of linkset classes to prevent any badness. | 91 | // We lock the diddling of linkset classes to prevent any badness. |
88 | // This locks the modification of the instances of this class. Changes | 92 | // This locks the modification of the instances of this class. Changes |
89 | // to the physical representation is done via the tainting mechenism. | 93 | // to the physical representation is done via the tainting mechenism. |
90 | protected object m_linksetActivityLock = new Object(); | 94 | protected object m_linksetActivityLock = new Object(); |
91 | 95 | ||
92 | // Some linksets have a preferred physical shape. | ||
93 | // Returns SHAPE_UNKNOWN if there is no preference. Causes the correct shape to be selected. | ||
94 | public virtual BSPhysicsShapeType PreferredPhysicalShape(BSPhysObject requestor) | ||
95 | { | ||
96 | return BSPhysicsShapeType.SHAPE_UNKNOWN; | ||
97 | } | ||
98 | |||
99 | // We keep the prim's mass in the linkset structure since it could be dependent on other prims | 96 | // We keep the prim's mass in the linkset structure since it could be dependent on other prims |
100 | public float LinksetMass { get; protected set; } | 97 | public float LinksetMass { get; protected set; } |
101 | 98 | ||
@@ -111,25 +108,27 @@ public abstract class BSLinkset | |||
111 | get { return ComputeLinksetGeometricCenter(); } | 108 | get { return ComputeLinksetGeometricCenter(); } |
112 | } | 109 | } |
113 | 110 | ||
114 | protected BSLinkset(BSScene scene, BSPhysObject parent) | 111 | protected BSLinkset(BSScene scene, BSPrimLinkable parent) |
115 | { | 112 | { |
116 | // A simple linkset of one (no children) | 113 | // A simple linkset of one (no children) |
117 | LinksetID = m_nextLinksetID++; | 114 | LinksetID = m_nextLinksetID++; |
118 | // We create LOTS of linksets. | 115 | // We create LOTS of linksets. |
119 | if (m_nextLinksetID <= 0) | 116 | if (m_nextLinksetID <= 0) |
120 | m_nextLinksetID = 1; | 117 | m_nextLinksetID = 1; |
121 | PhysicsScene = scene; | 118 | m_physicsScene = scene; |
122 | LinksetRoot = parent; | 119 | LinksetRoot = parent; |
123 | m_children = new HashSet<BSPhysObject>(); | 120 | m_children = new HashSet<BSPrimLinkable>(); |
124 | LinksetMass = parent.RawMass; | 121 | LinksetMass = parent.RawMass; |
125 | Rebuilding = false; | 122 | Rebuilding = false; |
123 | |||
124 | parent.ClearDisplacement(); | ||
126 | } | 125 | } |
127 | 126 | ||
128 | // Link to a linkset where the child knows the parent. | 127 | // Link to a linkset where the child knows the parent. |
129 | // Parent changing should not happen so do some sanity checking. | 128 | // Parent changing should not happen so do some sanity checking. |
130 | // We return the parent's linkset so the child can track its membership. | 129 | // We return the parent's linkset so the child can track its membership. |
131 | // Called at runtime. | 130 | // Called at runtime. |
132 | public BSLinkset AddMeToLinkset(BSPhysObject child) | 131 | public BSLinkset AddMeToLinkset(BSPrimLinkable child) |
133 | { | 132 | { |
134 | lock (m_linksetActivityLock) | 133 | lock (m_linksetActivityLock) |
135 | { | 134 | { |
@@ -145,7 +144,7 @@ public abstract class BSLinkset | |||
145 | // Returns a new linkset for the child which is a linkset of one (just the | 144 | // Returns a new linkset for the child which is a linkset of one (just the |
146 | // orphened child). | 145 | // orphened child). |
147 | // Called at runtime. | 146 | // Called at runtime. |
148 | public BSLinkset RemoveMeFromLinkset(BSPhysObject child) | 147 | public BSLinkset RemoveMeFromLinkset(BSPrimLinkable child) |
149 | { | 148 | { |
150 | lock (m_linksetActivityLock) | 149 | lock (m_linksetActivityLock) |
151 | { | 150 | { |
@@ -159,11 +158,11 @@ public abstract class BSLinkset | |||
159 | } | 158 | } |
160 | 159 | ||
161 | // The child is down to a linkset of just itself | 160 | // The child is down to a linkset of just itself |
162 | return BSLinkset.Factory(PhysicsScene, child); | 161 | return BSLinkset.Factory(m_physicsScene, child); |
163 | } | 162 | } |
164 | 163 | ||
165 | // Return 'true' if the passed object is the root object of this linkset | 164 | // Return 'true' if the passed object is the root object of this linkset |
166 | public bool IsRoot(BSPhysObject requestor) | 165 | public bool IsRoot(BSPrimLinkable requestor) |
167 | { | 166 | { |
168 | return (requestor.LocalID == LinksetRoot.LocalID); | 167 | return (requestor.LocalID == LinksetRoot.LocalID); |
169 | } | 168 | } |
@@ -174,14 +173,14 @@ public abstract class BSLinkset | |||
174 | public bool HasAnyChildren { get { return (m_children.Count > 0); } } | 173 | public bool HasAnyChildren { get { return (m_children.Count > 0); } } |
175 | 174 | ||
176 | // Return 'true' if this child is in this linkset | 175 | // Return 'true' if this child is in this linkset |
177 | public bool HasChild(BSPhysObject child) | 176 | public bool HasChild(BSPrimLinkable child) |
178 | { | 177 | { |
179 | bool ret = false; | 178 | bool ret = false; |
180 | lock (m_linksetActivityLock) | 179 | lock (m_linksetActivityLock) |
181 | { | 180 | { |
182 | ret = m_children.Contains(child); | 181 | ret = m_children.Contains(child); |
183 | /* Safer version but the above should work | 182 | /* Safer version but the above should work |
184 | foreach (BSPhysObject bp in m_children) | 183 | foreach (BSPrimLinkable bp in m_children) |
185 | { | 184 | { |
186 | if (child.LocalID == bp.LocalID) | 185 | if (child.LocalID == bp.LocalID) |
187 | { | 186 | { |
@@ -196,14 +195,14 @@ public abstract class BSLinkset | |||
196 | 195 | ||
197 | // Perform an action on each member of the linkset including root prim. | 196 | // Perform an action on each member of the linkset including root prim. |
198 | // Depends on the action on whether this should be done at taint time. | 197 | // Depends on the action on whether this should be done at taint time. |
199 | public delegate bool ForEachMemberAction(BSPhysObject obj); | 198 | public delegate bool ForEachMemberAction(BSPrimLinkable obj); |
200 | public virtual bool ForEachMember(ForEachMemberAction action) | 199 | public virtual bool ForEachMember(ForEachMemberAction action) |
201 | { | 200 | { |
202 | bool ret = false; | 201 | bool ret = false; |
203 | lock (m_linksetActivityLock) | 202 | lock (m_linksetActivityLock) |
204 | { | 203 | { |
205 | action(LinksetRoot); | 204 | action(LinksetRoot); |
206 | foreach (BSPhysObject po in m_children) | 205 | foreach (BSPrimLinkable po in m_children) |
207 | { | 206 | { |
208 | if (action(po)) | 207 | if (action(po)) |
209 | break; | 208 | break; |
@@ -214,16 +213,16 @@ public abstract class BSLinkset | |||
214 | 213 | ||
215 | // I am the root of a linkset and a new child is being added | 214 | // I am the root of a linkset and a new child is being added |
216 | // Called while LinkActivity is locked. | 215 | // Called while LinkActivity is locked. |
217 | protected abstract void AddChildToLinkset(BSPhysObject child); | 216 | protected abstract void AddChildToLinkset(BSPrimLinkable child); |
218 | 217 | ||
219 | // I am the root of a linkset and one of my children is being removed. | 218 | // I am the root of a linkset and one of my children is being removed. |
220 | // Safe to call even if the child is not really in my linkset. | 219 | // Safe to call even if the child is not really in my linkset. |
221 | protected abstract void RemoveChildFromLinkset(BSPhysObject child); | 220 | protected abstract void RemoveChildFromLinkset(BSPrimLinkable child); |
222 | 221 | ||
223 | // When physical properties are changed the linkset needs to recalculate | 222 | // When physical properties are changed the linkset needs to recalculate |
224 | // its internal properties. | 223 | // its internal properties. |
225 | // May be called at runtime or taint-time. | 224 | // May be called at runtime or taint-time. |
226 | public virtual void Refresh(BSPhysObject requestor) | 225 | public virtual void Refresh(BSPrimLinkable requestor) |
227 | { | 226 | { |
228 | LinksetMass = ComputeLinksetMass(); | 227 | LinksetMass = ComputeLinksetMass(); |
229 | } | 228 | } |
@@ -238,31 +237,26 @@ public abstract class BSLinkset | |||
238 | // has not yet been fully constructed. | 237 | // has not yet been fully constructed. |
239 | // Return 'true' if any properties updated on the passed object. | 238 | // Return 'true' if any properties updated on the passed object. |
240 | // Called at taint-time! | 239 | // Called at taint-time! |
241 | public abstract bool MakeDynamic(BSPhysObject child); | 240 | public abstract bool MakeDynamic(BSPrimLinkable child); |
242 | 241 | ||
243 | // The object is going static (non-physical). Do any setup necessary | 242 | // The object is going static (non-physical). Do any setup necessary |
244 | // for a static linkset. | 243 | // for a static linkset. |
245 | // Return 'true' if any properties updated on the passed object. | 244 | // Return 'true' if any properties updated on the passed object. |
246 | // Called at taint-time! | 245 | // Called at taint-time! |
247 | public abstract bool MakeStatic(BSPhysObject child); | 246 | public abstract bool MakeStatic(BSPrimLinkable child); |
248 | 247 | ||
249 | // Called when a parameter update comes from the physics engine for any object | 248 | // Called when a parameter update comes from the physics engine for any object |
250 | // of the linkset is received. | 249 | // of the linkset is received. |
251 | // Passed flag is update came from physics engine (true) or the user (false). | 250 | // Passed flag is update came from physics engine (true) or the user (false). |
252 | // Called at taint-time!! | 251 | // Called at taint-time!! |
253 | public abstract void UpdateProperties(BSPhysObject physObject, bool physicalUpdate); | 252 | public abstract void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable physObject); |
254 | 253 | ||
255 | // Routine used when rebuilding the body of the root of the linkset | 254 | // Routine used when rebuilding the body of the root of the linkset |
256 | // Destroy all the constraints have have been made to root. | 255 | // Destroy all the constraints have have been made to root. |
257 | // This is called when the root body is changing. | 256 | // This is called when the root body is changing. |
258 | // Returns 'true' of something was actually removed and would need restoring | 257 | // Returns 'true' of something was actually removed and would need restoring |
259 | // Called at taint-time!! | 258 | // Called at taint-time!! |
260 | public abstract bool RemoveBodyDependencies(BSPrim child); | 259 | public abstract bool RemoveDependencies(BSPrimLinkable child); |
261 | |||
262 | // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true', | ||
263 | // this routine will restore the removed constraints. | ||
264 | // Called at taint-time!! | ||
265 | public abstract void RestoreBodyDependencies(BSPrim child); | ||
266 | 260 | ||
267 | // ================================================================ | 261 | // ================================================================ |
268 | protected virtual float ComputeLinksetMass() | 262 | protected virtual float ComputeLinksetMass() |
@@ -272,7 +266,7 @@ public abstract class BSLinkset | |||
272 | { | 266 | { |
273 | lock (m_linksetActivityLock) | 267 | lock (m_linksetActivityLock) |
274 | { | 268 | { |
275 | foreach (BSPhysObject bp in m_children) | 269 | foreach (BSPrimLinkable bp in m_children) |
276 | { | 270 | { |
277 | mass += bp.RawMass; | 271 | mass += bp.RawMass; |
278 | } | 272 | } |
@@ -281,6 +275,7 @@ public abstract class BSLinkset | |||
281 | return mass; | 275 | return mass; |
282 | } | 276 | } |
283 | 277 | ||
278 | // Computes linkset's center of mass in world coordinates. | ||
284 | protected virtual OMV.Vector3 ComputeLinksetCenterOfMass() | 279 | protected virtual OMV.Vector3 ComputeLinksetCenterOfMass() |
285 | { | 280 | { |
286 | OMV.Vector3 com; | 281 | OMV.Vector3 com; |
@@ -289,7 +284,7 @@ public abstract class BSLinkset | |||
289 | com = LinksetRoot.Position * LinksetRoot.RawMass; | 284 | com = LinksetRoot.Position * LinksetRoot.RawMass; |
290 | float totalMass = LinksetRoot.RawMass; | 285 | float totalMass = LinksetRoot.RawMass; |
291 | 286 | ||
292 | foreach (BSPhysObject bp in m_children) | 287 | foreach (BSPrimLinkable bp in m_children) |
293 | { | 288 | { |
294 | com += bp.Position * bp.RawMass; | 289 | com += bp.Position * bp.RawMass; |
295 | totalMass += bp.RawMass; | 290 | totalMass += bp.RawMass; |
@@ -308,9 +303,9 @@ public abstract class BSLinkset | |||
308 | { | 303 | { |
309 | com = LinksetRoot.Position; | 304 | com = LinksetRoot.Position; |
310 | 305 | ||
311 | foreach (BSPhysObject bp in m_children) | 306 | foreach (BSPrimLinkable bp in m_children) |
312 | { | 307 | { |
313 | com += bp.Position * bp.RawMass; | 308 | com += bp.Position; |
314 | } | 309 | } |
315 | com /= (m_children.Count + 1); | 310 | com /= (m_children.Count + 1); |
316 | } | 311 | } |
@@ -321,8 +316,8 @@ public abstract class BSLinkset | |||
321 | // Invoke the detailed logger and output something if it's enabled. | 316 | // Invoke the detailed logger and output something if it's enabled. |
322 | protected void DetailLog(string msg, params Object[] args) | 317 | protected void DetailLog(string msg, params Object[] args) |
323 | { | 318 | { |
324 | if (PhysicsScene.PhysicsLogging.Enabled) | 319 | if (m_physicsScene.PhysicsLogging.Enabled) |
325 | PhysicsScene.DetailLog(msg, args); | 320 | m_physicsScene.DetailLog(msg, args); |
326 | } | 321 | } |
327 | 322 | ||
328 | } | 323 | } |