diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 86 |
1 files changed, 37 insertions, 49 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index d3f1e9c..6bfce5c 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -37,7 +37,7 @@ using OpenSim.Region.Physics.ConvexDecompositionDotNet; | |||
37 | namespace OpenSim.Region.Physics.BulletSPlugin | 37 | namespace OpenSim.Region.Physics.BulletSPlugin |
38 | { | 38 | { |
39 | [Serializable] | 39 | [Serializable] |
40 | public sealed class BSPrim : PhysicsActor | 40 | public sealed class BSPrim : BSPhysObject |
41 | { | 41 | { |
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
43 | private static readonly string LogHeader = "[BULLETS PRIM]"; | 43 | private static readonly string LogHeader = "[BULLETS PRIM]"; |
@@ -88,23 +88,14 @@ public sealed class BSPrim : PhysicsActor | |||
88 | private float _buoyancy; | 88 | private float _buoyancy; |
89 | 89 | ||
90 | // Membership in a linkset is controlled by this class. | 90 | // Membership in a linkset is controlled by this class. |
91 | private BSLinkset _linkset; | 91 | public override BSLinkset Linkset { get; set; } |
92 | public BSLinkset Linkset | ||
93 | { | ||
94 | get { return _linkset; } | ||
95 | set { _linkset = value; } | ||
96 | } | ||
97 | 92 | ||
98 | private int _subscribedEventsMs = 0; | 93 | private int _subscribedEventsMs = 0; |
99 | private int _nextCollisionOkTime = 0; | 94 | private int _nextCollisionOkTime = 0; |
100 | long _collidingStep; | 95 | long _collidingStep; |
101 | long _collidingGroundStep; | 96 | long _collidingGroundStep; |
102 | 97 | ||
103 | private BulletBody m_body; | 98 | public override BulletBody Body { get; set; } |
104 | public BulletBody Body { | ||
105 | get { return m_body; } | ||
106 | set { m_body = value; } | ||
107 | } | ||
108 | 99 | ||
109 | private BSDynamics _vehicle; | 100 | private BSDynamics _vehicle; |
110 | 101 | ||
@@ -139,7 +130,7 @@ public sealed class BSPrim : PhysicsActor | |||
139 | _friction = _scene.Params.defaultFriction; // TODO: compute based on object material | 130 | _friction = _scene.Params.defaultFriction; // TODO: compute based on object material |
140 | _density = _scene.Params.defaultDensity; // TODO: compute based on object material | 131 | _density = _scene.Params.defaultDensity; // TODO: compute based on object material |
141 | _restitution = _scene.Params.defaultRestitution; | 132 | _restitution = _scene.Params.defaultRestitution; |
142 | _linkset = new BSLinkset(Scene, this); // a linkset of one | 133 | Linkset = new BSLinkset(Scene, this); // a linkset of one |
143 | _vehicle = new BSDynamics(Scene, this); // add vehicleness | 134 | _vehicle = new BSDynamics(Scene, this); // add vehicleness |
144 | _mass = CalculateMass(); | 135 | _mass = CalculateMass(); |
145 | // do the actual object creation at taint time | 136 | // do the actual object creation at taint time |
@@ -151,23 +142,23 @@ public sealed class BSPrim : PhysicsActor | |||
151 | // Get the pointer to the physical body for this object. | 142 | // Get the pointer to the physical body for this object. |
152 | // At the moment, we're still letting BulletSim manage the creation and destruction | 143 | // At the moment, we're still letting BulletSim manage the creation and destruction |
153 | // of the object. Someday we'll move that into the C# code. | 144 | // of the object. Someday we'll move that into the C# code. |
154 | m_body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); | 145 | Body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); |
155 | }); | 146 | }); |
156 | } | 147 | } |
157 | 148 | ||
158 | // called when this prim is being destroyed and we should free all the resources | 149 | // called when this prim is being destroyed and we should free all the resources |
159 | public void Destroy() | 150 | public override void Destroy() |
160 | { | 151 | { |
161 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); | 152 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); |
162 | 153 | ||
163 | // Undo any links between me and any other object | 154 | // Undo any links between me and any other object |
164 | BSPrim parentBefore = _linkset.LinksetRoot; | 155 | BSPhysObject parentBefore = Linkset.LinksetRoot; |
165 | int childrenBefore = _linkset.NumberOfChildren; | 156 | int childrenBefore = Linkset.NumberOfChildren; |
166 | 157 | ||
167 | _linkset = _linkset.RemoveMeFromLinkset(this); | 158 | Linkset = Linkset.RemoveMeFromLinkset(this); |
168 | 159 | ||
169 | DetailLog("{0},BSPrim.Destroy,call,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}", | 160 | DetailLog("{0},BSPrim.Destroy,call,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}", |
170 | LocalID, parentBefore.LocalID, childrenBefore, _linkset.LinksetRoot.LocalID, _linkset.NumberOfChildren); | 161 | LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren); |
171 | 162 | ||
172 | // Undo any vehicle properties | 163 | // Undo any vehicle properties |
173 | this.VehicleType = (int)Vehicle.TYPE_NONE; | 164 | this.VehicleType = (int)Vehicle.TYPE_NONE; |
@@ -230,13 +221,13 @@ public sealed class BSPrim : PhysicsActor | |||
230 | BSPrim parent = obj as BSPrim; | 221 | BSPrim parent = obj as BSPrim; |
231 | if (parent != null) | 222 | if (parent != null) |
232 | { | 223 | { |
233 | BSPrim parentBefore = _linkset.LinksetRoot; | 224 | BSPhysObject parentBefore = Linkset.LinksetRoot; |
234 | int childrenBefore = _linkset.NumberOfChildren; | 225 | int childrenBefore = Linkset.NumberOfChildren; |
235 | 226 | ||
236 | _linkset = parent.Linkset.AddMeToLinkset(this); | 227 | Linkset = parent.Linkset.AddMeToLinkset(this); |
237 | 228 | ||
238 | DetailLog("{0},BSPrim.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}", | 229 | DetailLog("{0},BSPrim.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}", |
239 | LocalID, parentBefore.LocalID, childrenBefore, _linkset.LinksetRoot.LocalID, _linkset.NumberOfChildren); | 230 | LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren); |
240 | } | 231 | } |
241 | return; | 232 | return; |
242 | } | 233 | } |
@@ -246,13 +237,13 @@ public sealed class BSPrim : PhysicsActor | |||
246 | // TODO: decide if this parent checking needs to happen at taint time | 237 | // TODO: decide if this parent checking needs to happen at taint time |
247 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen | 238 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen |
248 | 239 | ||
249 | BSPrim parentBefore = _linkset.LinksetRoot; | 240 | BSPhysObject parentBefore = Linkset.LinksetRoot; |
250 | int childrenBefore = _linkset.NumberOfChildren; | 241 | int childrenBefore = Linkset.NumberOfChildren; |
251 | 242 | ||
252 | _linkset = _linkset.RemoveMeFromLinkset(this); | 243 | Linkset = Linkset.RemoveMeFromLinkset(this); |
253 | 244 | ||
254 | DetailLog("{0},BSPrim.delink,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}, ", | 245 | DetailLog("{0},BSPrim.delink,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}, ", |
255 | LocalID, parentBefore.LocalID, childrenBefore, _linkset.LinksetRoot.LocalID, _linkset.NumberOfChildren); | 246 | LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren); |
256 | return; | 247 | return; |
257 | } | 248 | } |
258 | 249 | ||
@@ -260,7 +251,7 @@ public sealed class BSPrim : PhysicsActor | |||
260 | // Do it to the properties so the values get set in the physics engine. | 251 | // Do it to the properties so the values get set in the physics engine. |
261 | // Push the setting of the values to the viewer. | 252 | // Push the setting of the values to the viewer. |
262 | // Called at taint time! | 253 | // Called at taint time! |
263 | public void ZeroMotion() | 254 | public override void ZeroMotion() |
264 | { | 255 | { |
265 | _velocity = OMV.Vector3.Zero; | 256 | _velocity = OMV.Vector3.Zero; |
266 | _acceleration = OMV.Vector3.Zero; | 257 | _acceleration = OMV.Vector3.Zero; |
@@ -281,7 +272,7 @@ public sealed class BSPrim : PhysicsActor | |||
281 | 272 | ||
282 | public override OMV.Vector3 Position { | 273 | public override OMV.Vector3 Position { |
283 | get { | 274 | get { |
284 | if (!_linkset.IsRoot(this)) | 275 | if (!Linkset.IsRoot(this)) |
285 | // child prims move around based on their parent. Need to get the latest location | 276 | // child prims move around based on their parent. Need to get the latest location |
286 | _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); | 277 | _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); |
287 | 278 | ||
@@ -306,23 +297,23 @@ public sealed class BSPrim : PhysicsActor | |||
306 | { | 297 | { |
307 | get | 298 | get |
308 | { | 299 | { |
309 | return _linkset.LinksetMass; | 300 | return Linkset.LinksetMass; |
310 | } | 301 | } |
311 | } | 302 | } |
312 | 303 | ||
313 | // used when we only want this prim's mass and not the linkset thing | 304 | // used when we only want this prim's mass and not the linkset thing |
314 | public float MassRaw { get { return _mass; } } | 305 | public override float MassRaw { get { return _mass; } } |
315 | 306 | ||
316 | // Is this used? | 307 | // Is this used? |
317 | public override OMV.Vector3 CenterOfMass | 308 | public override OMV.Vector3 CenterOfMass |
318 | { | 309 | { |
319 | get { return _linkset.CenterOfMass; } | 310 | get { return Linkset.CenterOfMass; } |
320 | } | 311 | } |
321 | 312 | ||
322 | // Is this used? | 313 | // Is this used? |
323 | public override OMV.Vector3 GeometricCenter | 314 | public override OMV.Vector3 GeometricCenter |
324 | { | 315 | { |
325 | get { return _linkset.GeometricCenter; } | 316 | get { return Linkset.GeometricCenter; } |
326 | } | 317 | } |
327 | 318 | ||
328 | public override OMV.Vector3 Force { | 319 | public override OMV.Vector3 Force { |
@@ -386,7 +377,7 @@ public sealed class BSPrim : PhysicsActor | |||
386 | 377 | ||
387 | // Called each simulation step to advance vehicle characteristics. | 378 | // Called each simulation step to advance vehicle characteristics. |
388 | // Called from Scene when doing simulation step so we're in taint processing time. | 379 | // Called from Scene when doing simulation step so we're in taint processing time. |
389 | public void StepVehicle(float timeStep) | 380 | public override void StepVehicle(float timeStep) |
390 | { | 381 | { |
391 | if (IsPhysical) | 382 | if (IsPhysical) |
392 | _vehicle.Step(timeStep); | 383 | _vehicle.Step(timeStep); |
@@ -431,7 +422,7 @@ public sealed class BSPrim : PhysicsActor | |||
431 | } | 422 | } |
432 | public override OMV.Quaternion Orientation { | 423 | public override OMV.Quaternion Orientation { |
433 | get { | 424 | get { |
434 | if (!_linkset.IsRoot(this)) | 425 | if (!Linkset.IsRoot(this)) |
435 | { | 426 | { |
436 | // Children move around because tied to parent. Get a fresh value. | 427 | // Children move around because tied to parent. Get a fresh value. |
437 | _orientation = BulletSimAPI.GetObjectOrientation(_scene.WorldID, LocalID); | 428 | _orientation = BulletSimAPI.GetObjectOrientation(_scene.WorldID, LocalID); |
@@ -490,7 +481,7 @@ public sealed class BSPrim : PhysicsActor | |||
490 | BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); | 481 | BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); |
491 | 482 | ||
492 | // recompute any linkset parameters | 483 | // recompute any linkset parameters |
493 | _linkset.Refresh(this); | 484 | Linkset.Refresh(this); |
494 | 485 | ||
495 | CollisionFlags cf = BulletSimAPI.GetCollisionFlags2(Body.Ptr); | 486 | CollisionFlags cf = BulletSimAPI.GetCollisionFlags2(Body.Ptr); |
496 | DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, cf); | 487 | DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, cf); |
@@ -1299,7 +1290,7 @@ public sealed class BSPrim : PhysicsActor | |||
1299 | const float ACCELERATION_TOLERANCE = 0.01f; | 1290 | const float ACCELERATION_TOLERANCE = 0.01f; |
1300 | const float ROTATIONAL_VELOCITY_TOLERANCE = 0.01f; | 1291 | const float ROTATIONAL_VELOCITY_TOLERANCE = 0.01f; |
1301 | 1292 | ||
1302 | public void UpdateProperties(EntityProperties entprop) | 1293 | public override void UpdateProperties(EntityProperties entprop) |
1303 | { | 1294 | { |
1304 | /* | 1295 | /* |
1305 | UpdatedProperties changed = 0; | 1296 | UpdatedProperties changed = 0; |
@@ -1347,7 +1338,7 @@ public sealed class BSPrim : PhysicsActor | |||
1347 | // Don't check for damping here -- it's done in BulletSim and SceneObjectPart. | 1338 | // Don't check for damping here -- it's done in BulletSim and SceneObjectPart. |
1348 | 1339 | ||
1349 | // Updates only for individual prims and for the root object of a linkset. | 1340 | // Updates only for individual prims and for the root object of a linkset. |
1350 | if (_linkset.IsRoot(this)) | 1341 | if (Linkset.IsRoot(this)) |
1351 | { | 1342 | { |
1352 | // Assign to the local variables so the normal set action does not happen | 1343 | // Assign to the local variables so the normal set action does not happen |
1353 | _position = entprop.Position; | 1344 | _position = entprop.Position; |
@@ -1375,7 +1366,7 @@ public sealed class BSPrim : PhysicsActor | |||
1375 | // I've collided with something | 1366 | // I've collided with something |
1376 | // Called at taint time from within the Step() function | 1367 | // Called at taint time from within the Step() function |
1377 | CollisionEventUpdate collisionCollection; | 1368 | CollisionEventUpdate collisionCollection; |
1378 | public void Collide(uint collidingWith, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | 1369 | public override void Collide(uint collidingWith, BSPhysObject collidee, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) |
1379 | { | 1370 | { |
1380 | // m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith); | 1371 | // m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith); |
1381 | 1372 | ||
@@ -1387,18 +1378,15 @@ public sealed class BSPrim : PhysicsActor | |||
1387 | } | 1378 | } |
1388 | 1379 | ||
1389 | // DetailLog("{0},BSPrim.Collison,call,with={1}", LocalID, collidingWith); | 1380 | // DetailLog("{0},BSPrim.Collison,call,with={1}", LocalID, collidingWith); |
1390 | BSPrim collidingWithPrim; | 1381 | |
1391 | if (_scene.Prims.TryGetValue(collidingWith, out collidingWithPrim)) | 1382 | // prims in the same linkset cannot collide with each other |
1383 | if (collidee != null && (this.Linkset.LinksetID == collidee.Linkset.LinksetID)) | ||
1392 | { | 1384 | { |
1393 | // prims in the same linkset cannot collide with each other | 1385 | return; |
1394 | if (this.Linkset.LinksetID == collidingWithPrim.Linkset.LinksetID) | ||
1395 | { | ||
1396 | return; | ||
1397 | } | ||
1398 | } | 1386 | } |
1399 | 1387 | ||
1400 | // if someone is subscribed to collision events.... | 1388 | // if someone has subscribed for collision events.... |
1401 | if (_subscribedEventsMs != 0) { | 1389 | if (SubscribedEvents()) { |
1402 | // throttle the collisions to the number of milliseconds specified in the subscription | 1390 | // throttle the collisions to the number of milliseconds specified in the subscription |
1403 | int nowTime = _scene.SimulationNowTime; | 1391 | int nowTime = _scene.SimulationNowTime; |
1404 | if (nowTime >= _nextCollisionOkTime) { | 1392 | if (nowTime >= _nextCollisionOkTime) { |
@@ -1412,7 +1400,7 @@ public sealed class BSPrim : PhysicsActor | |||
1412 | } | 1400 | } |
1413 | 1401 | ||
1414 | // The scene is telling us it's time to pass our collected collisions into the simulator | 1402 | // The scene is telling us it's time to pass our collected collisions into the simulator |
1415 | public void SendCollisions() | 1403 | public override void SendCollisions() |
1416 | { | 1404 | { |
1417 | if (collisionCollection != null && collisionCollection.Count > 0) | 1405 | if (collisionCollection != null && collisionCollection.Count > 0) |
1418 | { | 1406 | { |