diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 102 |
1 files changed, 87 insertions, 15 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 5ff9d32..62c5c81 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | |||
@@ -21,6 +21,18 @@ | |||
21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | * | ||
25 | * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces | ||
26 | * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised: | ||
27 | * ODEPrim.cs contains methods dealing with Prim editing, Prim | ||
28 | * characteristics and Kinetic motion. | ||
29 | * ODEDynamics.cs contains methods dealing with Prim Physical motion | ||
30 | * (dynamics) and the associated settings. Old Linear and angular | ||
31 | * motors for dynamic motion have been replace with MoveLinear() | ||
32 | * and MoveAngular(); 'Physical' is used only to switch ODE dynamic | ||
33 | * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to | ||
34 | * switch between 'VEHICLE' parameter use and general dynamics | ||
35 | * settings use. | ||
24 | */ | 36 | */ |
25 | 37 | ||
26 | /* | 38 | /* |
@@ -81,7 +93,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
81 | private float m_PIDTau; | 93 | private float m_PIDTau; |
82 | private float PID_D = 35f; | 94 | private float PID_D = 35f; |
83 | private float PID_G = 25f; | 95 | private float PID_G = 25f; |
84 | private bool m_usePID; | 96 | private bool m_usePID = false; |
97 | |||
98 | private Quaternion m_APIDTarget = new Quaternion(); | ||
99 | private float m_APIDStrength = 0.5f; | ||
100 | private float m_APIDDamping = 0.5f; | ||
101 | private bool m_useAPID = false; | ||
85 | 102 | ||
86 | // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau), | 103 | // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau), |
87 | // and are for non-VEHICLES only. | 104 | // and are for non-VEHICLES only. |
@@ -90,10 +107,17 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
90 | private float m_PIDHoverTau; | 107 | private float m_PIDHoverTau; |
91 | private bool m_useHoverPID; | 108 | private bool m_useHoverPID; |
92 | private PIDHoverType m_PIDHoverType = PIDHoverType.Ground; | 109 | private PIDHoverType m_PIDHoverType = PIDHoverType.Ground; |
110 | <<<<<<< HEAD:OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | ||
111 | private float m_targetHoverHeight = 0f; | ||
112 | private float m_groundHeight = 0f; | ||
113 | private float m_waterHeight = 0f; | ||
114 | private float m_buoyancy = 0f; //Set by llSetBuoyancy(), for non-vehicles. | ||
115 | ======= | ||
93 | private float m_targetHoverHeight; | 116 | private float m_targetHoverHeight; |
94 | private float m_groundHeight; | 117 | private float m_groundHeight; |
95 | private float m_waterHeight; | 118 | private float m_waterHeight; |
96 | private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle. | 119 | private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle. |
120 | >>>>>>> vehicles:OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | ||
97 | 121 | ||
98 | // private float m_tensor = 5f; | 122 | // private float m_tensor = 5f; |
99 | private int body_autodisable_frames = 20; | 123 | private int body_autodisable_frames = 20; |
@@ -182,6 +206,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
182 | private ODEDynamics m_vehicle; | 206 | private ODEDynamics m_vehicle; |
183 | 207 | ||
184 | internal int m_material = (int)Material.Wood; | 208 | internal int m_material = (int)Material.Wood; |
209 | |||
210 | private int frcount = 0; // Used to limit dynamics debug output to | ||
211 | |||
185 | 212 | ||
186 | public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size, | 213 | public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size, |
187 | Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) | 214 | Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) |
@@ -1558,9 +1585,14 @@ Console.WriteLine(" JointCreateFixed"); | |||
1558 | float fy = 0; | 1585 | float fy = 0; |
1559 | float fz = 0; | 1586 | float fz = 0; |
1560 | 1587 | ||
1588 | frcount++; // used to limit debug comment output | ||
1589 | if (frcount > 100) | ||
1590 | frcount = 0; | ||
1561 | 1591 | ||
1562 | if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // KF: Only move root prims. | 1592 | if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // KF: Only move root prims. |
1563 | { | 1593 | { |
1594 | if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle.Type + | ||
1595 | " usePID=" + m_usePID + " seHover=" + m_useHoverPID + " useAPID=" + m_useAPID); | ||
1564 | if (m_vehicle.Type != Vehicle.TYPE_NONE) | 1596 | if (m_vehicle.Type != Vehicle.TYPE_NONE) |
1565 | { | 1597 | { |
1566 | // 'VEHICLES' are dealt with in ODEDynamics.cs | 1598 | // 'VEHICLES' are dealt with in ODEDynamics.cs |
@@ -1568,7 +1600,6 @@ Console.WriteLine(" JointCreateFixed"); | |||
1568 | } | 1600 | } |
1569 | else | 1601 | else |
1570 | { | 1602 | { |
1571 | //Console.WriteLine("Move " + m_primName); | ||
1572 | if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009 | 1603 | if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009 |
1573 | // NON-'VEHICLES' are dealt with here | 1604 | // NON-'VEHICLES' are dealt with here |
1574 | if (d.BodyIsEnabled(Body) && !m_angularlock.ApproxEquals(Vector3.Zero, 0.003f)) | 1605 | if (d.BodyIsEnabled(Body) && !m_angularlock.ApproxEquals(Vector3.Zero, 0.003f)) |
@@ -1590,21 +1621,18 @@ Console.WriteLine(" JointCreateFixed"); | |||
1590 | //m_log.Info(m_collisionFlags.ToString()); | 1621 | //m_log.Info(m_collisionFlags.ToString()); |
1591 | 1622 | ||
1592 | 1623 | ||
1593 | //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle. | 1624 | //KF: m_buoyancy is set by llSetBuoyancy() and is for non-vehicle. |
1594 | // would come from SceneObjectPart.cs, public void SetBuoyancy(float fvalue) , PhysActor.Buoyancy = fvalue; ?? | ||
1595 | // m_buoyancy: (unlimited value) <0=Falls fast; 0=1g; 1=0g; >1 = floats up | 1625 | // m_buoyancy: (unlimited value) <0=Falls fast; 0=1g; 1=0g; >1 = floats up |
1596 | // gravityz multiplier = 1 - m_buoyancy | 1626 | // NB Prims in ODE are no subject to global gravity |
1597 | fz = _parent_scene.gravityz * (1.0f - m_buoyancy) * m_mass; | 1627 | fz = _parent_scene.gravityz * (1.0f - m_buoyancy) * m_mass; // force = acceleration * mass |
1598 | 1628 | ||
1599 | if (m_usePID) | 1629 | if (m_usePID) |
1600 | { | 1630 | { |
1601 | //Console.WriteLine("PID " + m_primName); | 1631 | //if(frcount == 0) Console.WriteLine("PID " + m_primName); |
1602 | // KF - this is for object move? eg. llSetPos() ? | 1632 | // KF - this is for object MoveToTarget. |
1633 | |||
1603 | //if (!d.BodyIsEnabled(Body)) | 1634 | //if (!d.BodyIsEnabled(Body)) |
1604 | //d.BodySetForce(Body, 0f, 0f, 0f); | 1635 | //d.BodySetForce(Body, 0f, 0f, 0f); |
1605 | // If we're using the PID controller, then we have no gravity | ||
1606 | //fz = (-1 * _parent_scene.gravityz) * m_mass; //KF: ?? Prims have no global gravity,so simply... | ||
1607 | fz = 0f; | ||
1608 | 1636 | ||
1609 | // no lock; for now it's only called from within Simulate() | 1637 | // no lock; for now it's only called from within Simulate() |
1610 | 1638 | ||
@@ -1739,7 +1767,7 @@ Console.WriteLine(" JointCreateFixed"); | |||
1739 | d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); | 1767 | d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); |
1740 | d.BodySetLinearVel(Body, vel.X, vel.Y, 0); | 1768 | d.BodySetLinearVel(Body, vel.X, vel.Y, 0); |
1741 | d.BodyAddForce(Body, 0, 0, fz); | 1769 | d.BodyAddForce(Body, 0, 0, fz); |
1742 | return; | 1770 | //KF this prevents furthur motions return; |
1743 | } | 1771 | } |
1744 | else | 1772 | else |
1745 | { | 1773 | { |
@@ -1748,8 +1776,46 @@ Console.WriteLine(" JointCreateFixed"); | |||
1748 | // We're flying and colliding with something | 1776 | // We're flying and colliding with something |
1749 | fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); | 1777 | fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); |
1750 | } | 1778 | } |
1751 | } | 1779 | } // end m_useHoverPID && !m_usePID |
1752 | 1780 | ||
1781 | if (m_useAPID) | ||
1782 | { | ||
1783 | // RotLookAt, apparently overrides all other rotation sources. Inputs: | ||
1784 | // Quaternion m_APIDTarget | ||
1785 | // float m_APIDStrength // From SL experiments, this is the time to get there | ||
1786 | // float m_APIDDamping // From SL experiments, this is damping, 1.0 = damped, 0.1 = wobbly | ||
1787 | // Also in SL the mass of the object has no effect on time to get there. | ||
1788 | // Factors: | ||
1789 | //if(frcount == 0) Console.WriteLine("APID "); | ||
1790 | // get present body rotation | ||
1791 | float limit = 1.0f; | ||
1792 | float scaler = 50f; // adjusts damping time | ||
1793 | float RLAservo = 0f; | ||
1794 | |||
1795 | d.Quaternion rot = d.BodyGetQuaternion(Body); | ||
1796 | Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); | ||
1797 | Quaternion rot_diff = Quaternion.Inverse(rotq) * m_APIDTarget; | ||
1798 | float diff_angle; | ||
1799 | Vector3 diff_axis; | ||
1800 | rot_diff.GetAxisAngle(out diff_axis, out diff_angle); | ||
1801 | diff_axis.Normalize(); | ||
1802 | if(diff_angle > 0.01f) // diff_angle is always +ve | ||
1803 | { | ||
1804 | // PhysicsVector rotforce = new PhysicsVector(diff_axis.X, diff_axis.Y, diff_axis.Z); | ||
1805 | Vector3 rotforce = new Vector3(diff_axis.X, diff_axis.Y, diff_axis.Z); | ||
1806 | rotforce = rotforce * rotq; | ||
1807 | if(diff_angle > limit) diff_angle = limit; // cap the rotate rate | ||
1808 | // RLAservo = timestep / m_APIDStrength * m_mass * scaler; | ||
1809 | // rotforce = rotforce * RLAservo * diff_angle ; | ||
1810 | // d.BodyAddRelTorque(Body, rotforce.X, rotforce.Y, rotforce.Z); | ||
1811 | RLAservo = timestep / m_APIDStrength * scaler; | ||
1812 | rotforce = rotforce * RLAservo * diff_angle ; | ||
1813 | d.BodySetAngularVel (Body, rotforce.X, rotforce.Y, rotforce.Z); | ||
1814 | //Console.WriteLine("axis= " + diff_axis + " angle= " + diff_angle + "servo= " + RLAservo); | ||
1815 | } | ||
1816 | if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + " angle= " + diff_angle); | ||
1817 | } // end m_useAPID | ||
1818 | |||
1753 | fx *= m_mass; | 1819 | fx *= m_mass; |
1754 | fy *= m_mass; | 1820 | fy *= m_mass; |
1755 | //fz *= m_mass; | 1821 | //fz *= m_mass; |
@@ -2643,7 +2709,7 @@ Console.WriteLine(" JointCreateFixed"); | |||
2643 | //outofBounds = true; | 2709 | //outofBounds = true; |
2644 | } | 2710 | } |
2645 | 2711 | ||
2646 | float Adiff = 1.0f - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)); | 2712 | // float Adiff = 1.0f - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)); |
2647 | //Console.WriteLine("Adiff " + m_primName + " = " + Adiff); | 2713 | //Console.WriteLine("Adiff " + m_primName + " = " + Adiff); |
2648 | if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) | 2714 | if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) |
2649 | && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) | 2715 | && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) |
@@ -2782,6 +2848,12 @@ Console.WriteLine(" JointCreateFixed"); | |||
2782 | } | 2848 | } |
2783 | public override bool PIDActive { set { m_usePID = value; } } | 2849 | public override bool PIDActive { set { m_usePID = value; } } |
2784 | public override float PIDTau { set { m_PIDTau = value; } } | 2850 | public override float PIDTau { set { m_PIDTau = value; } } |
2851 | |||
2852 | // For RotLookAt | ||
2853 | public override Quaternion APIDTarget { set { m_APIDTarget = value; } } | ||
2854 | public override bool APIDActive { set { m_useAPID = value; } } | ||
2855 | public override float APIDStrength { set { m_APIDStrength = value; } } | ||
2856 | public override float APIDDamping { set { m_APIDDamping = value; } } | ||
2785 | 2857 | ||
2786 | public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } } | 2858 | public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } } |
2787 | public override bool PIDHoverActive { set { m_useHoverPID = value; } } | 2859 | public override bool PIDHoverActive { set { m_useHoverPID = value; } } |