aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorTeravus Ovares2009-04-19 08:12:10 +0000
committerTeravus Ovares2009-04-19 08:12:10 +0000
commit03901c8c0dc537aca9bfbdcd45dac65891c88b4b (patch)
treee3a33a9431977ad7a1bd3876dcfe77a045a3dec3 /OpenSim/Region
parentAdded a "force_simple_prim_meshing" option to the ODE settings in OpenSim.ini... (diff)
downloadopensim-SC-03901c8c0dc537aca9bfbdcd45dac65891c88b4b.zip
opensim-SC-03901c8c0dc537aca9bfbdcd45dac65891c88b4b.tar.gz
opensim-SC-03901c8c0dc537aca9bfbdcd45dac65891c88b4b.tar.bz2
opensim-SC-03901c8c0dc537aca9bfbdcd45dac65891c88b4b.tar.xz
* Rudimentary angular motor implementation for the LSL Vehicle API
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs6
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs86
2 files changed, 84 insertions, 8 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index dae19c3..ed1366c 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -52,8 +52,12 @@ namespace OpenSim.Region.Physics.OdePlugin
52 StopCFM = 8, 52 StopCFM = 8,
53 LoStop2 = 256, 53 LoStop2 = 256,
54 HiStop2 = 257, 54 HiStop2 = 257,
55 Vel2 = 258,
56 FMax2 = 259,
55 LoStop3 = 512, 57 LoStop3 = 512,
56 HiStop3 = 513 58 HiStop3 = 513,
59 Vel3 = 514,
60 FMax3 = 515
57 } 61 }
58 public class OdeCharacter : PhysicsActor 62 public class OdeCharacter : PhysicsActor
59 { 63 {
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs
index 04de9a7..81c41ad 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEVehicleSettings.cs
@@ -62,6 +62,7 @@ namespace OpenSim.Region.Physics.OdePlugin
62 private Quaternion m_referenceFrame = Quaternion.Identity; 62 private Quaternion m_referenceFrame = Quaternion.Identity;
63 private Vector3 m_angularFrictionTimescale = Vector3.Zero; 63 private Vector3 m_angularFrictionTimescale = Vector3.Zero;
64 private Vector3 m_angularMotorDirection = Vector3.Zero; 64 private Vector3 m_angularMotorDirection = Vector3.Zero;
65 private Vector3 m_angularMotorDirectionLASTSET = Vector3.Zero;
65 private Vector3 m_linearFrictionTimescale = Vector3.Zero; 66 private Vector3 m_linearFrictionTimescale = Vector3.Zero;
66 private Vector3 m_linearMotorDirection = Vector3.Zero; 67 private Vector3 m_linearMotorDirection = Vector3.Zero;
67 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; 68 private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero;
@@ -84,6 +85,7 @@ namespace OpenSim.Region.Physics.OdePlugin
84 private float m_verticalAttractionEfficiency = 0; 85 private float m_verticalAttractionEfficiency = 0;
85 private float m_verticalAttractionTimescale = 0; 86 private float m_verticalAttractionTimescale = 0;
86 private Vector3 m_lastLinearVelocityVector = Vector3.Zero; 87 private Vector3 m_lastLinearVelocityVector = Vector3.Zero;
88 private Vector3 m_lastAngularVelocityVector = Vector3.Zero;
87 private VehicleFlag m_flags = (VehicleFlag) 0; 89 private VehicleFlag m_flags = (VehicleFlag) 0;
88 90
89 private bool m_LinearMotorSetLastFrame = false; 91 private bool m_LinearMotorSetLastFrame = false;
@@ -168,6 +170,7 @@ namespace OpenSim.Region.Physics.OdePlugin
168 break; 170 break;
169 case Vehicle.ANGULAR_MOTOR_DIRECTION: 171 case Vehicle.ANGULAR_MOTOR_DIRECTION:
170 m_angularMotorDirection = new Vector3(pValue, pValue, pValue); 172 m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
173 m_angularMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue);
171 break; 174 break;
172 case Vehicle.LINEAR_FRICTION_TIMESCALE: 175 case Vehicle.LINEAR_FRICTION_TIMESCALE:
173 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); 176 m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
@@ -193,7 +196,7 @@ namespace OpenSim.Region.Physics.OdePlugin
193 break; 196 break;
194 case Vehicle.ANGULAR_MOTOR_DIRECTION: 197 case Vehicle.ANGULAR_MOTOR_DIRECTION:
195 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); 198 m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
196 m_LinearMotorSetLastFrame = true; 199 m_angularMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z);
197 break; 200 break;
198 case Vehicle.LINEAR_FRICTION_TIMESCALE: 201 case Vehicle.LINEAR_FRICTION_TIMESCALE:
199 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); 202 m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
@@ -269,10 +272,12 @@ namespace OpenSim.Region.Physics.OdePlugin
269 d.JointAttach(m_lMotor1, Body, IntPtr.Zero); 272 d.JointAttach(m_lMotor1, Body, IntPtr.Zero);
270 } 273 }
271 274
272 Vector3 dirNorm = m_lastLinearVelocityVector; 275 if (m_aMotor == IntPtr.Zero)
273 dirNorm.Normalize(); 276 {
274 //d.JointSetLMotorAxis(m_lMotor1, 0, 1, dirNorm.X, dirNorm.Y, dirNorm.Z); 277 m_aMotor = d.JointCreateAMotor(pParentScene.world, m_jointGroup);
275 //d.JointSetLMotorParam(m_lMotor1, (int)dParam.Vel, m_lastLinearVelocityVector.Length()); 278 d.JointSetAMotorNumAxes(m_aMotor, 3);
279 d.JointAttach(m_aMotor, Body, IntPtr.Zero);
280 }
276 } 281 }
277 } 282 }
278 283
@@ -296,6 +301,7 @@ namespace OpenSim.Region.Physics.OdePlugin
296 return; 301 return;
297 VerticalAttractor(pTimestep); 302 VerticalAttractor(pTimestep);
298 LinearMotor(pTimestep); 303 LinearMotor(pTimestep);
304 AngularMotor(pTimestep);
299 } 305 }
300 306
301 private void SetDefaultsForType(Vehicle pType) 307 private void SetDefaultsForType(Vehicle pType)
@@ -490,7 +496,7 @@ namespace OpenSim.Region.Physics.OdePlugin
490 496
491 //System.Console.WriteLine(m_linearMotorDirection + " " + m_lastLinearVelocityVector); 497 //System.Console.WriteLine(m_linearMotorDirection + " " + m_lastLinearVelocityVector);
492 498
493 SetMotorProperties(); 499 SetLinearMotorProperties();
494 500
495 Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep); 501 Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep);
496 m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount; 502 m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount;
@@ -499,7 +505,7 @@ namespace OpenSim.Region.Physics.OdePlugin
499 505
500 } 506 }
501 507
502 private void SetMotorProperties() 508 private void SetLinearMotorProperties()
503 { 509 {
504 Vector3 dirNorm = m_lastLinearVelocityVector; 510 Vector3 dirNorm = m_lastLinearVelocityVector;
505 dirNorm.Normalize(); 511 dirNorm.Normalize();
@@ -519,5 +525,71 @@ namespace OpenSim.Region.Physics.OdePlugin
519 } 525 }
520 526
521 } 527 }
528
529 private void AngularMotor(float pTimestep)
530 {
531 if (!m_angularMotorDirection.ApproxEquals(Vector3.Zero, 0.01f))
532 {
533
534 Vector3 addAmount = m_angularMotorDirection / (m_angularMotorTimescale / pTimestep);
535 m_lastAngularVelocityVector += (addAmount * 10);
536
537 // This will work temporarily, but we really need to compare speed on an axis
538 if (Math.Abs(m_lastAngularVelocityVector.X) > Math.Abs(m_angularMotorDirectionLASTSET.X))
539 m_lastAngularVelocityVector.X = m_angularMotorDirectionLASTSET.X;
540 if (Math.Abs(m_lastAngularVelocityVector.Y) > Math.Abs(m_angularMotorDirectionLASTSET.Y))
541 m_lastAngularVelocityVector.Y = m_angularMotorDirectionLASTSET.Y;
542 if (Math.Abs(m_lastAngularVelocityVector.Z) > Math.Abs(m_angularMotorDirectionLASTSET.Z))
543 m_lastAngularVelocityVector.Z = m_angularMotorDirectionLASTSET.Z;
544 //Console.WriteLine("add: " + addAmount);
545
546 Vector3 decayfraction = ((Vector3.One / (m_angularMotorDecayTimescale / pTimestep)));
547 //Console.WriteLine("decay: " + decayfraction);
548
549 m_angularMotorDirection -= m_angularMotorDirection * decayfraction;
550 //Console.WriteLine("actual: " + m_linearMotorDirection);
551 }
552
553 //System.Console.WriteLine(m_linearMotorDirection + " " + m_lastLinearVelocityVector);
554
555 SetAngularMotorProperties();
556
557 Vector3 decayamount = Vector3.One / (m_angularFrictionTimescale / pTimestep);
558 m_lastAngularVelocityVector -= m_lastAngularVelocityVector * decayamount;
559
560 //m_linearMotorDirection *= decayamount;
561
562 }
563 private void SetAngularMotorProperties()
564 {
565
566
567
568 d.Mass objMass;
569 d.BodyGetMass(Body, out objMass);
570 d.Quaternion rot = d.BodyGetQuaternion(Body);
571 Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W);
572 Vector3 axis0 = Vector3.UnitX;
573 Vector3 axis1 = Vector3.UnitY;
574 Vector3 axis2 = Vector3.UnitZ;
575 axis0 *= rotq;
576 axis1 *= rotq;
577 axis2 *= rotq;
578
579
580 if (m_aMotor != IntPtr.Zero)
581 {
582 d.JointSetAMotorAxis(m_aMotor, 0, 1, axis0.X, axis0.Y, axis0.Z);
583 d.JointSetAMotorAxis(m_aMotor, 1, 1, axis1.X, axis1.Y, axis1.Z);
584 d.JointSetAMotorAxis(m_aMotor, 2, 1, axis2.X, axis2.Y, axis2.Z);
585 d.JointSetAMotorParam(m_aMotor, (int)dParam.FMax, 30*objMass.mass);
586 d.JointSetAMotorParam(m_aMotor, (int)dParam.FMax2, 30*objMass.mass);
587 d.JointSetAMotorParam(m_aMotor, (int)dParam.FMax3, 30 * objMass.mass);
588 d.JointSetAMotorParam(m_aMotor, (int)dParam.Vel, m_lastAngularVelocityVector.X);
589 d.JointSetAMotorParam(m_aMotor, (int)dParam.Vel2, m_lastAngularVelocityVector.Y);
590 d.JointSetAMotorParam(m_aMotor, (int)dParam.Vel3, m_lastAngularVelocityVector.Z);
591
592 }
593 }
522 } 594 }
523} 595}