diff options
author | Teravus Ovares | 2009-04-17 21:10:54 +0000 |
---|---|---|
committer | Teravus Ovares | 2009-04-17 21:10:54 +0000 |
commit | 07c113a766278b1b5c801c6735649ccc7a2dccfb (patch) | |
tree | eb797dbd295e41b0cfcbaaea5bfd83f90cb08ab2 /OpenSim/Region/Physics/OdePlugin | |
parent | add some stub config to OpenSim.ini.example for freeswitch. This needs (diff) | |
download | opensim-SC_OLD-07c113a766278b1b5c801c6735649ccc7a2dccfb.zip opensim-SC_OLD-07c113a766278b1b5c801c6735649ccc7a2dccfb.tar.gz opensim-SC_OLD-07c113a766278b1b5c801c6735649ccc7a2dccfb.tar.bz2 opensim-SC_OLD-07c113a766278b1b5c801c6735649ccc7a2dccfb.tar.xz |
* Add Implementation of Linear Motor and Linear friction from the LSL Vehicle API in Physics
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs | 82 |
1 files changed, 73 insertions, 9 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs index 12b623d..b61e1c5 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs | |||
@@ -54,7 +54,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
54 | private IntPtr m_body = IntPtr.Zero; | 54 | private IntPtr m_body = IntPtr.Zero; |
55 | private IntPtr m_jointGroup = IntPtr.Zero; | 55 | private IntPtr m_jointGroup = IntPtr.Zero; |
56 | private IntPtr m_aMotor = IntPtr.Zero; | 56 | private IntPtr m_aMotor = IntPtr.Zero; |
57 | private IntPtr m_lMotor = IntPtr.Zero; | 57 | private IntPtr m_lMotor1 = IntPtr.Zero; |
58 | private IntPtr m_lMotor2 = IntPtr.Zero; | ||
59 | private IntPtr m_lMotor3 = IntPtr.Zero; | ||
58 | 60 | ||
59 | // Vehicle properties | 61 | // Vehicle properties |
60 | private Quaternion m_referenceFrame = Quaternion.Identity; | 62 | private Quaternion m_referenceFrame = Quaternion.Identity; |
@@ -80,9 +82,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
80 | private float m_linearMotorTimescale = 0; | 82 | private float m_linearMotorTimescale = 0; |
81 | private float m_verticalAttractionEfficiency = 0; | 83 | private float m_verticalAttractionEfficiency = 0; |
82 | private float m_verticalAttractionTimescale = 0; | 84 | private float m_verticalAttractionTimescale = 0; |
83 | private Vector3 m_lastVector = Vector3.Zero; | 85 | private Vector3 m_lastLinearVelocityVector = Vector3.Zero; |
84 | private VehicleFlag m_flags = (VehicleFlag) 0; | 86 | private VehicleFlag m_flags = (VehicleFlag) 0; |
85 | 87 | ||
88 | private bool m_LinearMotorSetLastFrame = false; | ||
89 | |||
86 | 90 | ||
87 | 91 | ||
88 | 92 | ||
@@ -169,6 +173,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
169 | break; | 173 | break; |
170 | case Vehicle.LINEAR_MOTOR_DIRECTION: | 174 | case Vehicle.LINEAR_MOTOR_DIRECTION: |
171 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); | 175 | m_linearMotorDirection = new Vector3(pValue, pValue, pValue); |
176 | m_LinearMotorSetLastFrame = true; | ||
172 | break; | 177 | break; |
173 | case Vehicle.LINEAR_MOTOR_OFFSET: | 178 | case Vehicle.LINEAR_MOTOR_OFFSET: |
174 | m_linearMotorOffset = new Vector3(pValue, pValue, pValue); | 179 | m_linearMotorOffset = new Vector3(pValue, pValue, pValue); |
@@ -187,6 +192,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
187 | break; | 192 | break; |
188 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 193 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
189 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | 194 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
195 | m_LinearMotorSetLastFrame = true; | ||
190 | break; | 196 | break; |
191 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 197 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
192 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 198 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
@@ -247,6 +253,25 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
247 | 253 | ||
248 | m_body = pBody; | 254 | m_body = pBody; |
249 | m_parentScene = pParentScene; | 255 | m_parentScene = pParentScene; |
256 | if (m_jointGroup == IntPtr.Zero) | ||
257 | m_jointGroup = d.JointGroupCreate(3); | ||
258 | |||
259 | if (pBody != IntPtr.Zero) | ||
260 | { | ||
261 | |||
262 | if (m_lMotor1 == IntPtr.Zero) | ||
263 | { | ||
264 | d.BodySetAutoDisableFlag(Body, false); | ||
265 | m_lMotor1 = d.JointCreateLMotor(pParentScene.world, m_jointGroup); | ||
266 | d.JointSetLMotorNumAxes(m_lMotor1, 1); | ||
267 | d.JointAttach(m_lMotor1, Body, IntPtr.Zero); | ||
268 | } | ||
269 | |||
270 | Vector3 dirNorm = m_lastLinearVelocityVector; | ||
271 | dirNorm.Normalize(); | ||
272 | //d.JointSetLMotorAxis(m_lMotor1, 0, 1, dirNorm.X, dirNorm.Y, dirNorm.Z); | ||
273 | //d.JointSetLMotorParam(m_lMotor1, (int)dParam.Vel, m_lastLinearVelocityVector.Length()); | ||
274 | } | ||
250 | } | 275 | } |
251 | 276 | ||
252 | internal void Reset() | 277 | internal void Reset() |
@@ -439,15 +464,54 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
439 | private void LinearMotor(float pTimestep) | 464 | private void LinearMotor(float pTimestep) |
440 | { | 465 | { |
441 | 466 | ||
442 | /* | 467 | if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) |
443 | float decayval = (m_linearMotorDecayTimescale * pTimestep); | 468 | { |
444 | m_linearMotorDirection *= decayval; | 469 | Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep); |
445 | m_lastVector += m_linearMotorDirection | 470 | m_lastLinearVelocityVector += (addAmount*10); |
471 | |||
472 | // This will work temporarily, but we really need to compare speed on an axis | ||
473 | if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirection.X)) | ||
474 | m_lastLinearVelocityVector.X = m_linearMotorDirection.X; | ||
475 | if (Math.Abs(m_lastLinearVelocityVector.Y) > Math.Abs(m_linearMotorDirection.Y)) | ||
476 | m_lastLinearVelocityVector.Y = m_linearMotorDirection.Y; | ||
477 | if (Math.Abs(m_lastLinearVelocityVector.Z) > Math.Abs(m_linearMotorDirection.Z)) | ||
478 | m_lastLinearVelocityVector.Z = m_linearMotorDirection.Z; | ||
479 | //System.Console.WriteLine("add: " + addAmount); | ||
480 | |||
481 | m_linearMotorDirection -= (m_linearMotorDirection*new Vector3(1, 1, 1)/ | ||
482 | (m_linearMotorDecayTimescale/pTimestep)) * 0.10f; | ||
483 | //Console.WriteLine("actual: " + m_linearMotorDirection); | ||
484 | } | ||
485 | //System.Console.WriteLine(m_linearMotorDirection + " " + m_lastLinearVelocityVector); | ||
446 | 486 | ||
487 | SetMotorProperties(); | ||
447 | 488 | ||
448 | m_lin | 489 | Vector3 decayamount = new Vector3(1,1,1)/(m_linearFrictionTimescale/pTimestep); |
449 | m_lastVector | 490 | m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount; |
450 | * */ | 491 | |
492 | //m_linearMotorDirection *= decayamount; | ||
493 | |||
494 | } | ||
495 | |||
496 | private void SetMotorProperties() | ||
497 | { | ||
498 | Vector3 dirNorm = m_lastLinearVelocityVector; | ||
499 | dirNorm.Normalize(); | ||
500 | |||
501 | d.Mass objMass; | ||
502 | d.BodyGetMass(Body, out objMass); | ||
503 | d.Quaternion rot = d.BodyGetQuaternion(Body); | ||
504 | Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); | ||
505 | dirNorm *= rotq; | ||
506 | if (m_lMotor1 != IntPtr.Zero) | ||
507 | { | ||
508 | |||
509 | d.JointSetLMotorAxis(m_lMotor1, 0, 1, dirNorm.X, dirNorm.Y, dirNorm.Z); | ||
510 | d.JointSetLMotorParam(m_lMotor1, (int)dParam.Vel, m_linearMotorDirection.Length()); | ||
511 | |||
512 | d.JointSetLMotorParam(m_lMotor1, (int)dParam.FMax, 35f * objMass.mass); | ||
513 | } | ||
514 | |||
451 | } | 515 | } |
452 | } | 516 | } |
453 | } | 517 | } |