diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 93 |
1 files changed, 79 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 6f14f7b..c7e0848 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. |
@@ -182,6 +199,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
182 | private ODEDynamics m_vehicle; | 199 | private ODEDynamics m_vehicle; |
183 | 200 | ||
184 | internal int m_material = (int)Material.Wood; | 201 | internal int m_material = (int)Material.Wood; |
202 | |||
203 | private int frcount = 0; // Used to limit dynamics debug output to | ||
204 | |||
185 | 205 | ||
186 | public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size, | 206 | public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size, |
187 | Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) | 207 | Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) |
@@ -1558,9 +1578,14 @@ Console.WriteLine(" JointCreateFixed"); | |||
1558 | float fy = 0; | 1578 | float fy = 0; |
1559 | float fz = 0; | 1579 | float fz = 0; |
1560 | 1580 | ||
1581 | frcount++; // used to limit debug comment output | ||
1582 | if (frcount > 100) | ||
1583 | frcount = 0; | ||
1561 | 1584 | ||
1562 | if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // KF: Only move root prims. | 1585 | if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // KF: Only move root prims. |
1563 | { | 1586 | { |
1587 | //if(frcount == 0) Console.WriteLine("Move " + m_primName + " VTyp " + m_vehicle.Type + | ||
1588 | // " usePID=" + m_usePID + " seHover=" + m_useHoverPID + " useAPID=" + m_useAPID); | ||
1564 | if (m_vehicle.Type != Vehicle.TYPE_NONE) | 1589 | if (m_vehicle.Type != Vehicle.TYPE_NONE) |
1565 | { | 1590 | { |
1566 | // 'VEHICLES' are dealt with in ODEDynamics.cs | 1591 | // 'VEHICLES' are dealt with in ODEDynamics.cs |
@@ -1568,7 +1593,6 @@ Console.WriteLine(" JointCreateFixed"); | |||
1568 | } | 1593 | } |
1569 | else | 1594 | else |
1570 | { | 1595 | { |
1571 | //Console.WriteLine("Move " + m_primName); | ||
1572 | if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009 | 1596 | if(!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009 |
1573 | // NON-'VEHICLES' are dealt with here | 1597 | // NON-'VEHICLES' are dealt with here |
1574 | if (d.BodyIsEnabled(Body) && !m_angularlock.ApproxEquals(Vector3.Zero, 0.003f)) | 1598 | if (d.BodyIsEnabled(Body) && !m_angularlock.ApproxEquals(Vector3.Zero, 0.003f)) |
@@ -1590,21 +1614,18 @@ Console.WriteLine(" JointCreateFixed"); | |||
1590 | //m_log.Info(m_collisionFlags.ToString()); | 1614 | //m_log.Info(m_collisionFlags.ToString()); |
1591 | 1615 | ||
1592 | 1616 | ||
1593 | //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle. | 1617 | //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 | 1618 | // m_buoyancy: (unlimited value) <0=Falls fast; 0=1g; 1=0g; >1 = floats up |
1596 | // gravityz multiplier = 1 - m_buoyancy | 1619 | // NB Prims in ODE are no subject to global gravity |
1597 | fz = _parent_scene.gravityz * (1.0f - m_buoyancy) * m_mass; | 1620 | fz = _parent_scene.gravityz * (1.0f - m_buoyancy) * m_mass; // force = acceleration * mass |
1598 | 1621 | ||
1599 | if (m_usePID) | 1622 | if (m_usePID) |
1600 | { | 1623 | { |
1601 | //Console.WriteLine("PID " + m_primName); | 1624 | //if(frcount == 0) Console.WriteLine("PID " + m_primName); |
1602 | // KF - this is for object move? eg. llSetPos() ? | 1625 | // KF - this is for object MoveToTarget. |
1626 | |||
1603 | //if (!d.BodyIsEnabled(Body)) | 1627 | //if (!d.BodyIsEnabled(Body)) |
1604 | //d.BodySetForce(Body, 0f, 0f, 0f); | 1628 | //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 | 1629 | ||
1609 | // no lock; for now it's only called from within Simulate() | 1630 | // no lock; for now it's only called from within Simulate() |
1610 | 1631 | ||
@@ -1739,7 +1760,7 @@ Console.WriteLine(" JointCreateFixed"); | |||
1739 | d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); | 1760 | d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight); |
1740 | d.BodySetLinearVel(Body, vel.X, vel.Y, 0); | 1761 | d.BodySetLinearVel(Body, vel.X, vel.Y, 0); |
1741 | d.BodyAddForce(Body, 0, 0, fz); | 1762 | d.BodyAddForce(Body, 0, 0, fz); |
1742 | return; | 1763 | //KF this prevents furthur motions return; |
1743 | } | 1764 | } |
1744 | else | 1765 | else |
1745 | { | 1766 | { |
@@ -1748,8 +1769,46 @@ Console.WriteLine(" JointCreateFixed"); | |||
1748 | // We're flying and colliding with something | 1769 | // We're flying and colliding with something |
1749 | fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); | 1770 | fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass); |
1750 | } | 1771 | } |
1751 | } | 1772 | } // end m_useHoverPID && !m_usePID |
1752 | 1773 | ||
1774 | if (m_useAPID) | ||
1775 | { | ||
1776 | // RotLookAt, apparently overrides all other rotation sources. Inputs: | ||
1777 | // Quaternion m_APIDTarget | ||
1778 | // float m_APIDStrength // From SL experiments, this is the time to get there | ||
1779 | // float m_APIDDamping // From SL experiments, this is damping, 1.0 = damped, 0.1 = wobbly | ||
1780 | // Also in SL the mass of the object has no effect on time to get there. | ||
1781 | // Factors: | ||
1782 | //if(frcount == 0) Console.WriteLine("APID "); | ||
1783 | // get present body rotation | ||
1784 | float limit = 1.0f; | ||
1785 | float scaler = 50f; // adjusts damping time | ||
1786 | float RLAservo = 0f; | ||
1787 | |||
1788 | d.Quaternion rot = d.BodyGetQuaternion(Body); | ||
1789 | Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); | ||
1790 | Quaternion rot_diff = Quaternion.Inverse(rotq) * m_APIDTarget; | ||
1791 | float diff_angle; | ||
1792 | Vector3 diff_axis; | ||
1793 | rot_diff.GetAxisAngle(out diff_axis, out diff_angle); | ||
1794 | diff_axis.Normalize(); | ||
1795 | if(diff_angle > 0.01f) // diff_angle is always +ve | ||
1796 | { | ||
1797 | // PhysicsVector rotforce = new PhysicsVector(diff_axis.X, diff_axis.Y, diff_axis.Z); | ||
1798 | Vector3 rotforce = new Vector3(diff_axis.X, diff_axis.Y, diff_axis.Z); | ||
1799 | rotforce = rotforce * rotq; | ||
1800 | if(diff_angle > limit) diff_angle = limit; // cap the rotate rate | ||
1801 | // RLAservo = timestep / m_APIDStrength * m_mass * scaler; | ||
1802 | // rotforce = rotforce * RLAservo * diff_angle ; | ||
1803 | // d.BodyAddRelTorque(Body, rotforce.X, rotforce.Y, rotforce.Z); | ||
1804 | RLAservo = timestep / m_APIDStrength * scaler; | ||
1805 | rotforce = rotforce * RLAservo * diff_angle ; | ||
1806 | d.BodySetAngularVel (Body, rotforce.X, rotforce.Y, rotforce.Z); | ||
1807 | //Console.WriteLine("axis= " + diff_axis + " angle= " + diff_angle + "servo= " + RLAservo); | ||
1808 | } | ||
1809 | //if(frcount == 0) Console.WriteLine("mass= " + m_mass + " servo= " + RLAservo + " angle= " + diff_angle); | ||
1810 | } // end m_useAPID | ||
1811 | |||
1753 | fx *= m_mass; | 1812 | fx *= m_mass; |
1754 | fy *= m_mass; | 1813 | fy *= m_mass; |
1755 | //fz *= m_mass; | 1814 | //fz *= m_mass; |
@@ -2793,6 +2852,12 @@ Console.WriteLine(" JointCreateFixed"); | |||
2793 | } | 2852 | } |
2794 | public override bool PIDActive { set { m_usePID = value; } } | 2853 | public override bool PIDActive { set { m_usePID = value; } } |
2795 | public override float PIDTau { set { m_PIDTau = value; } } | 2854 | public override float PIDTau { set { m_PIDTau = value; } } |
2855 | |||
2856 | // For RotLookAt | ||
2857 | public override Quaternion APIDTarget { set { m_APIDTarget = value; } } | ||
2858 | public override bool APIDActive { set { m_useAPID = value; } } | ||
2859 | public override float APIDStrength { set { m_APIDStrength = value; } } | ||
2860 | public override float APIDDamping { set { m_APIDDamping = value; } } | ||
2796 | 2861 | ||
2797 | public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } } | 2862 | public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } } |
2798 | public override bool PIDHoverActive { set { m_useHoverPID = value; } } | 2863 | public override bool PIDHoverActive { set { m_useHoverPID = value; } } |