aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs')
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs80
1 files changed, 64 insertions, 16 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
index c9d0909..d0b4546 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEDynamics.cs
@@ -38,7 +38,7 @@
38 * settings use. 38 * settings use.
39 */ 39 */
40 40
41// Ubit 2012 41// Extensive change Ubit 2012
42 42
43using System; 43using System;
44using System.Collections.Generic; 44using System.Collections.Generic;
@@ -119,7 +119,15 @@ namespace OpenSim.Region.Physics.OdePlugin
119 // auxiliar 119 // auxiliar
120 private float m_lmEfect = 0; // current linear motor eficiency 120 private float m_lmEfect = 0; // current linear motor eficiency
121 private float m_amEfect = 0; // current angular motor eficiency 121 private float m_amEfect = 0; // current angular motor eficiency
122 private float m_ffactor = 1.0f;
122 123
124 public float FrictionFactor
125 {
126 get
127 {
128 return m_ffactor;
129 }
130 }
123 131
124 public ODEDynamics(OdePrim rootp) 132 public ODEDynamics(OdePrim rootp)
125 { 133 {
@@ -127,7 +135,6 @@ namespace OpenSim.Region.Physics.OdePlugin
127 _pParentScene = rootPrim._parent_scene; 135 _pParentScene = rootPrim._parent_scene;
128 } 136 }
129 137
130
131 public void DoSetVehicle(VehicleData vd) 138 public void DoSetVehicle(VehicleData vd)
132 { 139 {
133 140
@@ -152,6 +159,7 @@ namespace OpenSim.Region.Physics.OdePlugin
152 m_linearMotorTimescale = vd.m_linearMotorTimescale; 159 m_linearMotorTimescale = vd.m_linearMotorTimescale;
153 if (m_linearMotorTimescale < timestep) m_linearMotorTimescale = timestep; 160 if (m_linearMotorTimescale < timestep) m_linearMotorTimescale = timestep;
154 161
162
155 m_linearMotorOffset = vd.m_linearMotorOffset; 163 m_linearMotorOffset = vd.m_linearMotorOffset;
156 164
157 //Angular properties 165 //Angular properties
@@ -201,6 +209,7 @@ namespace OpenSim.Region.Physics.OdePlugin
201 209
202 m_lmEfect = 0; 210 m_lmEfect = 0;
203 m_amEfect = 0; 211 m_amEfect = 0;
212 m_ffactor = 1.0f;
204 } 213 }
205 214
206 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) 215 internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
@@ -318,6 +327,7 @@ namespace OpenSim.Region.Physics.OdePlugin
318 if (len > 30.0f) 327 if (len > 30.0f)
319 m_linearMotorDirection *= (30.0f / len); 328 m_linearMotorDirection *= (30.0f / len);
320 m_lmEfect = 1.0f; // turn it on 329 m_lmEfect = 1.0f; // turn it on
330 m_ffactor = 0.01f;
321 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body) 331 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body)
322 && !rootPrim.m_isSelected && !rootPrim.m_disabled) 332 && !rootPrim.m_isSelected && !rootPrim.m_disabled)
323 d.BodyEnable(rootPrim.Body); 333 d.BodyEnable(rootPrim.Body);
@@ -368,6 +378,7 @@ namespace OpenSim.Region.Physics.OdePlugin
368 if (len > 30.0f) 378 if (len > 30.0f)
369 m_linearMotorDirection *= (30.0f / len); 379 m_linearMotorDirection *= (30.0f / len);
370 m_lmEfect = 1.0f; // turn it on 380 m_lmEfect = 1.0f; // turn it on
381 m_ffactor = 0.01f;
371 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body) 382 if (rootPrim.Body != IntPtr.Zero && !d.BodyIsEnabled(rootPrim.Body)
372 && !rootPrim.m_isSelected && !rootPrim.m_disabled) 383 && !rootPrim.m_isSelected && !rootPrim.m_disabled)
373 d.BodyEnable(rootPrim.Body); 384 d.BodyEnable(rootPrim.Body);
@@ -414,6 +425,7 @@ namespace OpenSim.Region.Physics.OdePlugin
414 float invtimestep = _pParentScene.ODE_STEPSIZE; 425 float invtimestep = _pParentScene.ODE_STEPSIZE;
415 m_lmEfect = 0; 426 m_lmEfect = 0;
416 m_amEfect = 0; 427 m_amEfect = 0;
428 m_ffactor = 1f;
417 429
418 m_linearMotorDirection = Vector3.Zero; 430 m_linearMotorDirection = Vector3.Zero;
419 m_angularMotorDirection = Vector3.Zero; 431 m_angularMotorDirection = Vector3.Zero;
@@ -591,6 +603,7 @@ namespace OpenSim.Region.Physics.OdePlugin
591 { 603 {
592 m_lmEfect = 0; 604 m_lmEfect = 0;
593 m_amEfect = 0; 605 m_amEfect = 0;
606 m_ffactor = 1f;
594 } 607 }
595 608
596 public static Vector3 Xrot(Quaternion rot) 609 public static Vector3 Xrot(Quaternion rot)
@@ -614,6 +627,7 @@ namespace OpenSim.Region.Physics.OdePlugin
614 return vec; 627 return vec;
615 } 628 }
616 629
630 private const float pi = (float)Math.PI;
617 private const float halfpi = 0.5f * (float)Math.PI; 631 private const float halfpi = 0.5f * (float)Math.PI;
618 632
619 public static Vector3 ubitRot2Euler(Quaternion rot) 633 public static Vector3 ubitRot2Euler(Quaternion rot)
@@ -740,9 +754,14 @@ namespace OpenSim.Region.Physics.OdePlugin
740 force.Z += tmpV.Z; 754 force.Z += tmpV.Z;
741 } 755 }
742 m_lmEfect *= (1.0f - 1.0f / m_linearMotorDecayTimescale); 756 m_lmEfect *= (1.0f - 1.0f / m_linearMotorDecayTimescale);
757
758 m_ffactor = 0.01f + 1e-4f * curVel.LengthSquared();
743 } 759 }
744 else 760 else
761 {
745 m_lmEfect = 0; 762 m_lmEfect = 0;
763 m_ffactor = 1f;
764 }
746 765
747 // friction 766 // friction
748 if (curLocalVel.X != 0 || curLocalVel.Y != 0 || curLocalVel.Z != 0) 767 if (curLocalVel.X != 0 || curLocalVel.Y != 0 || curLocalVel.Z != 0)
@@ -884,35 +903,64 @@ namespace OpenSim.Region.Physics.OdePlugin
884 float ftmp = 1.0f / m_verticalAttractionTimescale / m_verticalAttractionTimescale / _pParentScene.ODE_STEPSIZE; 903 float ftmp = 1.0f / m_verticalAttractionTimescale / m_verticalAttractionTimescale / _pParentScene.ODE_STEPSIZE;
885 float ftmp2 = m_verticalAttractionEfficiency / _pParentScene.ODE_STEPSIZE; 904 float ftmp2 = m_verticalAttractionEfficiency / _pParentScene.ODE_STEPSIZE;
886 905
887 if (Math.Abs(roll) > 0.01) // roll 906 if (roll > halfpi)
907 roll = pi - roll;
908 else if (roll < -halfpi)
909 roll = -pi - roll;
910
911 float effroll = pitch / halfpi;
912 effroll *= effroll;
913 effroll = 1 - effroll;
914 effroll *= roll;
915
916 if (Math.Abs(effroll) > 0.01) // roll
888 { 917 {
889 torque.X -= -roll * ftmp + curLocalAngVel.X * ftmp2; 918 torque.X -= -effroll * ftmp + curLocalAngVel.X * ftmp2;
890 } 919 }
891 920
892 if (Math.Abs(pitch) > 0.01 && ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) == 0)) // pitch 921 if ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) == 0)
893 { 922 {
894 torque.Y -= -pitch * ftmp + curLocalAngVel.Y * ftmp2; 923 float effpitch = roll / halfpi;
924 effpitch *= effpitch;
925 effpitch = 1 - effpitch;
926 effpitch *= pitch;
927
928 if (Math.Abs(effpitch) > 0.01) // pitch
929 {
930 torque.Y -= -effpitch * ftmp + curLocalAngVel.Y * ftmp2;
931 }
895 } 932 }
896 933
897 if (m_bankingEfficiency != 0 && Math.Abs(roll) > 0.01) 934 if (m_bankingEfficiency != 0 && Math.Abs(effroll) > 0.01)
898 { 935 {
899 float broll = roll * m_bankingEfficiency; ; 936
937 float broll = effroll;
938/*
939 if (broll > halfpi)
940 broll = pi - broll;
941 else if (broll < -halfpi)
942 broll = -pi - broll;
943*/
944 broll *= m_bankingEfficiency;
900 if (m_bankingMix != 0) 945 if (m_bankingMix != 0)
901 { 946 {
902 float vfact = Math.Abs(curLocalVel.X) / 10.0f; 947 float vfact = Math.Abs(curLocalVel.X) / 10.0f;
903 if (vfact > 1.0f) vfact = 1.0f; 948 if (vfact > 1.0f) vfact = 1.0f;
949
904 if (curLocalVel.X >= 0) 950 if (curLocalVel.X >= 0)
905 broll *= ((1 - m_bankingMix) + vfact); 951 broll *= (1 + (vfact - 1) * m_bankingMix);
906 else 952 else
907 broll *= -((1 - m_bankingMix) + vfact); 953 broll *= -(1 + (vfact - 1) * m_bankingMix);
908 } 954 }
909 broll = (broll - curLocalAngVel.Z) / m_bankingTimescale;
910 // torque.Z += broll;
911
912 // make z rot be in world Z not local as seems to be in sl 955 // make z rot be in world Z not local as seems to be in sl
913 tmpV.X = 0; 956
914 tmpV.Y = 0; 957 broll = broll / m_bankingTimescale;
915 tmpV.Z = broll; 958
959 ftmp = -Math.Abs(m_bankingEfficiency) / m_bankingTimescale;
960
961 tmpV.X = ftmp * curAngVel.X;
962 tmpV.Y = ftmp * curAngVel.Y;
963 tmpV.Z = broll + ftmp * curAngVel.Z;
916 tmpV *= irotq; 964 tmpV *= irotq;
917 965
918 torque.X += tmpV.X; 966 torque.X += tmpV.X;