diff options
author | Robert Adams | 2013-02-07 11:53:49 -0800 |
---|---|---|
committer | Robert Adams | 2013-02-07 17:13:27 -0800 |
commit | ebb63b55aab98da6d44e82fc0ecfd5d22f245172 (patch) | |
tree | 4c695e5e577547e5c2562f23f8bb1ad06177447f /OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |
parent | Extend TestJsonReadNotecard() for reads to non-root locations and fake stores. (diff) | |
download | opensim-SC-ebb63b55aab98da6d44e82fc0ecfd5d22f245172.zip opensim-SC-ebb63b55aab98da6d44e82fc0ecfd5d22f245172.tar.gz opensim-SC-ebb63b55aab98da6d44e82fc0ecfd5d22f245172.tar.bz2 opensim-SC-ebb63b55aab98da6d44e82fc0ecfd5d22f245172.tar.xz |
BulletSim: add user setting of friction, density and restitution.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 99 |
1 files changed, 79 insertions, 20 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 54bf063..a86932a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -55,7 +55,6 @@ public sealed class BSPrim : BSPhysObject | |||
55 | private OMV.Vector3 _position; | 55 | private OMV.Vector3 _position; |
56 | 56 | ||
57 | private float _mass; // the mass of this object | 57 | private float _mass; // the mass of this object |
58 | private float _density; | ||
59 | private OMV.Vector3 _force; | 58 | private OMV.Vector3 _force; |
60 | private OMV.Vector3 _velocity; | 59 | private OMV.Vector3 _velocity; |
61 | private OMV.Vector3 _torque; | 60 | private OMV.Vector3 _torque; |
@@ -64,8 +63,6 @@ public sealed class BSPrim : BSPhysObject | |||
64 | private int _physicsActorType; | 63 | private int _physicsActorType; |
65 | private bool _isPhysical; | 64 | private bool _isPhysical; |
66 | private bool _flying; | 65 | private bool _flying; |
67 | private float _friction; | ||
68 | private float _restitution; | ||
69 | private bool _setAlwaysRun; | 66 | private bool _setAlwaysRun; |
70 | private bool _throttleUpdates; | 67 | private bool _throttleUpdates; |
71 | private bool _floatOnWater; | 68 | private bool _floatOnWater; |
@@ -101,12 +98,6 @@ public sealed class BSPrim : BSPhysObject | |||
101 | _isPhysical = pisPhysical; | 98 | _isPhysical = pisPhysical; |
102 | _isVolumeDetect = false; | 99 | _isVolumeDetect = false; |
103 | 100 | ||
104 | // Someday set default attributes based on the material but, for now, we don't know the prim material yet. | ||
105 | // MaterialAttributes primMat = BSMaterials.GetAttributes(Material, pisPhysical); | ||
106 | _density = PhysicsScene.Params.defaultDensity; | ||
107 | _friction = PhysicsScene.Params.defaultFriction; | ||
108 | _restitution = PhysicsScene.Params.defaultRestitution; | ||
109 | |||
110 | VehicleController = new BSDynamics(PhysicsScene, this); // add vehicleness | 101 | VehicleController = new BSDynamics(PhysicsScene, this); // add vehicleness |
111 | 102 | ||
112 | _mass = CalculateMass(); | 103 | _mass = CalculateMass(); |
@@ -457,11 +448,6 @@ public sealed class BSPrim : BSPhysObject | |||
457 | { | 448 | { |
458 | AddObjectToPhysicalWorld(); | 449 | AddObjectToPhysicalWorld(); |
459 | } | 450 | } |
460 | |||
461 | // Must set gravity after it has been added to the world because, for unknown reasons, | ||
462 | // adding the object resets the object's gravity to world gravity | ||
463 | PhysicsScene.PE.SetGravity(PhysBody, grav); | ||
464 | |||
465 | } | 451 | } |
466 | } | 452 | } |
467 | } | 453 | } |
@@ -469,7 +455,7 @@ public sealed class BSPrim : BSPhysObject | |||
469 | // Return what gravity should be set to this very moment | 455 | // Return what gravity should be set to this very moment |
470 | public OMV.Vector3 ComputeGravity(float buoyancy) | 456 | public OMV.Vector3 ComputeGravity(float buoyancy) |
471 | { | 457 | { |
472 | OMV.Vector3 ret = PhysicsScene.DefaultGravity; | 458 | OMV.Vector3 ret = PhysicsScene.DefaultGravity * GravityModifier; |
473 | 459 | ||
474 | if (!IsStatic) | 460 | if (!IsStatic) |
475 | ret *= (1f - buoyancy); | 461 | ret *= (1f - buoyancy); |
@@ -596,6 +582,74 @@ public sealed class BSPrim : BSPhysObject | |||
596 | } | 582 | } |
597 | return; | 583 | return; |
598 | } | 584 | } |
585 | public override void SetMaterial(int material) | ||
586 | { | ||
587 | base.SetMaterial(material); | ||
588 | PhysicsScene.TaintedObject("BSPrim.SetMaterial", delegate() | ||
589 | { | ||
590 | UpdatePhysicalParameters(); | ||
591 | }); | ||
592 | } | ||
593 | public override float Friction | ||
594 | { | ||
595 | get { return base.Friction; } | ||
596 | set | ||
597 | { | ||
598 | if (base.Friction != value) | ||
599 | { | ||
600 | base.Friction = value; | ||
601 | PhysicsScene.TaintedObject("BSPrim.setFriction", delegate() | ||
602 | { | ||
603 | UpdatePhysicalParameters(); | ||
604 | }); | ||
605 | } | ||
606 | } | ||
607 | } | ||
608 | public override float Restitution | ||
609 | { | ||
610 | get { return base.Restitution; } | ||
611 | set | ||
612 | { | ||
613 | if (base.Restitution != value) | ||
614 | { | ||
615 | base.Restitution = value; | ||
616 | PhysicsScene.TaintedObject("BSPrim.setRestitution", delegate() | ||
617 | { | ||
618 | UpdatePhysicalParameters(); | ||
619 | }); | ||
620 | } | ||
621 | } | ||
622 | } | ||
623 | public override float Density | ||
624 | { | ||
625 | get { return base.Density; } | ||
626 | set | ||
627 | { | ||
628 | if (base.Density != value) | ||
629 | { | ||
630 | base.Density = value; | ||
631 | PhysicsScene.TaintedObject("BSPrim.setDensity", delegate() | ||
632 | { | ||
633 | UpdatePhysicalParameters(); | ||
634 | }); | ||
635 | } | ||
636 | } | ||
637 | } | ||
638 | public override float GravityModifier | ||
639 | { | ||
640 | get { return base.GravityModifier; } | ||
641 | set | ||
642 | { | ||
643 | if (base.GravityModifier != value) | ||
644 | { | ||
645 | base.GravityModifier = value; | ||
646 | PhysicsScene.TaintedObject("BSPrim.setGravityModifier", delegate() | ||
647 | { | ||
648 | UpdatePhysicalParameters(); | ||
649 | }); | ||
650 | } | ||
651 | } | ||
652 | } | ||
599 | public override OMV.Vector3 RawVelocity | 653 | public override OMV.Vector3 RawVelocity |
600 | { | 654 | { |
601 | get { return _velocity; } | 655 | get { return _velocity; } |
@@ -810,8 +864,8 @@ public sealed class BSPrim : BSPhysObject | |||
810 | 864 | ||
811 | // Set various physical properties so other object interact properly | 865 | // Set various physical properties so other object interact properly |
812 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); | 866 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); |
813 | PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); | 867 | PhysicsScene.PE.SetFriction(PhysBody, Friction); |
814 | PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); | 868 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); |
815 | 869 | ||
816 | // Mass is zero which disables a bunch of physics stuff in Bullet | 870 | // Mass is zero which disables a bunch of physics stuff in Bullet |
817 | UpdatePhysicalMassProperties(0f, false); | 871 | UpdatePhysicalMassProperties(0f, false); |
@@ -840,8 +894,8 @@ public sealed class BSPrim : BSPhysObject | |||
840 | 894 | ||
841 | // Set various physical properties so other object interact properly | 895 | // Set various physical properties so other object interact properly |
842 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); | 896 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, true); |
843 | PhysicsScene.PE.SetFriction(PhysBody, matAttrib.friction); | 897 | PhysicsScene.PE.SetFriction(PhysBody, Friction); |
844 | PhysicsScene.PE.SetRestitution(PhysBody, matAttrib.restitution); | 898 | PhysicsScene.PE.SetRestitution(PhysBody, Restitution); |
845 | 899 | ||
846 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 | 900 | // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 |
847 | // Since this can be called multiple times, only zero forces when becoming physical | 901 | // Since this can be called multiple times, only zero forces when becoming physical |
@@ -940,6 +994,11 @@ public sealed class BSPrim : BSPhysObject | |||
940 | if (PhysBody.HasPhysicalBody) | 994 | if (PhysBody.HasPhysicalBody) |
941 | { | 995 | { |
942 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); | 996 | PhysicsScene.PE.AddObjectToWorld(PhysicsScene.World, PhysBody); |
997 | |||
998 | // Must set gravity after it has been added to the world because, for unknown reasons, | ||
999 | // adding the object resets the object's gravity to world gravity | ||
1000 | OMV.Vector3 grav = ComputeGravity(Buoyancy); | ||
1001 | PhysicsScene.PE.SetGravity(PhysBody, grav); | ||
943 | } | 1002 | } |
944 | else | 1003 | else |
945 | { | 1004 | { |
@@ -1581,7 +1640,7 @@ public sealed class BSPrim : BSPhysObject | |||
1581 | profileEnd = 1.0f - (float)BaseShape.ProfileEnd * 2.0e-5f; | 1640 | profileEnd = 1.0f - (float)BaseShape.ProfileEnd * 2.0e-5f; |
1582 | volume *= (profileEnd - profileBegin); | 1641 | volume *= (profileEnd - profileBegin); |
1583 | 1642 | ||
1584 | returnMass = _density * volume; | 1643 | returnMass = Density * volume; |
1585 | 1644 | ||
1586 | /* Comment out code that computes the mass of the linkset. That is done in the Linkset class. | 1645 | /* Comment out code that computes the mass of the linkset. That is done in the Linkset class. |
1587 | if (IsRootOfLinkset) | 1646 | if (IsRootOfLinkset) |