diff options
author | Teravus Ovares | 2009-04-17 04:34:52 +0000 |
---|---|---|
committer | Teravus Ovares | 2009-04-17 04:34:52 +0000 |
commit | 0d00a767bc9d1d6aae20c31131cd2e4e6ed62418 (patch) | |
tree | e72b735905d97e3bcf114bf3ef9febfb587e8b17 /OpenSim/Region/Physics/OdePlugin | |
parent | * minor: Eliminate redundant argument in PreloadUserCache (diff) | |
download | opensim-SC_OLD-0d00a767bc9d1d6aae20c31131cd2e4e6ed62418.zip opensim-SC_OLD-0d00a767bc9d1d6aae20c31131cd2e4e6ed62418.tar.gz opensim-SC_OLD-0d00a767bc9d1d6aae20c31131cd2e4e6ed62418.tar.bz2 opensim-SC_OLD-0d00a767bc9d1d6aae20c31131cd2e4e6ed62418.tar.xz |
* Commit a few fixes to the Vehicle settings
* Vertical Attractor servo
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 29 | ||||
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs | 51 |
2 files changed, 67 insertions, 13 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 391f644..adb559a 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | |||
@@ -66,6 +66,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
66 | private IntPtr Amotor = IntPtr.Zero; | 66 | private IntPtr Amotor = IntPtr.Zero; |
67 | 67 | ||
68 | private PhysicsVector m_PIDTarget = new PhysicsVector(0, 0, 0); | 68 | private PhysicsVector m_PIDTarget = new PhysicsVector(0, 0, 0); |
69 | private PhysicsVector m_taintPIDTarget = new PhysicsVector(0, 0, 0); | ||
69 | private float m_PIDTau = 0f; | 70 | private float m_PIDTau = 0f; |
70 | private float PID_D = 35f; | 71 | private float PID_D = 35f; |
71 | private float PID_G = 25f; | 72 | private float PID_G = 25f; |
@@ -908,6 +909,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
908 | 909 | ||
909 | if (!m_angularlock.IsIdentical(m_taintAngularLock,0)) | 910 | if (!m_angularlock.IsIdentical(m_taintAngularLock,0)) |
910 | changeAngularLock(timestep); | 911 | changeAngularLock(timestep); |
912 | |||
913 | |||
911 | } | 914 | } |
912 | else | 915 | else |
913 | { | 916 | { |
@@ -915,6 +918,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
915 | } | 918 | } |
916 | } | 919 | } |
917 | 920 | ||
921 | |||
918 | private void changeAngularLock(float timestep) | 922 | private void changeAngularLock(float timestep) |
919 | { | 923 | { |
920 | // do we have a Physical object? | 924 | // do we have a Physical object? |
@@ -1470,6 +1474,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1470 | } | 1474 | } |
1471 | } | 1475 | } |
1472 | d.BodyEnable(Body); | 1476 | d.BodyEnable(Body); |
1477 | if (m_vehicle.Type != Vehicle.TYPE_NONE) | ||
1478 | { | ||
1479 | m_vehicle.Enable(Body, _parent_scene); | ||
1480 | } | ||
1473 | } | 1481 | } |
1474 | else | 1482 | else |
1475 | { | 1483 | { |
@@ -1550,6 +1558,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1550 | 1558 | ||
1551 | if (m_usePID) | 1559 | if (m_usePID) |
1552 | { | 1560 | { |
1561 | |||
1553 | //if (!d.BodyIsEnabled(Body)) | 1562 | //if (!d.BodyIsEnabled(Body)) |
1554 | //d.BodySetForce(Body, 0f, 0f, 0f); | 1563 | //d.BodySetForce(Body, 0f, 0f, 0f); |
1555 | // If we're using the PID controller, then we have no gravity | 1564 | // If we're using the PID controller, then we have no gravity |
@@ -1737,6 +1746,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1737 | fy = nmin; | 1746 | fy = nmin; |
1738 | d.BodyAddForce(Body, fx, fy, fz); | 1747 | d.BodyAddForce(Body, fx, fy, fz); |
1739 | } | 1748 | } |
1749 | if (m_vehicle.Body == IntPtr.Zero && m_vehicle.Type != Vehicle.TYPE_NONE) | ||
1750 | m_vehicle.Enable(Body, _parent_scene); | ||
1740 | 1751 | ||
1741 | m_vehicle.Step(timestep); | 1752 | m_vehicle.Step(timestep); |
1742 | } | 1753 | } |
@@ -1747,6 +1758,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1747 | } | 1758 | } |
1748 | } | 1759 | } |
1749 | 1760 | ||
1761 | |||
1762 | |||
1750 | public void rotate(float timestep) | 1763 | public void rotate(float timestep) |
1751 | { | 1764 | { |
1752 | d.Quaternion myrot = new d.Quaternion(); | 1765 | d.Quaternion myrot = new d.Quaternion(); |
@@ -2701,8 +2714,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
2701 | set | 2714 | set |
2702 | { | 2715 | { |
2703 | if (PhysicsVector.isFinite(value)) | 2716 | if (PhysicsVector.isFinite(value)) |
2704 | m_PIDTarget = value; | 2717 | { |
2705 | else | 2718 | m_PIDTarget = value; |
2719 | } | ||
2720 | else | ||
2706 | m_log.Warn("[PHYSICS]: Got NaN PIDTarget from Scene on Object"); | 2721 | m_log.Warn("[PHYSICS]: Got NaN PIDTarget from Scene on Object"); |
2707 | } | 2722 | } |
2708 | } | 2723 | } |
@@ -3062,15 +3077,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
3062 | return det; | 3077 | return det; |
3063 | 3078 | ||
3064 | } | 3079 | } |
3065 | private static float Determinant(Matrix4 matrix) | 3080 | |
3066 | { | ||
3067 | float det = 0; | ||
3068 | |||
3069 | for (int j = 0; j < 4; j++) | ||
3070 | det += (matrix[0, j] * Determinant(Minor(matrix, 0, j)) * (int)System.Math.Pow(-1, 0 + j)); | ||
3071 | return det; | ||
3072 | } | ||
3073 | |||
3074 | private static void DMassCopy(ref d.Mass src, ref d.Mass dst) | 3081 | private static void DMassCopy(ref d.Mass src, ref d.Mass dst) |
3075 | { | 3082 | { |
3076 | dst.c.W = src.c.W; | 3083 | dst.c.W = src.c.W; |
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs index c4c3044..3a99b48 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs | |||
@@ -44,6 +44,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
44 | get { return m_type; } | 44 | get { return m_type; } |
45 | } | 45 | } |
46 | 46 | ||
47 | public IntPtr Body | ||
48 | { | ||
49 | get { return m_body; } | ||
50 | } | ||
51 | |||
47 | private Vehicle m_type = Vehicle.TYPE_NONE; | 52 | private Vehicle m_type = Vehicle.TYPE_NONE; |
48 | private OdeScene m_parentScene = null; | 53 | private OdeScene m_parentScene = null; |
49 | private IntPtr m_body = IntPtr.Zero; | 54 | private IntPtr m_body = IntPtr.Zero; |
@@ -75,6 +80,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
75 | private float m_linearMotorTimescale = 0; | 80 | private float m_linearMotorTimescale = 0; |
76 | private float m_verticalAttractionEfficiency = 0; | 81 | private float m_verticalAttractionEfficiency = 0; |
77 | private float m_verticalAttractionTimescale = 0; | 82 | private float m_verticalAttractionTimescale = 0; |
83 | private Vector3 m_lastVector = Vector3.Zero; | ||
78 | private VehicleFlag m_flags = (VehicleFlag) 0; | 84 | private VehicleFlag m_flags = (VehicleFlag) 0; |
79 | 85 | ||
80 | 86 | ||
@@ -222,8 +228,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
222 | 228 | ||
223 | internal void Enable(IntPtr pBody, OdeScene pParentScene) | 229 | internal void Enable(IntPtr pBody, OdeScene pParentScene) |
224 | { | 230 | { |
225 | if (pBody == IntPtr.Zero || m_type == Vehicle.TYPE_NONE) | 231 | if (m_type == Vehicle.TYPE_NONE) |
226 | return; | 232 | return; |
233 | |||
227 | m_body = pBody; | 234 | m_body = pBody; |
228 | m_parentScene = pParentScene; | 235 | m_parentScene = pParentScene; |
229 | } | 236 | } |
@@ -246,11 +253,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
246 | { | 253 | { |
247 | if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE) | 254 | if (m_body == IntPtr.Zero || m_type == Vehicle.TYPE_NONE) |
248 | return; | 255 | return; |
249 | 256 | VerticalAttractor(pTimestep); | |
257 | LinearMotor(pTimestep); | ||
250 | } | 258 | } |
251 | 259 | ||
252 | private void SetDefaultsForType(Vehicle pType) | 260 | private void SetDefaultsForType(Vehicle pType) |
253 | { | 261 | { |
262 | m_type = pType; | ||
254 | switch (pType) | 263 | switch (pType) |
255 | { | 264 | { |
256 | case Vehicle.TYPE_SLED: | 265 | case Vehicle.TYPE_SLED: |
@@ -388,5 +397,43 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
388 | 397 | ||
389 | } | 398 | } |
390 | } | 399 | } |
400 | |||
401 | private void VerticalAttractor(float pTimestep) | ||
402 | { | ||
403 | // The purpose of this routine here is to quickly stabilize the Body while it's popped up in the air. | ||
404 | // The amotor needs a few seconds to stabilize so without it, the avatar shoots up sky high when you | ||
405 | // change appearance and when you enter the simulator | ||
406 | // After this routine is done, the amotor stabilizes much quicker | ||
407 | d.Mass objMass; | ||
408 | d.BodyGetMass(Body, out objMass); | ||
409 | //d.BodyGetS | ||
410 | |||
411 | d.Vector3 feet; | ||
412 | d.Vector3 head; | ||
413 | d.BodyGetRelPointPos(m_body, 0.0f, 0.0f, -1.0f, out feet); | ||
414 | d.BodyGetRelPointPos(m_body, 0.0f, 0.0f, 1.0f, out head); | ||
415 | float posture = head.Z - feet.Z; | ||
416 | |||
417 | // restoring force proportional to lack of posture: | ||
418 | float servo = (2.5f - posture) * (objMass.mass * m_verticalAttractionEfficiency / (m_verticalAttractionTimescale * pTimestep)) * objMass.mass; | ||
419 | d.BodyAddForceAtRelPos(m_body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f); | ||
420 | d.BodyAddForceAtRelPos(m_body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); | ||
421 | //d.Matrix3 bodyrotation = d.BodyGetRotation(Body); | ||
422 | //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22); | ||
423 | } | ||
424 | |||
425 | private void LinearMotor(float pTimestep) | ||
426 | { | ||
427 | |||
428 | /* | ||
429 | float decayval = (m_linearMotorDecayTimescale * pTimestep); | ||
430 | m_linearMotorDirection *= decayval; | ||
431 | m_lastVector += m_linearMotorDirection | ||
432 | |||
433 | |||
434 | m_lin | ||
435 | m_lastVector | ||
436 | * */ | ||
437 | } | ||
391 | } | 438 | } |
392 | } | 439 | } |