aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRobert Adams2012-12-05 09:27:38 -0800
committerRobert Adams2012-12-06 09:30:28 -0800
commite599a8b2421ab51860c65e49bdfd38fa064fa9b8 (patch)
tree741515c9c443a5ef771dd645cfdd522d4369762e
parentfix openjpeg on 64 bit OSX we were pointing to a file taht did not (diff)
downloadopensim-SC-e599a8b2421ab51860c65e49bdfd38fa064fa9b8.zip
opensim-SC-e599a8b2421ab51860c65e49bdfd38fa064fa9b8.tar.gz
opensim-SC-e599a8b2421ab51860c65e49bdfd38fa064fa9b8.tar.bz2
opensim-SC-e599a8b2421ab51860c65e49bdfd38fa064fa9b8.tar.xz
BulletSim: Vehicle angular vertical attraction works. Other vehicle angular forces commented out for the moment for debugging.
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs55
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs3
2 files changed, 38 insertions, 20 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
index be8a502..a83d966 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs
@@ -620,11 +620,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin
620 private Vector3? m_knownVelocity; 620 private Vector3? m_knownVelocity;
621 private Quaternion? m_knownOrientation; 621 private Quaternion? m_knownOrientation;
622 private Vector3? m_knownRotationalVelocity; 622 private Vector3? m_knownRotationalVelocity;
623 private Vector3? m_knownRotationalForce;
623 624
624 private const int m_knownChangedPosition = 1 << 0; 625 private const int m_knownChangedPosition = 1 << 0;
625 private const int m_knownChangedVelocity = 1 << 1; 626 private const int m_knownChangedVelocity = 1 << 1;
626 private const int m_knownChangedOrientation = 1 << 2; 627 private const int m_knownChangedOrientation = 1 << 2;
627 private const int m_knownChangedRotationalVelocity = 1 << 3; 628 private const int m_knownChangedRotationalVelocity = 1 << 3;
629 private const int m_knownChangedRotationalForce = 1 << 4;
628 630
629 private void ForgetKnownVehicleProperties() 631 private void ForgetKnownVehicleProperties()
630 { 632 {
@@ -634,6 +636,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
634 m_knownVelocity = null; 636 m_knownVelocity = null;
635 m_knownOrientation = null; 637 m_knownOrientation = null;
636 m_knownRotationalVelocity = null; 638 m_knownRotationalVelocity = null;
639 m_knownRotationalForce = null;
637 m_knownChanged = 0; 640 m_knownChanged = 0;
638 } 641 }
639 private void PushKnownChanged() 642 private void PushKnownChanged()
@@ -645,12 +648,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin
645 if ((m_knownChanged & m_knownChangedOrientation) != 0) 648 if ((m_knownChanged & m_knownChangedOrientation) != 0)
646 Prim.ForceOrientation = VehicleOrientation; 649 Prim.ForceOrientation = VehicleOrientation;
647 if ((m_knownChanged & m_knownChangedVelocity) != 0) 650 if ((m_knownChanged & m_knownChangedVelocity) != 0)
651 {
648 Prim.ForceVelocity = VehicleVelocity; 652 Prim.ForceVelocity = VehicleVelocity;
653 BulletSimAPI.SetInterpolationLinearVelocity2(Prim.PhysBody.ptr, VehicleVelocity);
654 }
649 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0) 655 if ((m_knownChanged & m_knownChangedRotationalVelocity) != 0)
650 { 656 {
651 Prim.ForceRotationalVelocity = VehicleRotationalVelocity; 657 Prim.ForceRotationalVelocity = VehicleRotationalVelocity;
658 // Fake out Bullet by making it think the velocity is the same as last time.
652 BulletSimAPI.SetInterpolationAngularVelocity2(Prim.PhysBody.ptr, VehicleRotationalVelocity); 659 BulletSimAPI.SetInterpolationAngularVelocity2(Prim.PhysBody.ptr, VehicleRotationalVelocity);
653 } 660 }
661 if ((m_knownChanged & m_knownChangedRotationalForce) != 0)
662 Prim.AddAngularForce((Vector3)m_knownRotationalForce, false, true);
663
654 // If we set one of the values (ie, the physics engine didn't do it) we must force 664 // If we set one of the values (ie, the physics engine didn't do it) we must force
655 // an UpdateProperties event to send the changes up to the simulator. 665 // an UpdateProperties event to send the changes up to the simulator.
656 BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr); 666 BulletSimAPI.PushUpdate2(Prim.PhysBody.ptr);
@@ -734,6 +744,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
734 m_knownChanged |= m_knownChangedRotationalVelocity; 744 m_knownChanged |= m_knownChangedRotationalVelocity;
735 } 745 }
736 } 746 }
747 private void VehicleAddAngularForce(Vector3 aForce)
748 {
749 m_knownRotationalForce += aForce;
750 m_knownChanged |= m_knownChangedRotationalForce;
751 }
737 #endregion // Known vehicle value functions 752 #endregion // Known vehicle value functions
738 753
739 // One step of the vehicle properties for the next 'pTimestep' seconds. 754 // One step of the vehicle properties for the next 'pTimestep' seconds.
@@ -1013,11 +1028,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1013 + bankingContribution; 1028 + bankingContribution;
1014 1029
1015 // ================================================================== 1030 // ==================================================================
1016 // The correction is applied to the current orientation. 1031 // Apply the correction velocity.
1032 // TODO: Should this be applied as an angular force (torque)?
1017 if (!m_lastAngularCorrection.ApproxEquals(Vector3.Zero, 0.01f)) 1033 if (!m_lastAngularCorrection.ApproxEquals(Vector3.Zero, 0.01f))
1018 { 1034 {
1019 Vector3 scaledCorrection = m_lastAngularCorrection * pTimestep; 1035 Vector3 scaledCorrection = m_lastAngularCorrection * pTimestep;
1020
1021 VehicleRotationalVelocity = scaledCorrection; 1036 VehicleRotationalVelocity = scaledCorrection;
1022 1037
1023 VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5},scaledCorr={6}", 1038 VDetailLog("{0}, MoveAngular,done,nonZero,angMotorContrib={1},vertAttrContrib={2},bankContrib={3},deflectContrib={4},totalContrib={5},scaledCorr={6}",
@@ -1029,7 +1044,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1029 } 1044 }
1030 else 1045 else
1031 { 1046 {
1032 // The vehicle is not adding anything velocity wise. 1047 // The vehicle is not adding anything angular wise.
1033 VehicleRotationalVelocity = Vector3.Zero; 1048 VehicleRotationalVelocity = Vector3.Zero;
1034 VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID); 1049 VDetailLog("{0}, MoveAngular,done,zero", Prim.LocalID);
1035 } 1050 }
@@ -1060,8 +1075,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1060 torqueFromOffset.Y = 0; 1075 torqueFromOffset.Y = 0;
1061 if (float.IsNaN(torqueFromOffset.Z)) 1076 if (float.IsNaN(torqueFromOffset.Z))
1062 torqueFromOffset.Z = 0; 1077 torqueFromOffset.Z = 0;
1063 torqueFromOffset *= m_vehicleMass; 1078
1064 Prim.ApplyTorqueImpulse(torqueFromOffset, true); 1079 VehicleAddAngularForce(torqueFromOffset * m_vehicleMass);
1065 VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset); 1080 VDetailLog("{0}, BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset);
1066 } 1081 }
1067 1082
@@ -1097,23 +1112,21 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1097 ret.Y = - verticalError.X; 1112 ret.Y = - verticalError.X;
1098 ret.Z = 0f; 1113 ret.Z = 0f;
1099 1114
1100 // scale by the time scale and timestep 1115 // Scale the correction force by how far we're off from vertical.
1116 // Z error of one says little error. As Z gets smaller, the vehicle is leaning farther over.
1117 // float clampedZError = ClampInRange(0.1f, Math.Abs(verticalError.Z), 1f);
1118 float clampedSqrZError = ClampInRange(0.01f, verticalError.Z * verticalError.Z, 1f);
1119 // float vertForce = 1f / clampedSqrZError * m_verticalAttractionEfficiency;
1120 float vertForce = 1f / clampedSqrZError;
1121
1122 ret *= vertForce;
1123
1124 // Correction happens over a number of seconds.
1101 Vector3 unscaledContrib = ret; 1125 Vector3 unscaledContrib = ret;
1102 ret /= m_verticalAttractionTimescale; 1126 ret /= m_verticalAttractionTimescale;
1103 // This returns the angular correction desired. Timestep is added later. 1127
1104 // ret *= pTimestep; 1128 VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},vertForce={3},eff={4},vertAttr={5}",
1105 1129 Prim.LocalID, verticalError, unscaledContrib, vertForce, m_verticalAttractionEfficiency, ret);
1106 // apply efficiency
1107 Vector3 preEfficiencyContrib = ret;
1108 // TODO: implement efficiency.
1109 // Effenciency squared seems to give a more realistic effect
1110 float efficencySquared = m_verticalAttractionEfficiency * m_verticalAttractionEfficiency;
1111 // ret *= efficencySquared;
1112
1113 VDetailLog("{0}, MoveAngular,verticalAttraction,,verticalError={1},unscaled={2},preEff={3},eff={4},effSq={5},vertAttr={6}",
1114 Prim.LocalID, verticalError, unscaledContrib, preEfficiencyContrib,
1115 m_verticalAttractionEfficiency, efficencySquared,
1116 ret);
1117 } 1130 }
1118 return ret; 1131 return ret;
1119 } 1132 }
@@ -1123,6 +1136,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1123 public Vector3 ComputeAngularDeflection() 1136 public Vector3 ComputeAngularDeflection()
1124 { 1137 {
1125 Vector3 ret = Vector3.Zero; 1138 Vector3 ret = Vector3.Zero;
1139 return ret; // DEBUG DEBUG DEBUG debug the other contributors first
1126 1140
1127 if (m_angularDeflectionEfficiency != 0) 1141 if (m_angularDeflectionEfficiency != 0)
1128 { 1142 {
@@ -1151,6 +1165,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
1151 { 1165 {
1152 Vector3 ret = Vector3.Zero; 1166 Vector3 ret = Vector3.Zero;
1153 Vector3 computedBanking = Vector3.Zero; 1167 Vector3 computedBanking = Vector3.Zero;
1168 return ret; // DEBUG DEBUG DEBUG debug the other contributors first
1154 1169
1155 if (m_bankingEfficiency != 0) 1170 if (m_bankingEfficiency != 0)
1156 { 1171 {
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index ea1f71a..e392078 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -1010,6 +1010,9 @@ public sealed class BSPrim : BSPhysObject
1010 }); 1010 });
1011 } 1011 }
1012 // A torque impulse. 1012 // A torque impulse.
1013 // ApplyTorqueImpulse adds torque directly to the angularVelocity.
1014 // AddAngularForce accumulates the force and applied it to the angular velocity all at once.
1015 // Computed as: angularVelocity += impulse * inertia;
1013 public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime) 1016 public void ApplyTorqueImpulse(OMV.Vector3 impulse, bool inTaintTime)
1014 { 1017 {
1015 OMV.Vector3 applyImpulse = impulse; 1018 OMV.Vector3 applyImpulse = impulse;