diff options
author | onefang | 2019-09-11 16:36:50 +1000 |
---|---|---|
committer | onefang | 2019-09-11 16:36:50 +1000 |
commit | 50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch) | |
tree | 52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs | |
parent | Renamed branch to SledjChisl. (diff) | |
parent | Bump to release flavour, build 0. (diff) | |
download | opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2 opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz |
Merge branch 'SledjChisl'
Diffstat (limited to 'OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs')
-rw-r--r-- | OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs | 123 |
1 files changed, 106 insertions, 17 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs index da3fc18..6aa24d5 100644 --- a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs | |||
@@ -230,34 +230,97 @@ public abstract class BSPhysObject : PhysicsActor | |||
230 | // Update the physical location and motion of the object. Called with data from Bullet. | 230 | // Update the physical location and motion of the object. Called with data from Bullet. |
231 | public abstract void UpdateProperties(EntityProperties entprop); | 231 | public abstract void UpdateProperties(EntityProperties entprop); |
232 | 232 | ||
233 | // The position value as known by BulletSim. Does not effect the physics engine. | ||
233 | public virtual OMV.Vector3 RawPosition { get; set; } | 234 | public virtual OMV.Vector3 RawPosition { get; set; } |
235 | // Set position in BulletSim and the physics engined to a value immediately. Must be called at taint time. | ||
234 | public abstract OMV.Vector3 ForcePosition { get; set; } | 236 | public abstract OMV.Vector3 ForcePosition { get; set; } |
235 | 237 | ||
238 | // The orientation value as known by BulletSim. Does not effect the physics engine. | ||
236 | public virtual OMV.Quaternion RawOrientation { get; set; } | 239 | public virtual OMV.Quaternion RawOrientation { get; set; } |
240 | // Set orientation in BulletSim and the physics engine to a value immediately. Must be called at taint time. | ||
237 | public abstract OMV.Quaternion ForceOrientation { get; set; } | 241 | public abstract OMV.Quaternion ForceOrientation { get; set; } |
238 | 242 | ||
243 | // The velocity value as known by BulletSim. Does not effect the physics engine. | ||
239 | public virtual OMV.Vector3 RawVelocity { get; set; } | 244 | public virtual OMV.Vector3 RawVelocity { get; set; } |
245 | // Set velocity in BulletSim and the physics engined to a value immediately. Must be called at taint time. | ||
240 | public abstract OMV.Vector3 ForceVelocity { get; set; } | 246 | public abstract OMV.Vector3 ForceVelocity { get; set; } |
241 | 247 | ||
248 | // The rotational velocity value as known by BulletSim. Does not effect the physics engine. | ||
249 | public OMV.Vector3 RawRotationalVelocity { get; set; } | ||
250 | |||
251 | // RawForce is a constant force applied to object (see Force { set; } ) | ||
242 | public OMV.Vector3 RawForce { get; set; } | 252 | public OMV.Vector3 RawForce { get; set; } |
243 | public OMV.Vector3 RawTorque { get; set; } | 253 | public OMV.Vector3 RawTorque { get; set; } |
254 | |||
244 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) | 255 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) |
245 | { | 256 | { |
246 | AddAngularForce(force, pushforce, false); | 257 | AddAngularForce(false, force); |
247 | } | 258 | } |
248 | public abstract void AddAngularForce(OMV.Vector3 force, bool pushforce, bool inTaintTime); | 259 | public abstract void AddAngularForce(bool inTaintTime, OMV.Vector3 force); |
249 | public abstract void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime); | 260 | public abstract void AddForce(bool inTaintTime, OMV.Vector3 force); |
250 | 261 | ||
251 | public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } | 262 | // PhysicsActor.Velocity |
263 | public override OMV.Vector3 Velocity | ||
264 | { | ||
265 | get { return RawVelocity; } | ||
266 | set | ||
267 | { | ||
268 | // This sets the velocity now. BSCharacter will override to clear target velocity | ||
269 | // before calling this. | ||
270 | RawVelocity = value; | ||
271 | PhysScene.TaintedObject(LocalID, TypeName + ".SetVelocity", delegate () { | ||
272 | // DetailLog("{0},BSPhysObject.Velocity.set,vel={1}", LocalID, RawVelocity); | ||
273 | ForceVelocity = RawVelocity; | ||
274 | }); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | // PhysicsActor.SetMomentum | ||
279 | // All the physics engines use this as a way of forcing the velocity to something. | ||
280 | // BSCharacter overrides this so it can set the target velocity to zero before calling this. | ||
281 | public override void SetMomentum(OMV.Vector3 momentum) | ||
282 | { | ||
283 | this.Velocity = momentum; | ||
284 | } | ||
285 | |||
286 | public override OMV.Vector3 RotationalVelocity { | ||
287 | get { | ||
288 | return RawRotationalVelocity; | ||
289 | } | ||
290 | set { | ||
291 | RawRotationalVelocity = value; | ||
292 | Util.ClampV(RawRotationalVelocity, BSParam.MaxAngularVelocity); | ||
293 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); | ||
294 | PhysScene.TaintedObject(LocalID, TypeName + ".setRotationalVelocity", delegate() | ||
295 | { | ||
296 | ForceRotationalVelocity = RawRotationalVelocity; | ||
297 | }); | ||
298 | } | ||
299 | } | ||
300 | public OMV.Vector3 ForceRotationalVelocity { | ||
301 | get { | ||
302 | return RawRotationalVelocity; | ||
303 | } | ||
304 | set { | ||
305 | RawRotationalVelocity = Util.ClampV(value, BSParam.MaxAngularVelocity); | ||
306 | if (PhysBody.HasPhysicalBody) | ||
307 | { | ||
308 | DetailLog("{0},{1}.ForceRotationalVel,taint,rotvel={2}", LocalID, TypeName, RawRotationalVelocity); | ||
309 | PhysScene.PE.SetAngularVelocity(PhysBody, RawRotationalVelocity); | ||
310 | // PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); | ||
311 | ActivateIfPhysical(false); | ||
312 | } | ||
313 | } | ||
314 | } | ||
252 | 315 | ||
253 | public abstract float ForceBuoyancy { get; set; } | 316 | public abstract float ForceBuoyancy { get; set; } |
254 | 317 | ||
255 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } | 318 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } |
256 | 319 | ||
257 | public override bool PIDActive | 320 | public override bool PIDActive |
258 | { | 321 | { |
259 | get { return MoveToTargetActive; } | 322 | get { return MoveToTargetActive; } |
260 | set { MoveToTargetActive = value; } | 323 | set { MoveToTargetActive = value; } |
261 | } | 324 | } |
262 | 325 | ||
263 | public override OMV.Vector3 PIDTarget { set { MoveToTargetTarget = value; } } | 326 | public override OMV.Vector3 PIDTarget { set { MoveToTargetTarget = value; } } |
@@ -268,7 +331,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
268 | public float MoveToTargetTau { get; set; } | 331 | public float MoveToTargetTau { get; set; } |
269 | 332 | ||
270 | // Used for llSetHoverHeight and maybe vehicle height. Hover Height will override MoveTo target's Z | 333 | // Used for llSetHoverHeight and maybe vehicle height. Hover Height will override MoveTo target's Z |
271 | public override bool PIDHoverActive { set { HoverActive = value; } } | 334 | public override bool PIDHoverActive {get {return HoverActive;} set { HoverActive = value; } } |
272 | public override float PIDHoverHeight { set { HoverHeight = value; } } | 335 | public override float PIDHoverHeight { set { HoverHeight = value; } } |
273 | public override PIDHoverType PIDHoverType { set { HoverType = value; } } | 336 | public override PIDHoverType PIDHoverType { set { HoverType = value; } } |
274 | public override float PIDHoverTau { set { HoverTau = value; } } | 337 | public override float PIDHoverTau { set { HoverTau = value; } } |
@@ -452,18 +515,24 @@ public abstract class BSPhysObject : PhysicsActor | |||
452 | private long CollisionsLastTickStep = -1; | 515 | private long CollisionsLastTickStep = -1; |
453 | 516 | ||
454 | // The simulation step is telling this object about a collision. | 517 | // The simulation step is telling this object about a collision. |
518 | // I'm the 'collider', the thing I'm colliding with is the 'collidee'. | ||
455 | // Return 'true' if a collision was processed and should be sent up. | 519 | // Return 'true' if a collision was processed and should be sent up. |
456 | // Return 'false' if this object is not enabled/subscribed/appropriate for or has already seen this collision. | 520 | // Return 'false' if this object is not enabled/subscribed/appropriate for or has already seen this collision. |
457 | // Called at taint time from within the Step() function | 521 | // Called at taint time from within the Step() function |
458 | public delegate bool CollideCall(uint collidingWith, BSPhysObject collidee, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth); | 522 | public virtual bool Collide(BSPhysObject collidee, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) |
459 | public virtual bool Collide(uint collidingWith, BSPhysObject collidee, | ||
460 | OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth) | ||
461 | { | 523 | { |
462 | bool ret = false; | 524 | bool ret = false; |
463 | 525 | ||
526 | // if 'collidee' is null, that means it is terrain | ||
527 | uint collideeLocalID = (collidee == null) ? BSScene.TERRAIN_ID : collidee.LocalID; | ||
528 | // All terrain goes by the TERRAIN_ID id when passed up as a collision | ||
529 | if (collideeLocalID <= PhysScene.TerrainManager.HighestTerrainID) { | ||
530 | collideeLocalID = BSScene.TERRAIN_ID; | ||
531 | } | ||
532 | |||
464 | // The following lines make IsColliding(), CollidingGround() and CollidingObj work | 533 | // The following lines make IsColliding(), CollidingGround() and CollidingObj work |
465 | CollidingStep = PhysScene.SimulationStep; | 534 | CollidingStep = PhysScene.SimulationStep; |
466 | if (collidingWith <= PhysScene.TerrainManager.HighestTerrainID) | 535 | if (collideeLocalID == BSScene.TERRAIN_ID) |
467 | { | 536 | { |
468 | CollidingGroundStep = PhysScene.SimulationStep; | 537 | CollidingGroundStep = PhysScene.SimulationStep; |
469 | } | 538 | } |
@@ -474,10 +543,13 @@ public abstract class BSPhysObject : PhysicsActor | |||
474 | 543 | ||
475 | CollisionAccumulation++; | 544 | CollisionAccumulation++; |
476 | 545 | ||
477 | // For movement tests, remember if we are colliding with an object that is moving. | 546 | // For movement tests, if the collider is me, remember if we are colliding with an object that is moving. |
478 | ColliderIsMoving = collidee != null ? (collidee.RawVelocity != OMV.Vector3.Zero) : false; | 547 | // Here the 'collider'/'collidee' thing gets messed up. In the larger context, when something is checking |
548 | // if the thing it is colliding with is moving, for instance, it asks if the its collider is moving. | ||
549 | ColliderIsMoving = collidee != null ? (collidee.RawVelocity != OMV.Vector3.Zero || collidee.RotationalVelocity != OMV.Vector3.Zero) : false; | ||
479 | ColliderIsVolumeDetect = collidee != null ? (collidee.IsVolumeDetect) : false; | 550 | ColliderIsVolumeDetect = collidee != null ? (collidee.IsVolumeDetect) : false; |
480 | 551 | ||
552 | |||
481 | // Make a collection of the collisions that happened the last simulation tick. | 553 | // Make a collection of the collisions that happened the last simulation tick. |
482 | // This is different than the collection created for sending up to the simulator as it is cleared every tick. | 554 | // This is different than the collection created for sending up to the simulator as it is cleared every tick. |
483 | if (CollisionsLastTickStep != PhysScene.SimulationStep) | 555 | if (CollisionsLastTickStep != PhysScene.SimulationStep) |
@@ -485,16 +557,29 @@ public abstract class BSPhysObject : PhysicsActor | |||
485 | CollisionsLastTick = new CollisionEventUpdate(); | 557 | CollisionsLastTick = new CollisionEventUpdate(); |
486 | CollisionsLastTickStep = PhysScene.SimulationStep; | 558 | CollisionsLastTickStep = PhysScene.SimulationStep; |
487 | } | 559 | } |
488 | CollisionsLastTick.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); | 560 | CollisionsLastTick.AddCollider(collideeLocalID, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); |
489 | 561 | ||
490 | // If someone has subscribed for collision events log the collision so it will be reported up | 562 | // If someone has subscribed for collision events log the collision so it will be reported up |
491 | if (SubscribedEvents()) { | 563 | if (SubscribedEvents()) { |
564 | ContactPoint newContact = new ContactPoint(contactPoint, contactNormal, pentrationDepth); | ||
565 | |||
566 | // Collision sound requires a velocity to know it should happen. This is a lot of computation for a little used feature. | ||
567 | OMV.Vector3 relvel = OMV.Vector3.Zero; | ||
568 | if (IsPhysical) | ||
569 | relvel = RawVelocity; | ||
570 | if (collidee != null && collidee.IsPhysical) | ||
571 | relvel -= collidee.RawVelocity; | ||
572 | newContact.RelativeSpeed = -OMV.Vector3.Dot(relvel, contactNormal); | ||
573 | // DetailLog("{0},{1}.Collision.AddCollider,vel={2},contee.vel={3},relvel={4},relspeed={5}", | ||
574 | // LocalID, TypeName, RawVelocity, (collidee == null ? OMV.Vector3.Zero : collidee.RawVelocity), relvel, newContact.RelativeSpeed); | ||
575 | |||
492 | lock (PhysScene.CollisionLock) | 576 | lock (PhysScene.CollisionLock) |
493 | { | 577 | { |
494 | CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); | 578 | CollisionCollection.AddCollider(collideeLocalID, newContact); |
495 | } | 579 | } |
496 | DetailLog("{0},{1}.Collision.AddCollider,call,with={2},point={3},normal={4},depth={5},colliderMoving={6}", | 580 | DetailLog("{0},{1}.Collision.AddCollider,call,with={2},point={3},normal={4},depth={5},speed={6},colliderMoving={7}", |
497 | LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth, ColliderIsMoving); | 581 | LocalID, TypeName, collideeLocalID, contactPoint, contactNormal, pentrationDepth, |
582 | newContact.RelativeSpeed, ColliderIsMoving); | ||
498 | 583 | ||
499 | ret = true; | 584 | ret = true; |
500 | } | 585 | } |
@@ -555,7 +640,11 @@ public abstract class BSPhysObject : PhysicsActor | |||
555 | PhysScene.TaintedObject(LocalID, TypeName+".SubscribeEvents", delegate() | 640 | PhysScene.TaintedObject(LocalID, TypeName+".SubscribeEvents", delegate() |
556 | { | 641 | { |
557 | if (PhysBody.HasPhysicalBody) | 642 | if (PhysBody.HasPhysicalBody) |
643 | { | ||
558 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 644 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
645 | DetailLog("{0},{1}.SubscribeEvents,setting collision. ms={2}, collisionFlags={3:x}", | ||
646 | LocalID, TypeName, SubscribedEventsMs, CurrentCollisionFlags); | ||
647 | } | ||
559 | }); | 648 | }); |
560 | } | 649 | } |
561 | else | 650 | else |