diff options
author | Robert Adams | 2013-06-30 13:39:58 -0700 |
---|---|---|
committer | Robert Adams | 2013-06-30 17:07:49 -0700 |
commit | 23516717e48095011c1c06d64785ef7d91754ff2 (patch) | |
tree | 706e3cb958e94d0989d2546ef07a463dc7858ff9 /OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs | |
parent | BulletSim: add inTaintTime parameter to collision cache clear function. (diff) | |
download | opensim-SC_OLD-23516717e48095011c1c06d64785ef7d91754ff2.zip opensim-SC_OLD-23516717e48095011c1c06d64785ef7d91754ff2.tar.gz opensim-SC_OLD-23516717e48095011c1c06d64785ef7d91754ff2.tar.bz2 opensim-SC_OLD-23516717e48095011c1c06d64785ef7d91754ff2.tar.xz |
BulletSim: a better version of llMoveToTarget that doesn't go crazy.
There is still some overshoot but mostly fixes Mantis 6693.
Fix bug where moveToTarget was active for non-physical objects
and while selected.
Fix bug where move target was not getting changed if the script
changed the target during a move.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs | 80 |
1 files changed, 71 insertions, 9 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs index 75ff24e..bdf4bc0 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs | |||
@@ -50,7 +50,8 @@ public class BSActorMoveToTarget : BSActor | |||
50 | // BSActor.isActive | 50 | // BSActor.isActive |
51 | public override bool isActive | 51 | public override bool isActive |
52 | { | 52 | { |
53 | get { return Enabled; } | 53 | // MoveToTarget only works on physical prims |
54 | get { return Enabled && m_controllingPrim.IsPhysicallyActive; } | ||
54 | } | 55 | } |
55 | 56 | ||
56 | // Release any connections and resources used by the actor. | 57 | // Release any connections and resources used by the actor. |
@@ -102,16 +103,28 @@ public class BSActorMoveToTarget : BSActor | |||
102 | // We're taking over after this. | 103 | // We're taking over after this. |
103 | m_controllingPrim.ZeroMotion(true); | 104 | m_controllingPrim.ZeroMotion(true); |
104 | 105 | ||
105 | m_targetMotor = new BSVMotor("BSActorMoveToTargget.Activate", | 106 | /* Someday use the PID controller |
106 | m_controllingPrim.MoveToTargetTau, // timeScale | 107 | m_targetMotor = new BSPIDVMotor("BSActorMoveToTarget-" + m_controllingPrim.LocalID.ToString()); |
107 | BSMotor.Infinite, // decay time scale | 108 | m_targetMotor.TimeScale = m_controllingPrim.MoveToTargetTau; |
108 | 1f // efficiency | 109 | m_targetMotor.Efficiency = 1f; |
110 | */ | ||
111 | m_targetMotor = new BSVMotor("BSActorMoveToTarget-" + m_controllingPrim.LocalID.ToString(), | ||
112 | m_controllingPrim.MoveToTargetTau, // timeScale | ||
113 | BSMotor.Infinite, // decay time scale | ||
114 | 1f // efficiency | ||
109 | ); | 115 | ); |
110 | m_targetMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG so motor will output detail log messages. | 116 | m_targetMotor.PhysicsScene = m_physicsScene; // DEBUG DEBUG so motor will output detail log messages. |
111 | m_targetMotor.SetTarget(m_controllingPrim.MoveToTargetTarget); | 117 | m_targetMotor.SetTarget(m_controllingPrim.MoveToTargetTarget); |
112 | m_targetMotor.SetCurrent(m_controllingPrim.RawPosition); | 118 | m_targetMotor.SetCurrent(m_controllingPrim.RawPosition); |
113 | 119 | ||
114 | m_physicsScene.BeforeStep += Mover; | 120 | // m_physicsScene.BeforeStep += Mover; |
121 | m_physicsScene.BeforeStep += Mover2; | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | // If already allocated, make sure the target and other paramters are current | ||
126 | m_targetMotor.SetTarget(m_controllingPrim.MoveToTargetTarget); | ||
127 | m_targetMotor.SetCurrent(m_controllingPrim.RawPosition); | ||
115 | } | 128 | } |
116 | } | 129 | } |
117 | 130 | ||
@@ -119,12 +132,16 @@ public class BSActorMoveToTarget : BSActor | |||
119 | { | 132 | { |
120 | if (m_targetMotor != null) | 133 | if (m_targetMotor != null) |
121 | { | 134 | { |
122 | m_physicsScene.BeforeStep -= Mover; | 135 | // m_physicsScene.BeforeStep -= Mover; |
136 | m_physicsScene.BeforeStep -= Mover2; | ||
123 | m_targetMotor = null; | 137 | m_targetMotor = null; |
124 | } | 138 | } |
125 | } | 139 | } |
126 | 140 | ||
127 | // Called just before the simulation step. Update the vertical position for hoverness. | 141 | // Origional mover that set the objects position to move to the target. |
142 | // The problem was that gravity would keep trying to push the object down so | ||
143 | // the overall downward velocity would increase to infinity. | ||
144 | // Called just before the simulation step. | ||
128 | private void Mover(float timeStep) | 145 | private void Mover(float timeStep) |
129 | { | 146 | { |
130 | // Don't do hovering while the object is selected. | 147 | // Don't do hovering while the object is selected. |
@@ -142,6 +159,7 @@ public class BSActorMoveToTarget : BSActor | |||
142 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover,zeroMovement,movePos={1},pos={2},mass={3}", | 159 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover,zeroMovement,movePos={1},pos={2},mass={3}", |
143 | m_controllingPrim.LocalID, movePosition, m_controllingPrim.RawPosition, m_controllingPrim.Mass); | 160 | m_controllingPrim.LocalID, movePosition, m_controllingPrim.RawPosition, m_controllingPrim.Mass); |
144 | m_controllingPrim.ForcePosition = m_targetMotor.TargetValue; | 161 | m_controllingPrim.ForcePosition = m_targetMotor.TargetValue; |
162 | m_controllingPrim.ForceVelocity = OMV.Vector3.Zero; | ||
145 | // Setting the position does not cause the physics engine to generate a property update. Force it. | 163 | // Setting the position does not cause the physics engine to generate a property update. Force it. |
146 | m_physicsScene.PE.PushUpdate(m_controllingPrim.PhysBody); | 164 | m_physicsScene.PE.PushUpdate(m_controllingPrim.PhysBody); |
147 | } | 165 | } |
@@ -151,7 +169,51 @@ public class BSActorMoveToTarget : BSActor | |||
151 | // Setting the position does not cause the physics engine to generate a property update. Force it. | 169 | // Setting the position does not cause the physics engine to generate a property update. Force it. |
152 | m_physicsScene.PE.PushUpdate(m_controllingPrim.PhysBody); | 170 | m_physicsScene.PE.PushUpdate(m_controllingPrim.PhysBody); |
153 | } | 171 | } |
154 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover,move,fromPos={1},movePos={2}", m_controllingPrim.LocalID, origPosition, movePosition); | 172 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover,move,fromPos={1},movePos={2}", |
173 | m_controllingPrim.LocalID, origPosition, movePosition); | ||
174 | } | ||
175 | |||
176 | // Version of mover that applies forces to move the physical object to the target. | ||
177 | // Also overcomes gravity so the object doesn't just drop to the ground. | ||
178 | // Called just before the simulation step. | ||
179 | private void Mover2(float timeStep) | ||
180 | { | ||
181 | // Don't do hovering while the object is selected. | ||
182 | if (!isActive) | ||
183 | return; | ||
184 | |||
185 | OMV.Vector3 origPosition = m_controllingPrim.RawPosition; // DEBUG DEBUG (for printout below) | ||
186 | OMV.Vector3 addedForce = OMV.Vector3.Zero; | ||
187 | |||
188 | // CorrectionVector is the movement vector required this step | ||
189 | OMV.Vector3 correctionVector = m_targetMotor.Step(timeStep, m_controllingPrim.RawPosition); | ||
190 | |||
191 | // If we are very close to our target, turn off the movement motor. | ||
192 | if (m_targetMotor.ErrorIsZero()) | ||
193 | { | ||
194 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover3,zeroMovement,pos={1},mass={2}", | ||
195 | m_controllingPrim.LocalID, m_controllingPrim.RawPosition, m_controllingPrim.Mass); | ||
196 | m_controllingPrim.ForcePosition = m_targetMotor.TargetValue; | ||
197 | m_controllingPrim.ForceVelocity = OMV.Vector3.Zero; | ||
198 | // Setting the position does not cause the physics engine to generate a property update. Force it. | ||
199 | m_physicsScene.PE.PushUpdate(m_controllingPrim.PhysBody); | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | // First force to move us there -- the motor return a timestep scaled value. | ||
204 | addedForce = correctionVector / timeStep; | ||
205 | // Remove the existing velocity (only the moveToTarget force counts) | ||
206 | addedForce -= m_controllingPrim.RawVelocity; | ||
207 | // Overcome gravity. | ||
208 | addedForce -= m_controllingPrim.Gravity; | ||
209 | |||
210 | // Add enough force to overcome the mass of the object | ||
211 | addedForce *= m_controllingPrim.Mass; | ||
212 | |||
213 | m_controllingPrim.AddForce(addedForce, false /* pushForce */, true /* inTaintTime */); | ||
214 | } | ||
215 | m_physicsScene.DetailLog("{0},BSActorMoveToTarget.Mover3,move,fromPos={1},addedForce={2}", | ||
216 | m_controllingPrim.LocalID, origPosition, addedForce); | ||
155 | } | 217 | } |
156 | } | 218 | } |
157 | } | 219 | } |