diff options
author | Robert Adams | 2013-02-07 17:05:40 -0800 |
---|---|---|
committer | Robert Adams | 2013-02-07 17:13:28 -0800 |
commit | 913965256fecd4e25e06fe374fa5d8b8712a3b15 (patch) | |
tree | b82cbbe7d6e3ec56a5e0cd8dbcd94328f66efe64 /OpenSim/Region/Physics | |
parent | BulletSim: fix exceptions caused by setting physical properties before the pr... (diff) | |
download | opensim-SC_OLD-913965256fecd4e25e06fe374fa5d8b8712a3b15.zip opensim-SC_OLD-913965256fecd4e25e06fe374fa5d8b8712a3b15.tar.gz opensim-SC_OLD-913965256fecd4e25e06fe374fa5d8b8712a3b15.tar.bz2 opensim-SC_OLD-913965256fecd4e25e06fe374fa5d8b8712a3b15.tar.xz |
BulletSim: Adapt BulletSim to the newer physical properties. Viewer
dialog setting of friction, restitution, ... working.
Diffstat (limited to 'OpenSim/Region/Physics')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 4 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 54 |
2 files changed, 28 insertions, 30 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 0b35f3a..0d8bb03 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -79,7 +79,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
79 | TypeName = typeName; | 79 | TypeName = typeName; |
80 | 80 | ||
81 | // Initialize variables kept in base. | 81 | // Initialize variables kept in base. |
82 | GravityModifier = 1.0f; | 82 | GravModifier = 1.0f; |
83 | Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity); | 83 | Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity); |
84 | 84 | ||
85 | // We don't have any physical representation yet. | 85 | // We don't have any physical representation yet. |
@@ -170,6 +170,8 @@ public abstract class BSPhysObject : PhysicsActor | |||
170 | public override void SetMaterial(int material) | 170 | public override void SetMaterial(int material) |
171 | { | 171 | { |
172 | Material = (MaterialAttributes.Material)material; | 172 | Material = (MaterialAttributes.Material)material; |
173 | |||
174 | // Setting the material sets the material attributes also. | ||
173 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); | 175 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); |
174 | Friction = matAttrib.friction; | 176 | Friction = matAttrib.friction; |
175 | Restitution = matAttrib.restitution; | 177 | Restitution = matAttrib.restitution; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 38adb72..85c2627 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -423,8 +423,6 @@ public sealed class BSPrim : BSPhysObject | |||
423 | } | 423 | } |
424 | else | 424 | else |
425 | { | 425 | { |
426 | OMV.Vector3 grav = ComputeGravity(Buoyancy); | ||
427 | |||
428 | if (inWorld) | 426 | if (inWorld) |
429 | { | 427 | { |
430 | // Changing interesting properties doesn't change proxy and collision cache | 428 | // Changing interesting properties doesn't change proxy and collision cache |
@@ -434,15 +432,15 @@ public sealed class BSPrim : BSPhysObject | |||
434 | } | 432 | } |
435 | 433 | ||
436 | // The computation of mass props requires gravity to be set on the object. | 434 | // The computation of mass props requires gravity to be set on the object. |
437 | PhysicsScene.PE.SetGravity(PhysBody, grav); | 435 | Gravity = ComputeGravity(Buoyancy); |
436 | PhysicsScene.PE.SetGravity(PhysBody, Gravity); | ||
438 | 437 | ||
439 | Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); | 438 | Inertia = PhysicsScene.PE.CalculateLocalInertia(PhysShape, physMass); |
440 | PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia); | 439 | PhysicsScene.PE.SetMassProps(PhysBody, physMass, Inertia); |
441 | PhysicsScene.PE.UpdateInertiaTensor(PhysBody); | 440 | PhysicsScene.PE.UpdateInertiaTensor(PhysBody); |
442 | 441 | ||
443 | // center of mass is at the zero of the object | 442 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", |
444 | // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(PhysBody, ForcePosition, ForceOrientation); | 443 | LocalID, physMass, Inertia, Gravity, inWorld); |
445 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld); | ||
446 | 444 | ||
447 | if (inWorld) | 445 | if (inWorld) |
448 | { | 446 | { |
@@ -455,10 +453,13 @@ public sealed class BSPrim : BSPhysObject | |||
455 | // Return what gravity should be set to this very moment | 453 | // Return what gravity should be set to this very moment |
456 | public OMV.Vector3 ComputeGravity(float buoyancy) | 454 | public OMV.Vector3 ComputeGravity(float buoyancy) |
457 | { | 455 | { |
458 | OMV.Vector3 ret = PhysicsScene.DefaultGravity * GravityModifier; | 456 | OMV.Vector3 ret = PhysicsScene.DefaultGravity; |
459 | 457 | ||
460 | if (!IsStatic) | 458 | if (!IsStatic) |
459 | { | ||
461 | ret *= (1f - buoyancy); | 460 | ret *= (1f - buoyancy); |
461 | ret *= GravModifier; | ||
462 | } | ||
462 | 463 | ||
463 | return ret; | 464 | return ret; |
464 | } | 465 | } |
@@ -587,8 +588,7 @@ public sealed class BSPrim : BSPhysObject | |||
587 | base.SetMaterial(material); | 588 | base.SetMaterial(material); |
588 | PhysicsScene.TaintedObject("BSPrim.SetMaterial", delegate() | 589 | PhysicsScene.TaintedObject("BSPrim.SetMaterial", delegate() |
589 | { | 590 | { |
590 | if (PhysBody.HasPhysicalBody) | 591 | UpdatePhysicalParameters(); |
591 | UpdatePhysicalParameters(); | ||
592 | }); | 592 | }); |
593 | } | 593 | } |
594 | public override float Friction | 594 | public override float Friction |
@@ -601,8 +601,7 @@ public sealed class BSPrim : BSPhysObject | |||
601 | base.Friction = value; | 601 | base.Friction = value; |
602 | PhysicsScene.TaintedObject("BSPrim.setFriction", delegate() | 602 | PhysicsScene.TaintedObject("BSPrim.setFriction", delegate() |
603 | { | 603 | { |
604 | if (PhysBody.HasPhysicalBody) | 604 | UpdatePhysicalParameters(); |
605 | UpdatePhysicalParameters(); | ||
606 | }); | 605 | }); |
607 | } | 606 | } |
608 | } | 607 | } |
@@ -617,8 +616,7 @@ public sealed class BSPrim : BSPhysObject | |||
617 | base.Restitution = value; | 616 | base.Restitution = value; |
618 | PhysicsScene.TaintedObject("BSPrim.setRestitution", delegate() | 617 | PhysicsScene.TaintedObject("BSPrim.setRestitution", delegate() |
619 | { | 618 | { |
620 | if (PhysBody.HasPhysicalBody) | 619 | UpdatePhysicalParameters(); |
621 | UpdatePhysicalParameters(); | ||
622 | }); | 620 | }); |
623 | } | 621 | } |
624 | } | 622 | } |
@@ -633,24 +631,22 @@ public sealed class BSPrim : BSPhysObject | |||
633 | base.Density = value; | 631 | base.Density = value; |
634 | PhysicsScene.TaintedObject("BSPrim.setDensity", delegate() | 632 | PhysicsScene.TaintedObject("BSPrim.setDensity", delegate() |
635 | { | 633 | { |
636 | if (PhysBody.HasPhysicalBody) | 634 | UpdatePhysicalParameters(); |
637 | UpdatePhysicalParameters(); | ||
638 | }); | 635 | }); |
639 | } | 636 | } |
640 | } | 637 | } |
641 | } | 638 | } |
642 | public override float GravityModifier | 639 | public override float GravModifier |
643 | { | 640 | { |
644 | get { return base.GravityModifier; } | 641 | get { return base.GravModifier; } |
645 | set | 642 | set |
646 | { | 643 | { |
647 | if (base.GravityModifier != value) | 644 | if (base.GravModifier != value) |
648 | { | 645 | { |
649 | base.GravityModifier = value; | 646 | base.GravModifier = value; |
650 | PhysicsScene.TaintedObject("BSPrim.setGravityModifier", delegate() | 647 | PhysicsScene.TaintedObject("BSPrim.setGravityModifier", delegate() |
651 | { | 648 | { |
652 | if (PhysBody.HasPhysicalBody) | 649 | UpdatePhysicalParameters(); |
653 | UpdatePhysicalParameters(); | ||
654 | }); | 650 | }); |
655 | } | 651 | } |
656 | } | 652 | } |
@@ -820,7 +816,12 @@ public sealed class BSPrim : BSPhysObject | |||
820 | // collisionEvents: whether this object returns collision events | 816 | // collisionEvents: whether this object returns collision events |
821 | public void UpdatePhysicalParameters() | 817 | public void UpdatePhysicalParameters() |
822 | { | 818 | { |
823 | // DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); | 819 | if (!PhysBody.HasPhysicalBody) |
820 | { | ||
821 | // This would only happen if updates are called for during initialization when the body is not set up yet. | ||
822 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taint,calledWithNoPhysBody", LocalID); | ||
823 | return; | ||
824 | } | ||
824 | 825 | ||
825 | // Mangling all the physical properties requires the object not be in the physical world. | 826 | // Mangling all the physical properties requires the object not be in the physical world. |
826 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). | 827 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). |
@@ -898,9 +899,9 @@ public sealed class BSPrim : BSPhysObject | |||
898 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); | 899 | CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.CF_STATIC_OBJECT); |
899 | 900 | ||
900 | // Set various physical properties so other object interact properly | 901 | // Set various physical properties so other object interact properly |
901 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); | ||
902 | PhysicsScene.PE.SetFriction(PhysBody, Friction); | 902 | PhysicsScene.PE.SetFriction(PhysBody, Friction); |
903 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); | 903 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); |
904 | // DetailLog("{0},BSPrim.MakeDynamic,frict={1},rest={2}", LocalID, Friction, Restitution); | ||
904 | 905 | ||
905 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 | 906 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 |
906 | // Since this can be called multiple times, only zero forces when becoming physical | 907 | // Since this can be called multiple times, only zero forces when becoming physical |
@@ -999,16 +1000,11 @@ public sealed class BSPrim : BSPhysObject | |||
999 | if (PhysBody.HasPhysicalBody) | 1000 | if (PhysBody.HasPhysicalBody) |
1000 | { | 1001 | { |
1001 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); | 1002 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); |
1002 | |||
1003 | // Must set gravity after it has been added to the world because, for unknown reasons, | ||
1004 | // adding the object resets the object's gravity to world gravity | ||
1005 | OMV.Vector3 grav = ComputeGravity(Buoyancy); | ||
1006 | PhysicsScene.PE.SetGravity(PhysBody, grav); | ||
1007 | } | 1003 | } |
1008 | else | 1004 | else |
1009 | { | 1005 | { |
1010 | m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID); | 1006 | m_log.ErrorFormat("{0} Attempt to add physical object without body. id={1}", LogHeader, LocalID); |
1011 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType); | 1007 | DetailLog("{0},BSPrim.AddObjectToPhysicalWorld,addObjectWithoutBody,cType={1}", LocalID, PhysBody.collisionType); |
1012 | } | 1008 | } |
1013 | } | 1009 | } |
1014 | 1010 | ||