diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 1169 |
1 files changed, 615 insertions, 554 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 5a9f135..dbc9039 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -23,7 +23,7 @@ | |||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | * |
27 | 27 | ||
28 | /* RA: June 14, 2011. Copied from ODEDynamics.cs and converted to | 28 | /* RA: June 14, 2011. Copied from ODEDynamics.cs and converted to |
29 | * call the BulletSim system. | 29 | * call the BulletSim system. |
@@ -52,19 +52,20 @@ using OpenSim.Region.Physics.Manager; | |||
52 | 52 | ||
53 | namespace OpenSim.Region.Physics.BulletSPlugin | 53 | namespace OpenSim.Region.Physics.BulletSPlugin |
54 | { | 54 | { |
55 | public class BSDynamics | 55 | public sealed class BSDynamics |
56 | { | 56 | { |
57 | private int frcount = 0; // Used to limit dynamics debug output to | 57 | private static string LogHeader = "[BULLETSIM VEHICLE]"; |
58 | // every 100th frame | 58 | |
59 | private BSScene PhysicsScene { get; set; } | ||
60 | // the prim this dynamic controller belongs to | ||
61 | private BSPrim Prim { get; set; } | ||
59 | 62 | ||
60 | private BSPrim m_prim; // the prim this dynamic controller belongs to | 63 | // mass of the vehicle fetched each time we're calles |
64 | private float m_vehicleMass; | ||
61 | 65 | ||
62 | // Vehicle properties | 66 | // Vehicle properties |
63 | private Vehicle m_type = Vehicle.TYPE_NONE; // If a 'VEHICLE', and what kind | 67 | public Vehicle Type { get; set; } |
64 | public Vehicle Type | 68 | |
65 | { | ||
66 | get { return m_type; } | ||
67 | } | ||
68 | // private Quaternion m_referenceFrame = Quaternion.Identity; // Axis modifier | 69 | // private Quaternion m_referenceFrame = Quaternion.Identity; // Axis modifier |
69 | private VehicleFlag m_flags = (VehicleFlag) 0; // Boolean settings: | 70 | private VehicleFlag m_flags = (VehicleFlag) 0; // Boolean settings: |
70 | // HOVER_TERRAIN_ONLY | 71 | // HOVER_TERRAIN_ONLY |
@@ -74,13 +75,15 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
74 | // HOVER_UP_ONLY | 75 | // HOVER_UP_ONLY |
75 | // LIMIT_MOTOR_UP | 76 | // LIMIT_MOTOR_UP |
76 | // LIMIT_ROLL_ONLY | 77 | // LIMIT_ROLL_ONLY |
77 | private VehicleFlag m_Hoverflags = (VehicleFlag)0; | ||
78 | private Vector3 m_BlockingEndPoint = Vector3.Zero; | 78 | private Vector3 m_BlockingEndPoint = Vector3.Zero; |
79 | private Quaternion m_RollreferenceFrame = Quaternion.Identity; | 79 | private Quaternion m_RollreferenceFrame = Quaternion.Identity; |
80 | private Quaternion m_referenceFrame = Quaternion.Identity; | ||
81 | |||
80 | // Linear properties | 82 | // Linear properties |
81 | private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time | 83 | private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time |
84 | private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center | ||
82 | private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL | 85 | private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL |
83 | private Vector3 m_dir = Vector3.Zero; // velocity applied to body | 86 | private Vector3 m_newVelocity = Vector3.Zero; // velocity computed to be applied to body |
84 | private Vector3 m_linearFrictionTimescale = Vector3.Zero; | 87 | private Vector3 m_linearFrictionTimescale = Vector3.Zero; |
85 | private float m_linearMotorDecayTimescale = 0; | 88 | private float m_linearMotorDecayTimescale = 0; |
86 | private float m_linearMotorTimescale = 0; | 89 | private float m_linearMotorTimescale = 0; |
@@ -91,28 +94,28 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
91 | 94 | ||
92 | //Angular properties | 95 | //Angular properties |
93 | private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor | 96 | private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor |
94 | private int m_angularMotorApply = 0; // application frame counter | 97 | // private int m_angularMotorApply = 0; // application frame counter |
95 | private Vector3 m_angularMotorVelocity = Vector3.Zero; // current angular motor velocity | 98 | private Vector3 m_angularMotorVelocity = Vector3.Zero; // current angular motor velocity |
96 | private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate | 99 | private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate |
97 | private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate | 100 | private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate |
98 | private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate | 101 | private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate |
99 | private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body | 102 | private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body |
100 | // private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body | 103 | private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body |
101 | 104 | ||
102 | //Deflection properties | 105 | //Deflection properties |
103 | // private float m_angularDeflectionEfficiency = 0; | 106 | private float m_angularDeflectionEfficiency = 0; |
104 | // private float m_angularDeflectionTimescale = 0; | 107 | private float m_angularDeflectionTimescale = 0; |
105 | // private float m_linearDeflectionEfficiency = 0; | 108 | private float m_linearDeflectionEfficiency = 0; |
106 | // private float m_linearDeflectionTimescale = 0; | 109 | private float m_linearDeflectionTimescale = 0; |
107 | 110 | ||
108 | //Banking properties | 111 | //Banking properties |
109 | // private float m_bankingEfficiency = 0; | 112 | private float m_bankingEfficiency = 0; |
110 | // private float m_bankingMix = 0; | 113 | private float m_bankingMix = 0; |
111 | // private float m_bankingTimescale = 0; | 114 | private float m_bankingTimescale = 0; |
112 | 115 | ||
113 | //Hover and Buoyancy properties | 116 | //Hover and Buoyancy properties |
114 | private float m_VhoverHeight = 0f; | 117 | private float m_VhoverHeight = 0f; |
115 | // private float m_VhoverEfficiency = 0f; | 118 | private float m_VhoverEfficiency = 0f; |
116 | private float m_VhoverTimescale = 0f; | 119 | private float m_VhoverTimescale = 0f; |
117 | private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height | 120 | private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height |
118 | private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle. | 121 | private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle. |
@@ -124,86 +127,74 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
124 | private float m_verticalAttractionEfficiency = 1.0f; // damped | 127 | private float m_verticalAttractionEfficiency = 1.0f; // damped |
125 | private float m_verticalAttractionTimescale = 500f; // Timescale > 300 means no vert attractor. | 128 | private float m_verticalAttractionTimescale = 500f; // Timescale > 300 means no vert attractor. |
126 | 129 | ||
127 | public BSDynamics(BSPrim myPrim) | 130 | public BSDynamics(BSScene myScene, BSPrim myPrim) |
131 | { | ||
132 | PhysicsScene = myScene; | ||
133 | Prim = myPrim; | ||
134 | Type = Vehicle.TYPE_NONE; | ||
135 | } | ||
136 | |||
137 | // Return 'true' if this vehicle is doing vehicle things | ||
138 | public bool IsActive | ||
128 | { | 139 | { |
129 | m_prim = myPrim; | 140 | get { return Type != Vehicle.TYPE_NONE; } |
130 | m_type = Vehicle.TYPE_NONE; | ||
131 | } | 141 | } |
132 | 142 | ||
133 | internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue, float timestep) | 143 | internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue) |
134 | { | 144 | { |
135 | DetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", m_prim.LocalID, pParam, pValue); | 145 | VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); |
136 | switch (pParam) | 146 | switch (pParam) |
137 | { | 147 | { |
138 | case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: | 148 | case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY: |
139 | if (pValue < 0.01f) pValue = 0.01f; | 149 | m_angularDeflectionEfficiency = Math.Max(pValue, 0.01f); |
140 | // m_angularDeflectionEfficiency = pValue; | ||
141 | break; | 150 | break; |
142 | case Vehicle.ANGULAR_DEFLECTION_TIMESCALE: | 151 | case Vehicle.ANGULAR_DEFLECTION_TIMESCALE: |
143 | if (pValue < 0.01f) pValue = 0.01f; | 152 | m_angularDeflectionTimescale = Math.Max(pValue, 0.01f); |
144 | // m_angularDeflectionTimescale = pValue; | ||
145 | break; | 153 | break; |
146 | case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE: | 154 | case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE: |
147 | if (pValue < 0.01f) pValue = 0.01f; | 155 | m_angularMotorDecayTimescale = Math.Max(pValue, 0.01f); |
148 | m_angularMotorDecayTimescale = pValue; | ||
149 | break; | 156 | break; |
150 | case Vehicle.ANGULAR_MOTOR_TIMESCALE: | 157 | case Vehicle.ANGULAR_MOTOR_TIMESCALE: |
151 | if (pValue < 0.01f) pValue = 0.01f; | 158 | m_angularMotorTimescale = Math.Max(pValue, 0.01f); |
152 | m_angularMotorTimescale = pValue; | ||
153 | break; | 159 | break; |
154 | case Vehicle.BANKING_EFFICIENCY: | 160 | case Vehicle.BANKING_EFFICIENCY: |
155 | if (pValue < 0.01f) pValue = 0.01f; | 161 | m_bankingEfficiency = Math.Max(-1f, Math.Min(pValue, 1f)); |
156 | // m_bankingEfficiency = pValue; | ||
157 | break; | 162 | break; |
158 | case Vehicle.BANKING_MIX: | 163 | case Vehicle.BANKING_MIX: |
159 | if (pValue < 0.01f) pValue = 0.01f; | 164 | m_bankingMix = Math.Max(pValue, 0.01f); |
160 | // m_bankingMix = pValue; | ||
161 | break; | 165 | break; |
162 | case Vehicle.BANKING_TIMESCALE: | 166 | case Vehicle.BANKING_TIMESCALE: |
163 | if (pValue < 0.01f) pValue = 0.01f; | 167 | m_bankingTimescale = Math.Max(pValue, 0.01f); |
164 | // m_bankingTimescale = pValue; | ||
165 | break; | 168 | break; |
166 | case Vehicle.BUOYANCY: | 169 | case Vehicle.BUOYANCY: |
167 | if (pValue < -1f) pValue = -1f; | 170 | m_VehicleBuoyancy = Math.Max(-1f, Math.Min(pValue, 1f)); |
168 | if (pValue > 1f) pValue = 1f; | 171 | break; |
169 | m_VehicleBuoyancy = pValue; | 172 | case Vehicle.HOVER_EFFICIENCY: |
170 | break; | 173 | m_VhoverEfficiency = Math.Max(0f, Math.Min(pValue, 1f)); |
171 | // case Vehicle.HOVER_EFFICIENCY: | 174 | break; |
172 | // if (pValue < 0f) pValue = 0f; | ||
173 | // if (pValue > 1f) pValue = 1f; | ||
174 | // m_VhoverEfficiency = pValue; | ||
175 | // break; | ||
176 | case Vehicle.HOVER_HEIGHT: | 175 | case Vehicle.HOVER_HEIGHT: |
177 | m_VhoverHeight = pValue; | 176 | m_VhoverHeight = pValue; |
178 | break; | 177 | break; |
179 | case Vehicle.HOVER_TIMESCALE: | 178 | case Vehicle.HOVER_TIMESCALE: |
180 | if (pValue < 0.01f) pValue = 0.01f; | 179 | m_VhoverTimescale = Math.Max(pValue, 0.01f); |
181 | m_VhoverTimescale = pValue; | ||
182 | break; | 180 | break; |
183 | case Vehicle.LINEAR_DEFLECTION_EFFICIENCY: | 181 | case Vehicle.LINEAR_DEFLECTION_EFFICIENCY: |
184 | if (pValue < 0.01f) pValue = 0.01f; | 182 | m_linearDeflectionEfficiency = Math.Max(pValue, 0.01f); |
185 | // m_linearDeflectionEfficiency = pValue; | ||
186 | break; | 183 | break; |
187 | case Vehicle.LINEAR_DEFLECTION_TIMESCALE: | 184 | case Vehicle.LINEAR_DEFLECTION_TIMESCALE: |
188 | if (pValue < 0.01f) pValue = 0.01f; | 185 | m_linearDeflectionTimescale = Math.Max(pValue, 0.01f); |
189 | // m_linearDeflectionTimescale = pValue; | ||
190 | break; | 186 | break; |
191 | case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: | 187 | case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE: |
192 | if (pValue < 0.01f) pValue = 0.01f; | 188 | m_linearMotorDecayTimescale = Math.Max(pValue, 0.01f); |
193 | m_linearMotorDecayTimescale = pValue; | ||
194 | break; | 189 | break; |
195 | case Vehicle.LINEAR_MOTOR_TIMESCALE: | 190 | case Vehicle.LINEAR_MOTOR_TIMESCALE: |
196 | if (pValue < 0.01f) pValue = 0.01f; | 191 | m_linearMotorTimescale = Math.Max(pValue, 0.01f); |
197 | m_linearMotorTimescale = pValue; | ||
198 | break; | 192 | break; |
199 | case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY: | 193 | case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY: |
200 | if (pValue < 0.1f) pValue = 0.1f; // Less goes unstable | 194 | m_verticalAttractionEfficiency = Math.Max(0.1f, Math.Min(pValue, 1f)); |
201 | if (pValue > 1.0f) pValue = 1.0f; | ||
202 | m_verticalAttractionEfficiency = pValue; | ||
203 | break; | 195 | break; |
204 | case Vehicle.VERTICAL_ATTRACTION_TIMESCALE: | 196 | case Vehicle.VERTICAL_ATTRACTION_TIMESCALE: |
205 | if (pValue < 0.01f) pValue = 0.01f; | 197 | m_verticalAttractionTimescale = Math.Max(pValue, 0.01f); |
206 | m_verticalAttractionTimescale = pValue; | ||
207 | break; | 198 | break; |
208 | 199 | ||
209 | // These are vector properties but the engine lets you use a single float value to | 200 | // These are vector properties but the engine lets you use a single float value to |
@@ -213,7 +204,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
213 | break; | 204 | break; |
214 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 205 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
215 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); | 206 | m_angularMotorDirection = new Vector3(pValue, pValue, pValue); |
216 | m_angularMotorApply = 10; | 207 | // m_angularMotorApply = 100; |
217 | break; | 208 | break; |
218 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 209 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
219 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); | 210 | m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue); |
@@ -223,30 +214,27 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
223 | m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue); | 214 | m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue); |
224 | break; | 215 | break; |
225 | case Vehicle.LINEAR_MOTOR_OFFSET: | 216 | case Vehicle.LINEAR_MOTOR_OFFSET: |
226 | // m_linearMotorOffset = new Vector3(pValue, pValue, pValue); | 217 | m_linearMotorOffset = new Vector3(pValue, pValue, pValue); |
227 | break; | 218 | break; |
228 | 219 | ||
229 | } | 220 | } |
230 | }//end ProcessFloatVehicleParam | 221 | }//end ProcessFloatVehicleParam |
231 | 222 | ||
232 | internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue, float timestep) | 223 | internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue) |
233 | { | 224 | { |
234 | DetailLog("{0},ProcessVectorVehicleParam,param={1},val={2}", m_prim.LocalID, pParam, pValue); | 225 | VDetailLog("{0},ProcessVectorVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); |
235 | switch (pParam) | 226 | switch (pParam) |
236 | { | 227 | { |
237 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: | 228 | case Vehicle.ANGULAR_FRICTION_TIMESCALE: |
238 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 229 | m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
239 | break; | 230 | break; |
240 | case Vehicle.ANGULAR_MOTOR_DIRECTION: | 231 | case Vehicle.ANGULAR_MOTOR_DIRECTION: |
241 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); | ||
242 | // Limit requested angular speed to 2 rps= 4 pi rads/sec | 232 | // Limit requested angular speed to 2 rps= 4 pi rads/sec |
243 | if (m_angularMotorDirection.X > 12.56f) m_angularMotorDirection.X = 12.56f; | 233 | pValue.X = Math.Max(-12.56f, Math.Min(pValue.X, 12.56f)); |
244 | if (m_angularMotorDirection.X < - 12.56f) m_angularMotorDirection.X = - 12.56f; | 234 | pValue.Y = Math.Max(-12.56f, Math.Min(pValue.Y, 12.56f)); |
245 | if (m_angularMotorDirection.Y > 12.56f) m_angularMotorDirection.Y = 12.56f; | 235 | pValue.Z = Math.Max(-12.56f, Math.Min(pValue.Z, 12.56f)); |
246 | if (m_angularMotorDirection.Y < - 12.56f) m_angularMotorDirection.Y = - 12.56f; | 236 | m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z); |
247 | if (m_angularMotorDirection.Z > 12.56f) m_angularMotorDirection.Z = 12.56f; | 237 | // m_angularMotorApply = 100; |
248 | if (m_angularMotorDirection.Z < - 12.56f) m_angularMotorDirection.Z = - 12.56f; | ||
249 | m_angularMotorApply = 10; | ||
250 | break; | 238 | break; |
251 | case Vehicle.LINEAR_FRICTION_TIMESCALE: | 239 | case Vehicle.LINEAR_FRICTION_TIMESCALE: |
252 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); | 240 | m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z); |
@@ -256,7 +244,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
256 | m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); | 244 | m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z); |
257 | break; | 245 | break; |
258 | case Vehicle.LINEAR_MOTOR_OFFSET: | 246 | case Vehicle.LINEAR_MOTOR_OFFSET: |
259 | // m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); | 247 | m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z); |
260 | break; | 248 | break; |
261 | case Vehicle.BLOCK_EXIT: | 249 | case Vehicle.BLOCK_EXIT: |
262 | m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z); | 250 | m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z); |
@@ -266,11 +254,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
266 | 254 | ||
267 | internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue) | 255 | internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue) |
268 | { | 256 | { |
269 | DetailLog("{0},ProcessRotationalVehicleParam,param={1},val={2}", m_prim.LocalID, pParam, pValue); | 257 | VDetailLog("{0},ProcessRotationalVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue); |
270 | switch (pParam) | 258 | switch (pParam) |
271 | { | 259 | { |
272 | case Vehicle.REFERENCE_FRAME: | 260 | case Vehicle.REFERENCE_FRAME: |
273 | // m_referenceFrame = pValue; | 261 | m_referenceFrame = pValue; |
274 | break; | 262 | break; |
275 | case Vehicle.ROLL_FRAME: | 263 | case Vehicle.ROLL_FRAME: |
276 | m_RollreferenceFrame = pValue; | 264 | m_RollreferenceFrame = pValue; |
@@ -280,575 +268,545 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
280 | 268 | ||
281 | internal void ProcessVehicleFlags(int pParam, bool remove) | 269 | internal void ProcessVehicleFlags(int pParam, bool remove) |
282 | { | 270 | { |
283 | DetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", m_prim.LocalID, pParam, remove); | 271 | VDetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", Prim.LocalID, pParam, remove); |
284 | if (remove) | 272 | VehicleFlag parm = (VehicleFlag)pParam; |
285 | { | 273 | if (pParam == -1) |
286 | if (pParam == -1) | 274 | m_flags = (VehicleFlag)0; |
287 | { | ||
288 | m_flags = (VehicleFlag)0; | ||
289 | m_Hoverflags = (VehicleFlag)0; | ||
290 | return; | ||
291 | } | ||
292 | if ((pParam & (int)VehicleFlag.HOVER_GLOBAL_HEIGHT) == (int)VehicleFlag.HOVER_GLOBAL_HEIGHT) | ||
293 | { | ||
294 | if ((m_Hoverflags & VehicleFlag.HOVER_GLOBAL_HEIGHT) != (VehicleFlag)0) | ||
295 | m_Hoverflags &= ~(VehicleFlag.HOVER_GLOBAL_HEIGHT); | ||
296 | } | ||
297 | if ((pParam & (int)VehicleFlag.HOVER_TERRAIN_ONLY) == (int)VehicleFlag.HOVER_TERRAIN_ONLY) | ||
298 | { | ||
299 | if ((m_Hoverflags & VehicleFlag.HOVER_TERRAIN_ONLY) != (VehicleFlag)0) | ||
300 | m_Hoverflags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY); | ||
301 | } | ||
302 | if ((pParam & (int)VehicleFlag.HOVER_UP_ONLY) == (int)VehicleFlag.HOVER_UP_ONLY) | ||
303 | { | ||
304 | if ((m_Hoverflags & VehicleFlag.HOVER_UP_ONLY) != (VehicleFlag)0) | ||
305 | m_Hoverflags &= ~(VehicleFlag.HOVER_UP_ONLY); | ||
306 | } | ||
307 | if ((pParam & (int)VehicleFlag.HOVER_WATER_ONLY) == (int)VehicleFlag.HOVER_WATER_ONLY) | ||
308 | { | ||
309 | if ((m_Hoverflags & VehicleFlag.HOVER_WATER_ONLY) != (VehicleFlag)0) | ||
310 | m_Hoverflags &= ~(VehicleFlag.HOVER_WATER_ONLY); | ||
311 | } | ||
312 | if ((pParam & (int)VehicleFlag.LIMIT_MOTOR_UP) == (int)VehicleFlag.LIMIT_MOTOR_UP) | ||
313 | { | ||
314 | if ((m_flags & VehicleFlag.LIMIT_MOTOR_UP) != (VehicleFlag)0) | ||
315 | m_flags &= ~(VehicleFlag.LIMIT_MOTOR_UP); | ||
316 | } | ||
317 | if ((pParam & (int)VehicleFlag.LIMIT_ROLL_ONLY) == (int)VehicleFlag.LIMIT_ROLL_ONLY) | ||
318 | { | ||
319 | if ((m_flags & VehicleFlag.LIMIT_ROLL_ONLY) != (VehicleFlag)0) | ||
320 | m_flags &= ~(VehicleFlag.LIMIT_ROLL_ONLY); | ||
321 | } | ||
322 | if ((pParam & (int)VehicleFlag.MOUSELOOK_BANK) == (int)VehicleFlag.MOUSELOOK_BANK) | ||
323 | { | ||
324 | if ((m_flags & VehicleFlag.MOUSELOOK_BANK) != (VehicleFlag)0) | ||
325 | m_flags &= ~(VehicleFlag.MOUSELOOK_BANK); | ||
326 | } | ||
327 | if ((pParam & (int)VehicleFlag.MOUSELOOK_STEER) == (int)VehicleFlag.MOUSELOOK_STEER) | ||
328 | { | ||
329 | if ((m_flags & VehicleFlag.MOUSELOOK_STEER) != (VehicleFlag)0) | ||
330 | m_flags &= ~(VehicleFlag.MOUSELOOK_STEER); | ||
331 | } | ||
332 | if ((pParam & (int)VehicleFlag.NO_DEFLECTION_UP) == (int)VehicleFlag.NO_DEFLECTION_UP) | ||
333 | { | ||
334 | if ((m_flags & VehicleFlag.NO_DEFLECTION_UP) != (VehicleFlag)0) | ||
335 | m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP); | ||
336 | } | ||
337 | if ((pParam & (int)VehicleFlag.CAMERA_DECOUPLED) == (int)VehicleFlag.CAMERA_DECOUPLED) | ||
338 | { | ||
339 | if ((m_flags & VehicleFlag.CAMERA_DECOUPLED) != (VehicleFlag)0) | ||
340 | m_flags &= ~(VehicleFlag.CAMERA_DECOUPLED); | ||
341 | } | ||
342 | if ((pParam & (int)VehicleFlag.NO_X) == (int)VehicleFlag.NO_X) | ||
343 | { | ||
344 | if ((m_flags & VehicleFlag.NO_X) != (VehicleFlag)0) | ||
345 | m_flags &= ~(VehicleFlag.NO_X); | ||
346 | } | ||
347 | if ((pParam & (int)VehicleFlag.NO_Y) == (int)VehicleFlag.NO_Y) | ||
348 | { | ||
349 | if ((m_flags & VehicleFlag.NO_Y) != (VehicleFlag)0) | ||
350 | m_flags &= ~(VehicleFlag.NO_Y); | ||
351 | } | ||
352 | if ((pParam & (int)VehicleFlag.NO_Z) == (int)VehicleFlag.NO_Z) | ||
353 | { | ||
354 | if ((m_flags & VehicleFlag.NO_Z) != (VehicleFlag)0) | ||
355 | m_flags &= ~(VehicleFlag.NO_Z); | ||
356 | } | ||
357 | if ((pParam & (int)VehicleFlag.LOCK_HOVER_HEIGHT) == (int)VehicleFlag.LOCK_HOVER_HEIGHT) | ||
358 | { | ||
359 | if ((m_Hoverflags & VehicleFlag.LOCK_HOVER_HEIGHT) != (VehicleFlag)0) | ||
360 | m_Hoverflags &= ~(VehicleFlag.LOCK_HOVER_HEIGHT); | ||
361 | } | ||
362 | if ((pParam & (int)VehicleFlag.NO_DEFLECTION) == (int)VehicleFlag.NO_DEFLECTION) | ||
363 | { | ||
364 | if ((m_flags & VehicleFlag.NO_DEFLECTION) != (VehicleFlag)0) | ||
365 | m_flags &= ~(VehicleFlag.NO_DEFLECTION); | ||
366 | } | ||
367 | if ((pParam & (int)VehicleFlag.LOCK_ROTATION) == (int)VehicleFlag.LOCK_ROTATION) | ||
368 | { | ||
369 | if ((m_flags & VehicleFlag.LOCK_ROTATION) != (VehicleFlag)0) | ||
370 | m_flags &= ~(VehicleFlag.LOCK_ROTATION); | ||
371 | } | ||
372 | } | ||
373 | else | 275 | else |
374 | { | 276 | { |
375 | if ((pParam & (int)VehicleFlag.HOVER_GLOBAL_HEIGHT) == (int)VehicleFlag.HOVER_GLOBAL_HEIGHT) | 277 | if (remove) |
376 | { | 278 | m_flags &= ~parm; |
377 | m_Hoverflags |= (VehicleFlag.HOVER_GLOBAL_HEIGHT | m_flags); | 279 | else |
378 | } | 280 | m_flags |= parm; |
379 | if ((pParam & (int)VehicleFlag.HOVER_TERRAIN_ONLY) == (int)VehicleFlag.HOVER_TERRAIN_ONLY) | ||
380 | { | ||
381 | m_Hoverflags |= (VehicleFlag.HOVER_TERRAIN_ONLY | m_flags); | ||
382 | } | ||
383 | if ((pParam & (int)VehicleFlag.HOVER_UP_ONLY) == (int)VehicleFlag.HOVER_UP_ONLY) | ||
384 | { | ||
385 | m_Hoverflags |= (VehicleFlag.HOVER_UP_ONLY | m_flags); | ||
386 | } | ||
387 | if ((pParam & (int)VehicleFlag.HOVER_WATER_ONLY) == (int)VehicleFlag.HOVER_WATER_ONLY) | ||
388 | { | ||
389 | m_Hoverflags |= (VehicleFlag.HOVER_WATER_ONLY | m_flags); | ||
390 | } | ||
391 | if ((pParam & (int)VehicleFlag.LIMIT_MOTOR_UP) == (int)VehicleFlag.LIMIT_MOTOR_UP) | ||
392 | { | ||
393 | m_flags |= (VehicleFlag.LIMIT_MOTOR_UP | m_flags); | ||
394 | } | ||
395 | if ((pParam & (int)VehicleFlag.MOUSELOOK_BANK) == (int)VehicleFlag.MOUSELOOK_BANK) | ||
396 | { | ||
397 | m_flags |= (VehicleFlag.MOUSELOOK_BANK | m_flags); | ||
398 | } | ||
399 | if ((pParam & (int)VehicleFlag.MOUSELOOK_STEER) == (int)VehicleFlag.MOUSELOOK_STEER) | ||
400 | { | ||
401 | m_flags |= (VehicleFlag.MOUSELOOK_STEER | m_flags); | ||
402 | } | ||
403 | if ((pParam & (int)VehicleFlag.NO_DEFLECTION_UP) == (int)VehicleFlag.NO_DEFLECTION_UP) | ||
404 | { | ||
405 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | m_flags); | ||
406 | } | ||
407 | if ((pParam & (int)VehicleFlag.CAMERA_DECOUPLED) == (int)VehicleFlag.CAMERA_DECOUPLED) | ||
408 | { | ||
409 | m_flags |= (VehicleFlag.CAMERA_DECOUPLED | m_flags); | ||
410 | } | ||
411 | if ((pParam & (int)VehicleFlag.NO_X) == (int)VehicleFlag.NO_X) | ||
412 | { | ||
413 | m_flags |= (VehicleFlag.NO_X); | ||
414 | } | ||
415 | if ((pParam & (int)VehicleFlag.NO_Y) == (int)VehicleFlag.NO_Y) | ||
416 | { | ||
417 | m_flags |= (VehicleFlag.NO_Y); | ||
418 | } | ||
419 | if ((pParam & (int)VehicleFlag.NO_Z) == (int)VehicleFlag.NO_Z) | ||
420 | { | ||
421 | m_flags |= (VehicleFlag.NO_Z); | ||
422 | } | ||
423 | if ((pParam & (int)VehicleFlag.LOCK_HOVER_HEIGHT) == (int)VehicleFlag.LOCK_HOVER_HEIGHT) | ||
424 | { | ||
425 | m_Hoverflags |= (VehicleFlag.LOCK_HOVER_HEIGHT); | ||
426 | } | ||
427 | if ((pParam & (int)VehicleFlag.NO_DEFLECTION) == (int)VehicleFlag.NO_DEFLECTION) | ||
428 | { | ||
429 | m_flags |= (VehicleFlag.NO_DEFLECTION); | ||
430 | } | ||
431 | if ((pParam & (int)VehicleFlag.LOCK_ROTATION) == (int)VehicleFlag.LOCK_ROTATION) | ||
432 | { | ||
433 | m_flags |= (VehicleFlag.LOCK_ROTATION); | ||
434 | } | ||
435 | } | 281 | } |
436 | }//end ProcessVehicleFlags | 282 | } |
437 | 283 | ||
438 | internal void ProcessTypeChange(Vehicle pType) | 284 | internal void ProcessTypeChange(Vehicle pType) |
439 | { | 285 | { |
440 | DetailLog("{0},ProcessTypeChange,type={1}", m_prim.LocalID, pType); | 286 | VDetailLog("{0},ProcessTypeChange,type={1}", Prim.LocalID, pType); |
441 | // Set Defaults For Type | 287 | // Set Defaults For Type |
442 | m_type = pType; | 288 | Type = pType; |
443 | switch (pType) | 289 | switch (pType) |
444 | { | 290 | { |
445 | case Vehicle.TYPE_NONE: | 291 | case Vehicle.TYPE_NONE: |
446 | m_linearFrictionTimescale = new Vector3(0, 0, 0); | ||
447 | m_angularFrictionTimescale = new Vector3(0, 0, 0); | ||
448 | m_linearMotorDirection = Vector3.Zero; | 292 | m_linearMotorDirection = Vector3.Zero; |
449 | m_linearMotorTimescale = 0; | 293 | m_linearMotorTimescale = 0; |
450 | m_linearMotorDecayTimescale = 0; | 294 | m_linearMotorDecayTimescale = 0; |
295 | m_linearFrictionTimescale = new Vector3(0, 0, 0); | ||
296 | |||
451 | m_angularMotorDirection = Vector3.Zero; | 297 | m_angularMotorDirection = Vector3.Zero; |
452 | m_angularMotorTimescale = 0; | ||
453 | m_angularMotorDecayTimescale = 0; | 298 | m_angularMotorDecayTimescale = 0; |
299 | m_angularMotorTimescale = 0; | ||
300 | m_angularFrictionTimescale = new Vector3(0, 0, 0); | ||
301 | |||
454 | m_VhoverHeight = 0; | 302 | m_VhoverHeight = 0; |
303 | m_VhoverEfficiency = 0; | ||
455 | m_VhoverTimescale = 0; | 304 | m_VhoverTimescale = 0; |
456 | m_VehicleBuoyancy = 0; | 305 | m_VehicleBuoyancy = 0; |
306 | |||
307 | m_linearDeflectionEfficiency = 1; | ||
308 | m_linearDeflectionTimescale = 1; | ||
309 | |||
310 | m_angularDeflectionEfficiency = 0; | ||
311 | m_angularDeflectionTimescale = 1000; | ||
312 | |||
313 | m_verticalAttractionEfficiency = 0; | ||
314 | m_verticalAttractionTimescale = 0; | ||
315 | |||
316 | m_bankingEfficiency = 0; | ||
317 | m_bankingTimescale = 1000; | ||
318 | m_bankingMix = 1; | ||
319 | |||
320 | m_referenceFrame = Quaternion.Identity; | ||
457 | m_flags = (VehicleFlag)0; | 321 | m_flags = (VehicleFlag)0; |
458 | break; | 322 | break; |
459 | 323 | ||
460 | case Vehicle.TYPE_SLED: | 324 | case Vehicle.TYPE_SLED: |
461 | m_linearFrictionTimescale = new Vector3(30, 1, 1000); | ||
462 | m_angularFrictionTimescale = new Vector3(1000, 1000, 1000); | ||
463 | m_linearMotorDirection = Vector3.Zero; | 325 | m_linearMotorDirection = Vector3.Zero; |
464 | m_linearMotorTimescale = 1000; | 326 | m_linearMotorTimescale = 1000; |
465 | m_linearMotorDecayTimescale = 120; | 327 | m_linearMotorDecayTimescale = 120; |
328 | m_linearFrictionTimescale = new Vector3(30, 1, 1000); | ||
329 | |||
466 | m_angularMotorDirection = Vector3.Zero; | 330 | m_angularMotorDirection = Vector3.Zero; |
467 | m_angularMotorTimescale = 1000; | 331 | m_angularMotorTimescale = 1000; |
468 | m_angularMotorDecayTimescale = 120; | 332 | m_angularMotorDecayTimescale = 120; |
333 | m_angularFrictionTimescale = new Vector3(1000, 1000, 1000); | ||
334 | |||
469 | m_VhoverHeight = 0; | 335 | m_VhoverHeight = 0; |
470 | // m_VhoverEfficiency = 1; | 336 | m_VhoverEfficiency = 10; // TODO: this looks wrong!! |
471 | m_VhoverTimescale = 10; | 337 | m_VhoverTimescale = 10; |
472 | m_VehicleBuoyancy = 0; | 338 | m_VehicleBuoyancy = 0; |
473 | // m_linearDeflectionEfficiency = 1; | 339 | |
474 | // m_linearDeflectionTimescale = 1; | 340 | m_linearDeflectionEfficiency = 1; |
475 | // m_angularDeflectionEfficiency = 1; | 341 | m_linearDeflectionTimescale = 1; |
476 | // m_angularDeflectionTimescale = 1000; | 342 | |
477 | // m_bankingEfficiency = 0; | 343 | m_angularDeflectionEfficiency = 1; |
478 | // m_bankingMix = 1; | 344 | m_angularDeflectionTimescale = 1000; |
479 | // m_bankingTimescale = 10; | 345 | |
480 | // m_referenceFrame = Quaternion.Identity; | 346 | m_verticalAttractionEfficiency = 0; |
481 | m_Hoverflags &= | 347 | m_verticalAttractionTimescale = 0; |
348 | |||
349 | m_bankingEfficiency = 0; | ||
350 | m_bankingTimescale = 10; | ||
351 | m_bankingMix = 1; | ||
352 | |||
353 | m_referenceFrame = Quaternion.Identity; | ||
354 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP); | ||
355 | m_flags &= | ||
482 | ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | | 356 | ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | |
483 | VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY); | 357 | VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY); |
484 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP); | ||
485 | break; | 358 | break; |
486 | case Vehicle.TYPE_CAR: | 359 | case Vehicle.TYPE_CAR: |
487 | m_linearFrictionTimescale = new Vector3(100, 2, 1000); | ||
488 | m_angularFrictionTimescale = new Vector3(1000, 1000, 1000); | ||
489 | m_linearMotorDirection = Vector3.Zero; | 360 | m_linearMotorDirection = Vector3.Zero; |
490 | m_linearMotorTimescale = 1; | 361 | m_linearMotorTimescale = 1; |
491 | m_linearMotorDecayTimescale = 60; | 362 | m_linearMotorDecayTimescale = 60; |
363 | m_linearFrictionTimescale = new Vector3(100, 2, 1000); | ||
364 | |||
492 | m_angularMotorDirection = Vector3.Zero; | 365 | m_angularMotorDirection = Vector3.Zero; |
493 | m_angularMotorTimescale = 1; | 366 | m_angularMotorTimescale = 1; |
494 | m_angularMotorDecayTimescale = 0.8f; | 367 | m_angularMotorDecayTimescale = 0.8f; |
368 | m_angularFrictionTimescale = new Vector3(1000, 1000, 1000); | ||
369 | |||
495 | m_VhoverHeight = 0; | 370 | m_VhoverHeight = 0; |
496 | // m_VhoverEfficiency = 0; | 371 | m_VhoverEfficiency = 0; |
497 | m_VhoverTimescale = 1000; | 372 | m_VhoverTimescale = 1000; |
498 | m_VehicleBuoyancy = 0; | 373 | m_VehicleBuoyancy = 0; |
499 | // // m_linearDeflectionEfficiency = 1; | 374 | |
500 | // // m_linearDeflectionTimescale = 2; | 375 | m_linearDeflectionEfficiency = 1; |
501 | // // m_angularDeflectionEfficiency = 0; | 376 | m_linearDeflectionTimescale = 2; |
502 | // m_angularDeflectionTimescale = 10; | 377 | |
378 | m_angularDeflectionEfficiency = 0; | ||
379 | m_angularDeflectionTimescale = 10; | ||
380 | |||
503 | m_verticalAttractionEfficiency = 1f; | 381 | m_verticalAttractionEfficiency = 1f; |
504 | m_verticalAttractionTimescale = 10f; | 382 | m_verticalAttractionTimescale = 10f; |
505 | // m_bankingEfficiency = -0.2f; | 383 | |
506 | // m_bankingMix = 1; | 384 | m_bankingEfficiency = -0.2f; |
507 | // m_bankingTimescale = 1; | 385 | m_bankingMix = 1; |
508 | // m_referenceFrame = Quaternion.Identity; | 386 | m_bankingTimescale = 1; |
509 | m_Hoverflags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT); | 387 | |
510 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | | 388 | m_referenceFrame = Quaternion.Identity; |
511 | VehicleFlag.LIMIT_MOTOR_UP); | 389 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
512 | m_Hoverflags |= (VehicleFlag.HOVER_UP_ONLY); | 390 | | VehicleFlag.HOVER_TERRAIN_ONLY |
391 | | VehicleFlag.HOVER_GLOBAL_HEIGHT); | ||
392 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | ||
393 | | VehicleFlag.LIMIT_ROLL_ONLY | ||
394 | | VehicleFlag.LIMIT_MOTOR_UP | ||
395 | | VehicleFlag.HOVER_UP_ONLY); | ||
513 | break; | 396 | break; |
514 | case Vehicle.TYPE_BOAT: | 397 | case Vehicle.TYPE_BOAT: |
515 | m_linearFrictionTimescale = new Vector3(10, 3, 2); | ||
516 | m_angularFrictionTimescale = new Vector3(10,10,10); | ||
517 | m_linearMotorDirection = Vector3.Zero; | 398 | m_linearMotorDirection = Vector3.Zero; |
518 | m_linearMotorTimescale = 5; | 399 | m_linearMotorTimescale = 5; |
519 | m_linearMotorDecayTimescale = 60; | 400 | m_linearMotorDecayTimescale = 60; |
401 | m_linearFrictionTimescale = new Vector3(10, 3, 2); | ||
402 | |||
520 | m_angularMotorDirection = Vector3.Zero; | 403 | m_angularMotorDirection = Vector3.Zero; |
521 | m_angularMotorTimescale = 4; | 404 | m_angularMotorTimescale = 4; |
522 | m_angularMotorDecayTimescale = 4; | 405 | m_angularMotorDecayTimescale = 4; |
406 | m_angularFrictionTimescale = new Vector3(10,10,10); | ||
407 | |||
523 | m_VhoverHeight = 0; | 408 | m_VhoverHeight = 0; |
524 | // m_VhoverEfficiency = 0.5f; | 409 | m_VhoverEfficiency = 0.5f; |
525 | m_VhoverTimescale = 2; | 410 | m_VhoverTimescale = 2; |
526 | m_VehicleBuoyancy = 1; | 411 | m_VehicleBuoyancy = 1; |
527 | // m_linearDeflectionEfficiency = 0.5f; | 412 | |
528 | // m_linearDeflectionTimescale = 3; | 413 | m_linearDeflectionEfficiency = 0.5f; |
529 | // m_angularDeflectionEfficiency = 0.5f; | 414 | m_linearDeflectionTimescale = 3; |
530 | // m_angularDeflectionTimescale = 5; | 415 | |
416 | m_angularDeflectionEfficiency = 0.5f; | ||
417 | m_angularDeflectionTimescale = 5; | ||
418 | |||
531 | m_verticalAttractionEfficiency = 0.5f; | 419 | m_verticalAttractionEfficiency = 0.5f; |
532 | m_verticalAttractionTimescale = 5f; | 420 | m_verticalAttractionTimescale = 5f; |
533 | // m_bankingEfficiency = -0.3f; | 421 | |
534 | // m_bankingMix = 0.8f; | 422 | m_bankingEfficiency = -0.3f; |
535 | // m_bankingTimescale = 1; | 423 | m_bankingMix = 0.8f; |
536 | // m_referenceFrame = Quaternion.Identity; | 424 | m_bankingTimescale = 1; |
537 | m_Hoverflags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY | | 425 | |
538 | VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY); | 426 | m_referenceFrame = Quaternion.Identity; |
539 | m_flags &= ~(VehicleFlag.LIMIT_ROLL_ONLY); | 427 | m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY |
540 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | | 428 | | VehicleFlag.HOVER_GLOBAL_HEIGHT |
541 | VehicleFlag.LIMIT_MOTOR_UP); | 429 | | VehicleFlag.LIMIT_ROLL_ONLY |
542 | m_Hoverflags |= (VehicleFlag.HOVER_WATER_ONLY); | 430 | | VehicleFlag.HOVER_UP_ONLY); |
431 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | ||
432 | | VehicleFlag.LIMIT_MOTOR_UP | ||
433 | | VehicleFlag.HOVER_WATER_ONLY); | ||
543 | break; | 434 | break; |
544 | case Vehicle.TYPE_AIRPLANE: | 435 | case Vehicle.TYPE_AIRPLANE: |
545 | m_linearFrictionTimescale = new Vector3(200, 10, 5); | ||
546 | m_angularFrictionTimescale = new Vector3(20, 20, 20); | ||
547 | m_linearMotorDirection = Vector3.Zero; | 436 | m_linearMotorDirection = Vector3.Zero; |
548 | m_linearMotorTimescale = 2; | 437 | m_linearMotorTimescale = 2; |
549 | m_linearMotorDecayTimescale = 60; | 438 | m_linearMotorDecayTimescale = 60; |
439 | m_linearFrictionTimescale = new Vector3(200, 10, 5); | ||
440 | |||
550 | m_angularMotorDirection = Vector3.Zero; | 441 | m_angularMotorDirection = Vector3.Zero; |
551 | m_angularMotorTimescale = 4; | 442 | m_angularMotorTimescale = 4; |
552 | m_angularMotorDecayTimescale = 4; | 443 | m_angularMotorDecayTimescale = 4; |
444 | m_angularFrictionTimescale = new Vector3(20, 20, 20); | ||
445 | |||
553 | m_VhoverHeight = 0; | 446 | m_VhoverHeight = 0; |
554 | // m_VhoverEfficiency = 0.5f; | 447 | m_VhoverEfficiency = 0.5f; |
555 | m_VhoverTimescale = 1000; | 448 | m_VhoverTimescale = 1000; |
556 | m_VehicleBuoyancy = 0; | 449 | m_VehicleBuoyancy = 0; |
557 | // m_linearDeflectionEfficiency = 0.5f; | 450 | |
558 | // m_linearDeflectionTimescale = 3; | 451 | m_linearDeflectionEfficiency = 0.5f; |
559 | // m_angularDeflectionEfficiency = 1; | 452 | m_linearDeflectionTimescale = 3; |
560 | // m_angularDeflectionTimescale = 2; | 453 | |
454 | m_angularDeflectionEfficiency = 1; | ||
455 | m_angularDeflectionTimescale = 2; | ||
456 | |||
561 | m_verticalAttractionEfficiency = 0.9f; | 457 | m_verticalAttractionEfficiency = 0.9f; |
562 | m_verticalAttractionTimescale = 2f; | 458 | m_verticalAttractionTimescale = 2f; |
563 | // m_bankingEfficiency = 1; | 459 | |
564 | // m_bankingMix = 0.7f; | 460 | m_bankingEfficiency = 1; |
565 | // m_bankingTimescale = 2; | 461 | m_bankingMix = 0.7f; |
566 | // m_referenceFrame = Quaternion.Identity; | 462 | m_bankingTimescale = 2; |
567 | m_Hoverflags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | | 463 | |
568 | VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY); | 464 | m_referenceFrame = Quaternion.Identity; |
569 | m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_MOTOR_UP); | 465 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
466 | | VehicleFlag.HOVER_TERRAIN_ONLY | ||
467 | | VehicleFlag.HOVER_GLOBAL_HEIGHT | ||
468 | | VehicleFlag.HOVER_UP_ONLY | ||
469 | | VehicleFlag.NO_DEFLECTION_UP | ||
470 | | VehicleFlag.LIMIT_MOTOR_UP); | ||
570 | m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY); | 471 | m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY); |
571 | break; | 472 | break; |
572 | case Vehicle.TYPE_BALLOON: | 473 | case Vehicle.TYPE_BALLOON: |
573 | m_linearFrictionTimescale = new Vector3(5, 5, 5); | ||
574 | m_angularFrictionTimescale = new Vector3(10, 10, 10); | ||
575 | m_linearMotorDirection = Vector3.Zero; | 474 | m_linearMotorDirection = Vector3.Zero; |
576 | m_linearMotorTimescale = 5; | 475 | m_linearMotorTimescale = 5; |
476 | m_linearFrictionTimescale = new Vector3(5, 5, 5); | ||
577 | m_linearMotorDecayTimescale = 60; | 477 | m_linearMotorDecayTimescale = 60; |
478 | |||
578 | m_angularMotorDirection = Vector3.Zero; | 479 | m_angularMotorDirection = Vector3.Zero; |
579 | m_angularMotorTimescale = 6; | 480 | m_angularMotorTimescale = 6; |
481 | m_angularFrictionTimescale = new Vector3(10, 10, 10); | ||
580 | m_angularMotorDecayTimescale = 10; | 482 | m_angularMotorDecayTimescale = 10; |
483 | |||
581 | m_VhoverHeight = 5; | 484 | m_VhoverHeight = 5; |
582 | // m_VhoverEfficiency = 0.8f; | 485 | m_VhoverEfficiency = 0.8f; |
583 | m_VhoverTimescale = 10; | 486 | m_VhoverTimescale = 10; |
584 | m_VehicleBuoyancy = 1; | 487 | m_VehicleBuoyancy = 1; |
585 | // m_linearDeflectionEfficiency = 0; | 488 | |
586 | // m_linearDeflectionTimescale = 5; | 489 | m_linearDeflectionEfficiency = 0; |
587 | // m_angularDeflectionEfficiency = 0; | 490 | m_linearDeflectionTimescale = 5; |
588 | // m_angularDeflectionTimescale = 5; | 491 | |
492 | m_angularDeflectionEfficiency = 0; | ||
493 | m_angularDeflectionTimescale = 5; | ||
494 | |||
589 | m_verticalAttractionEfficiency = 1f; | 495 | m_verticalAttractionEfficiency = 1f; |
590 | m_verticalAttractionTimescale = 100f; | 496 | m_verticalAttractionTimescale = 100f; |
591 | // m_bankingEfficiency = 0; | 497 | |
592 | // m_bankingMix = 0.7f; | 498 | m_bankingEfficiency = 0; |
593 | // m_bankingTimescale = 5; | 499 | m_bankingMix = 0.7f; |
594 | // m_referenceFrame = Quaternion.Identity; | 500 | m_bankingTimescale = 5; |
595 | m_Hoverflags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | | 501 | m_referenceFrame = Quaternion.Identity; |
596 | VehicleFlag.HOVER_UP_ONLY); | 502 | |
597 | m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_MOTOR_UP); | 503 | m_referenceFrame = Quaternion.Identity; |
598 | m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY); | 504 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
599 | m_Hoverflags |= (VehicleFlag.HOVER_GLOBAL_HEIGHT); | 505 | | VehicleFlag.HOVER_TERRAIN_ONLY |
506 | | VehicleFlag.HOVER_UP_ONLY | ||
507 | | VehicleFlag.NO_DEFLECTION_UP | ||
508 | | VehicleFlag.LIMIT_MOTOR_UP); | ||
509 | m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY | ||
510 | | VehicleFlag.HOVER_GLOBAL_HEIGHT); | ||
600 | break; | 511 | break; |
601 | } | 512 | } |
602 | }//end SetDefaultsForType | 513 | } |
514 | |||
515 | // Some of the properties of this prim may have changed. | ||
516 | // Do any updating needed for a vehicle | ||
517 | public void Refresh() | ||
518 | { | ||
519 | if (IsActive) | ||
520 | { | ||
521 | // Friction effects are handled by this vehicle code | ||
522 | BulletSimAPI.SetFriction2(Prim.PhysBody.ptr, 0f); | ||
523 | BulletSimAPI.SetHitFraction2(Prim.PhysBody.ptr, 0f); | ||
524 | |||
525 | // BulletSimAPI.SetAngularDamping2(Prim.PhysBody.ptr, 0.8f); | ||
526 | |||
527 | VDetailLog("{0},BSDynamics.Refresh,zeroingFriction and adding damping", Prim.LocalID); | ||
528 | } | ||
529 | } | ||
530 | |||
531 | public bool RemoveBodyDependencies(BSPhysObject prim) | ||
532 | { | ||
533 | // If active, we need to add our properties back when the body is rebuilt. | ||
534 | return IsActive; | ||
535 | } | ||
536 | |||
537 | public void RestoreBodyDependencies(BSPhysObject prim) | ||
538 | { | ||
539 | if (Prim.LocalID != prim.LocalID) | ||
540 | { | ||
541 | // The call should be on us by our prim. Error if not. | ||
542 | PhysicsScene.Logger.ErrorFormat("{0} RestoreBodyDependencies: called by not my prim. passedLocalID={1}, vehiclePrimLocalID={2}", | ||
543 | LogHeader, prim.LocalID, Prim.LocalID); | ||
544 | return; | ||
545 | } | ||
546 | Refresh(); | ||
547 | } | ||
603 | 548 | ||
549 | // One step of the vehicle properties for the next 'pTimestep' seconds. | ||
604 | internal void Step(float pTimestep) | 550 | internal void Step(float pTimestep) |
605 | { | 551 | { |
606 | if (m_type == Vehicle.TYPE_NONE) return; | 552 | if (!IsActive) return; |
607 | 553 | ||
608 | frcount++; // used to limit debug comment output | 554 | // DEBUG |
609 | if (frcount > 100) | 555 | // Because Bullet does apply forces to the vehicle, our last computed |
610 | frcount = 0; | 556 | // linear and angular velocities are not what is happening now. |
557 | // Vector3 externalAngularVelocity = Prim.ForceRotationalVelocity - m_lastAngularVelocity; | ||
558 | // m_lastAngularVelocity += (externalAngularVelocity * 0.5f) * pTimestep; | ||
559 | // m_lastAngularVelocity = Prim.ForceRotationalVelocity; // DEBUG: account for what Bullet did last time | ||
560 | // m_lastLinearVelocityVector = Prim.ForceVelocity * Quaternion.Inverse(Prim.ForceOrientation); // DEBUG: | ||
561 | // END DEBUG | ||
562 | |||
563 | m_vehicleMass = Prim.Linkset.LinksetMass; | ||
611 | 564 | ||
612 | MoveLinear(pTimestep); | 565 | MoveLinear(pTimestep); |
566 | // Commented out for debug | ||
613 | MoveAngular(pTimestep); | 567 | MoveAngular(pTimestep); |
568 | // Prim.ApplyTorqueImpulse(-Prim.RotationalVelocity * m_vehicleMass, false); // DEBUG DEBUG | ||
569 | // Prim.ForceRotationalVelocity = -Prim.RotationalVelocity; // DEBUG DEBUG | ||
570 | |||
614 | LimitRotation(pTimestep); | 571 | LimitRotation(pTimestep); |
615 | 572 | ||
616 | DetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}", | 573 | // remember the position so next step we can limit absolute movement effects |
617 | m_prim.LocalID, m_prim.Position, m_prim.Force, m_prim.Velocity, m_prim.RotationalVelocity); | 574 | m_lastPositionVector = Prim.ForcePosition; |
575 | |||
576 | VDetailLog("{0},BSDynamics.Step,frict={1},grav={2},inertia={3},mass={4}", // DEBUG DEBUG | ||
577 | Prim.LocalID, | ||
578 | BulletSimAPI.GetFriction2(Prim.PhysBody.ptr), | ||
579 | BulletSimAPI.GetGravity2(Prim.PhysBody.ptr), | ||
580 | Prim.Inertia, | ||
581 | m_vehicleMass | ||
582 | ); | ||
583 | VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}", | ||
584 | Prim.LocalID, Prim.ForcePosition, Prim.Force, Prim.ForceVelocity, Prim.RotationalVelocity); | ||
618 | }// end Step | 585 | }// end Step |
619 | 586 | ||
587 | // Apply the effect of the linear motor. | ||
588 | // Also does hover and float. | ||
620 | private void MoveLinear(float pTimestep) | 589 | private void MoveLinear(float pTimestep) |
621 | { | 590 | { |
622 | // requested m_linearMotorDirection is significant | 591 | // m_linearMotorDirection is the target direction we are moving relative to the vehicle coordinates |
623 | // if (!m_linearMotorDirection.ApproxEquals(Vector3.Zero, 0.01f)) | 592 | // m_lastLinearVelocityVector is the current speed we are moving in that direction |
624 | if (m_linearMotorDirection.LengthSquared() > 0.0001f) | 593 | if (m_linearMotorDirection.LengthSquared() > 0.001f) |
625 | { | 594 | { |
626 | Vector3 origDir = m_linearMotorDirection; | 595 | Vector3 origDir = m_linearMotorDirection; // DEBUG |
627 | Vector3 origVel = m_lastLinearVelocityVector; | 596 | Vector3 origVel = m_lastLinearVelocityVector; // DEBUG |
628 | 597 | // DEBUG: the vehicle velocity rotated to be relative to vehicle coordinates for comparison | |
629 | // add drive to body | 598 | Vector3 vehicleVelocity = Prim.ForceVelocity * Quaternion.Inverse(Prim.ForceOrientation); // DEBUG |
630 | // Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale/pTimestep); | 599 | |
631 | Vector3 addAmount = m_linearMotorDirection/(m_linearMotorTimescale); | 600 | // Add (desiredVelocity - lastAppliedVelocity) / howLongItShouldTakeToComplete |
632 | // lastLinearVelocityVector is the current body velocity vector? | 601 | Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/(m_linearMotorTimescale) * pTimestep; |
633 | // RA: Not sure what the *10 is for. A correction for pTimestep? | ||
634 | // m_lastLinearVelocityVector += (addAmount*10); | ||
635 | m_lastLinearVelocityVector += addAmount; | ||
636 | |||
637 | // This will work temporarily, but we really need to compare speed on an axis | ||
638 | // KF: Limit body velocity to applied velocity? | ||
639 | // Limit the velocity vector to less than the last set linear motor direction | ||
640 | if (Math.Abs(m_lastLinearVelocityVector.X) > Math.Abs(m_linearMotorDirectionLASTSET.X)) | ||
641 | m_lastLinearVelocityVector.X = m_linearMotorDirectionLASTSET.X; | ||
642 | if (Math.Abs(m_lastLinearVelocityVector.Y) > Math.Abs(m_linearMotorDirectionLASTSET.Y)) | ||
643 | m_lastLinearVelocityVector.Y = m_linearMotorDirectionLASTSET.Y; | ||
644 | if (Math.Abs(m_lastLinearVelocityVector.Z) > Math.Abs(m_linearMotorDirectionLASTSET.Z)) | ||
645 | m_lastLinearVelocityVector.Z = m_linearMotorDirectionLASTSET.Z; | ||
646 | |||
647 | // decay applied velocity | ||
648 | Vector3 decayfraction = ((Vector3.One/(m_linearMotorDecayTimescale/pTimestep))); | ||
649 | m_linearMotorDirection -= m_linearMotorDirection * decayfraction * 0.5f; | ||
650 | |||
651 | /* | ||
652 | Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/m_linearMotorTimescale; | ||
653 | m_lastLinearVelocityVector += addAmount; | 602 | m_lastLinearVelocityVector += addAmount; |
654 | 603 | ||
655 | float decayfraction = (1.0f - 1.0f / m_linearMotorDecayTimescale); | 604 | float decayFactor = (1.0f / m_linearMotorDecayTimescale) * pTimestep; |
656 | m_linearMotorDirection *= decayfraction; | 605 | m_linearMotorDirection *= (1f - decayFactor); |
606 | |||
607 | // Rotate new object velocity from vehicle relative to world coordinates | ||
608 | m_newVelocity = m_lastLinearVelocityVector * Prim.ForceOrientation; | ||
657 | 609 | ||
658 | */ | 610 | // Apply friction for next time |
611 | Vector3 frictionFactor = (Vector3.One / m_linearFrictionTimescale) * pTimestep; | ||
612 | m_lastLinearVelocityVector *= (Vector3.One - frictionFactor); | ||
659 | 613 | ||
660 | DetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},add={3},decay={4},dir={5},vel={6}", | 614 | VDetailLog("{0},MoveLinear,nonZero,origlmDir={1},origlvVel={2},vehVel={3},add={4},decay={5},frict={6},lmDir={7},lvVec={8},newVel={9}", |
661 | m_prim.LocalID, origDir, origVel, addAmount, decayfraction, m_linearMotorDirection, m_lastLinearVelocityVector); | 615 | Prim.LocalID, origDir, origVel, vehicleVelocity, addAmount, decayFactor, frictionFactor, |
616 | m_linearMotorDirection, m_lastLinearVelocityVector, m_newVelocity); | ||
662 | } | 617 | } |
663 | else | 618 | else |
664 | { | 619 | { |
665 | // if what remains of applied is small, zero it. | 620 | // if what remains of direction is very small, zero it. |
666 | // if (m_lastLinearVelocityVector.ApproxEquals(Vector3.Zero, 0.01f)) | ||
667 | // m_lastLinearVelocityVector = Vector3.Zero; | ||
668 | m_linearMotorDirection = Vector3.Zero; | 621 | m_linearMotorDirection = Vector3.Zero; |
669 | m_lastLinearVelocityVector = Vector3.Zero; | 622 | m_lastLinearVelocityVector = Vector3.Zero; |
670 | } | 623 | m_newVelocity = Vector3.Zero; |
671 | 624 | ||
672 | // convert requested object velocity to world-referenced vector | 625 | VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID); |
673 | Quaternion rotq = m_prim.Orientation; | 626 | } |
674 | m_dir = m_lastLinearVelocityVector * rotq; | ||
675 | 627 | ||
676 | // Add the various forces into m_dir which will be our new direction vector (velocity) | 628 | // m_newVelocity is velocity computed from linear motor in world coordinates |
677 | 629 | ||
678 | // add Gravity and Buoyancy | 630 | // Gravity and Buoyancy |
679 | // KF: So far I have found no good method to combine a script-requested | ||
680 | // .Z velocity and gravity. Therefore only 0g will used script-requested | ||
681 | // .Z velocity. >0g (m_VehicleBuoyancy < 1) will used modified gravity only. | ||
682 | Vector3 grav = Vector3.Zero; | ||
683 | // There is some gravity, make a gravity force vector that is applied after object velocity. | 631 | // There is some gravity, make a gravity force vector that is applied after object velocity. |
684 | // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; | 632 | // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g; |
685 | grav.Z = m_prim.Scene.DefaultGravity.Z * m_prim.Mass * (1f - m_VehicleBuoyancy); | 633 | Vector3 grav = Prim.PhysicsScene.DefaultGravity * (1f - m_VehicleBuoyancy); |
634 | |||
635 | /* | ||
636 | * RA: Not sure why one would do this unless we are hoping external forces are doing gravity, ... | ||
686 | // Preserve the current Z velocity | 637 | // Preserve the current Z velocity |
687 | Vector3 vel_now = m_prim.Velocity; | 638 | Vector3 vel_now = m_prim.Velocity; |
688 | m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity | 639 | m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity |
640 | */ | ||
689 | 641 | ||
690 | Vector3 pos = m_prim.Position; | 642 | Vector3 pos = Prim.ForcePosition; |
691 | Vector3 posChange = pos; | ||
692 | // Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f); | 643 | // Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f); |
693 | double Zchange = Math.Abs(posChange.Z); | ||
694 | if (m_BlockingEndPoint != Vector3.Zero) | ||
695 | { | ||
696 | bool changed = false; | ||
697 | if (pos.X >= (m_BlockingEndPoint.X - (float)1)) | ||
698 | { | ||
699 | pos.X -= posChange.X + 1; | ||
700 | changed = true; | ||
701 | } | ||
702 | if (pos.Y >= (m_BlockingEndPoint.Y - (float)1)) | ||
703 | { | ||
704 | pos.Y -= posChange.Y + 1; | ||
705 | changed = true; | ||
706 | } | ||
707 | if (pos.Z >= (m_BlockingEndPoint.Z - (float)1)) | ||
708 | { | ||
709 | pos.Z -= posChange.Z + 1; | ||
710 | changed = true; | ||
711 | } | ||
712 | if (pos.X <= 0) | ||
713 | { | ||
714 | pos.X += posChange.X + 1; | ||
715 | changed = true; | ||
716 | } | ||
717 | if (pos.Y <= 0) | ||
718 | { | ||
719 | pos.Y += posChange.Y + 1; | ||
720 | changed = true; | ||
721 | } | ||
722 | if (changed) | ||
723 | { | ||
724 | m_prim.Position = pos; | ||
725 | DetailLog("{0},MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}", | ||
726 | m_prim.LocalID, m_BlockingEndPoint, posChange, pos); | ||
727 | } | ||
728 | } | ||
729 | 644 | ||
730 | // If below the terrain, move us above the ground a little. | 645 | // If below the terrain, move us above the ground a little. |
731 | if (pos.Z < m_prim.Scene.GetTerrainHeightAtXYZ(pos)) | 646 | float terrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); |
647 | // Taking the rotated size doesn't work here because m_prim.Size is the size of the root prim and not the linkset. | ||
648 | // TODO: Add a m_prim.LinkSet.Size similar to m_prim.LinkSet.Mass. | ||
649 | // Vector3 rotatedSize = m_prim.Size * m_prim.ForceOrientation; | ||
650 | // if (rotatedSize.Z < terrainHeight) | ||
651 | if (pos.Z < terrainHeight) | ||
732 | { | 652 | { |
733 | pos.Z = m_prim.Scene.GetTerrainHeightAtXYZ(pos) + 2; | 653 | pos.Z = terrainHeight + 2; |
734 | m_prim.Position = pos; | 654 | Prim.ForcePosition = pos; |
735 | DetailLog("{0},MoveLinear,terrainHeight,pos={1}", m_prim.LocalID, pos); | 655 | VDetailLog("{0},MoveLinear,terrainHeight,terrainHeight={1},pos={2}", Prim.LocalID, terrainHeight, pos); |
736 | } | 656 | } |
737 | 657 | ||
738 | // Check if hovering | 658 | // Check if hovering |
739 | if ((m_Hoverflags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0) | 659 | // m_VhoverEfficiency: 0=bouncy, 1=totally damped |
660 | // m_VhoverTimescale: time to achieve height | ||
661 | if ((m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0) | ||
740 | { | 662 | { |
741 | // We should hover, get the target height | 663 | // We should hover, get the target height |
742 | if ((m_Hoverflags & VehicleFlag.HOVER_WATER_ONLY) != 0) | 664 | if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0) |
743 | { | 665 | { |
744 | m_VhoverTargetHeight = m_prim.Scene.GetWaterLevel() + m_VhoverHeight; | 666 | m_VhoverTargetHeight = Prim.PhysicsScene.GetWaterLevelAtXYZ(pos) + m_VhoverHeight; |
745 | } | 667 | } |
746 | if ((m_Hoverflags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0) | 668 | if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0) |
747 | { | 669 | { |
748 | m_VhoverTargetHeight = m_prim.Scene.GetTerrainHeightAtXY(pos.X, pos.Y) + m_VhoverHeight; | 670 | m_VhoverTargetHeight = terrainHeight + m_VhoverHeight; |
749 | } | 671 | } |
750 | if ((m_Hoverflags & VehicleFlag.HOVER_GLOBAL_HEIGHT) != 0) | 672 | if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) != 0) |
751 | { | 673 | { |
752 | m_VhoverTargetHeight = m_VhoverHeight; | 674 | m_VhoverTargetHeight = m_VhoverHeight; |
753 | } | 675 | } |
754 | 676 | ||
755 | if ((m_Hoverflags & VehicleFlag.HOVER_UP_ONLY) != 0) | 677 | if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0) |
756 | { | 678 | { |
757 | // If body is aready heigher, use its height as target height | 679 | // If body is already heigher, use its height as target height |
758 | if (pos.Z > m_VhoverTargetHeight) m_VhoverTargetHeight = pos.Z; | 680 | if (pos.Z > m_VhoverTargetHeight) |
681 | m_VhoverTargetHeight = pos.Z; | ||
759 | } | 682 | } |
760 | if ((m_Hoverflags & VehicleFlag.LOCK_HOVER_HEIGHT) != 0) | 683 | if ((m_flags & VehicleFlag.LOCK_HOVER_HEIGHT) != 0) |
761 | { | 684 | { |
762 | if ((pos.Z - m_VhoverTargetHeight) > .2 || (pos.Z - m_VhoverTargetHeight) < -.2) | 685 | if (Math.Abs(pos.Z - m_VhoverTargetHeight) > 0.2f) |
763 | { | 686 | { |
764 | m_prim.Position = pos; | 687 | pos.Z = m_VhoverTargetHeight; |
688 | Prim.ForcePosition = pos; | ||
765 | } | 689 | } |
766 | } | 690 | } |
767 | else | 691 | else |
768 | { | 692 | { |
769 | float herr0 = pos.Z - m_VhoverTargetHeight; | 693 | float verticalError = pos.Z - m_VhoverTargetHeight; |
694 | // RA: where does the 50 come from? | ||
695 | float verticalCorrectionVelocity = pTimestep * ((verticalError * 50.0f) / m_VhoverTimescale); | ||
770 | // Replace Vertical speed with correction figure if significant | 696 | // Replace Vertical speed with correction figure if significant |
771 | if (Math.Abs(herr0) > 0.01f) | 697 | if (Math.Abs(verticalError) > 0.01f) |
772 | { | 698 | { |
773 | m_dir.Z = -((herr0 * pTimestep * 50.0f) / m_VhoverTimescale); | 699 | m_newVelocity.Z += verticalCorrectionVelocity; |
774 | //KF: m_VhoverEfficiency is not yet implemented | 700 | //KF: m_VhoverEfficiency is not yet implemented |
775 | } | 701 | } |
702 | else if (verticalError < -0.01) | ||
703 | { | ||
704 | m_newVelocity.Z -= verticalCorrectionVelocity; | ||
705 | } | ||
776 | else | 706 | else |
777 | { | 707 | { |
778 | m_dir.Z = 0f; | 708 | m_newVelocity.Z = 0f; |
779 | } | 709 | } |
780 | } | 710 | } |
781 | 711 | ||
782 | DetailLog("{0},MoveLinear,hover,pos={1},dir={2},height={3},target={4}", m_prim.LocalID, pos, m_dir, m_VhoverHeight, m_VhoverTargetHeight); | 712 | VDetailLog("{0},MoveLinear,hover,pos={1},dir={2},height={3},target={4}", Prim.LocalID, pos, m_newVelocity, m_VhoverHeight, m_VhoverTargetHeight); |
783 | |||
784 | // m_VhoverEfficiency = 0f; // 0=boucy, 1=Crit.damped | ||
785 | // m_VhoverTimescale = 0f; // time to acheive height | ||
786 | // pTimestep is time since last frame,in secs | ||
787 | } | 713 | } |
788 | 714 | ||
789 | if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) | 715 | Vector3 posChange = pos - m_lastPositionVector; |
716 | if (m_BlockingEndPoint != Vector3.Zero) | ||
790 | { | 717 | { |
791 | //Start Experimental Values | 718 | bool changed = false; |
792 | if (Zchange > .3) | 719 | if (pos.X >= (m_BlockingEndPoint.X - (float)1)) |
793 | { | 720 | { |
794 | grav.Z = (float)(grav.Z * 3); | 721 | pos.X -= posChange.X + 1; |
722 | changed = true; | ||
795 | } | 723 | } |
796 | if (Zchange > .15) | 724 | if (pos.Y >= (m_BlockingEndPoint.Y - (float)1)) |
797 | { | 725 | { |
798 | grav.Z = (float)(grav.Z * 2); | 726 | pos.Y -= posChange.Y + 1; |
727 | changed = true; | ||
799 | } | 728 | } |
800 | if (Zchange > .75) | 729 | if (pos.Z >= (m_BlockingEndPoint.Z - (float)1)) |
801 | { | 730 | { |
802 | grav.Z = (float)(grav.Z * 1.5); | 731 | pos.Z -= posChange.Z + 1; |
732 | changed = true; | ||
803 | } | 733 | } |
804 | if (Zchange > .05) | 734 | if (pos.X <= 0) |
805 | { | 735 | { |
806 | grav.Z = (float)(grav.Z * 1.25); | 736 | pos.X += posChange.X + 1; |
737 | changed = true; | ||
807 | } | 738 | } |
808 | if (Zchange > .025) | 739 | if (pos.Y <= 0) |
809 | { | 740 | { |
810 | grav.Z = (float)(grav.Z * 1.125); | 741 | pos.Y += posChange.Y + 1; |
742 | changed = true; | ||
811 | } | 743 | } |
812 | float terraintemp = m_prim.Scene.GetTerrainHeightAtXYZ(pos); | 744 | if (changed) |
813 | float postemp = (pos.Z - terraintemp); | ||
814 | if (postemp > 2.5f) | ||
815 | { | 745 | { |
816 | grav.Z = (float)(grav.Z * 1.037125); | 746 | Prim.ForcePosition = pos; |
747 | VDetailLog("{0},MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}", | ||
748 | Prim.LocalID, m_BlockingEndPoint, posChange, pos); | ||
817 | } | 749 | } |
818 | DetailLog("{0},MoveLinear,limitMotorUp,grav={1}", m_prim.LocalID, grav); | ||
819 | //End Experimental Values | ||
820 | } | 750 | } |
821 | if ((m_flags & (VehicleFlag.NO_X)) != 0) | 751 | |
752 | #region downForce | ||
753 | Vector3 downForce = Vector3.Zero; | ||
754 | |||
755 | if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) | ||
822 | { | 756 | { |
823 | m_dir.X = 0; | 757 | // If the vehicle is motoring into the sky, get it going back down. |
758 | // Is this an angular force or both linear and angular?? | ||
759 | float distanceAboveGround = pos.Z - terrainHeight; | ||
760 | if (distanceAboveGround > 2f) | ||
761 | { | ||
762 | // downForce = new Vector3(0, 0, (-distanceAboveGround / m_bankingTimescale) * pTimestep); | ||
763 | // downForce = new Vector3(0, 0, -distanceAboveGround / m_bankingTimescale); | ||
764 | downForce = new Vector3(0, 0, -distanceAboveGround); | ||
765 | } | ||
766 | // TODO: this calculation is all wrong. From the description at | ||
767 | // (http://wiki.secondlife.com/wiki/Category:LSL_Vehicle), the downForce | ||
768 | // has a decay factor. This says this force should | ||
769 | // be computed with a motor. | ||
770 | VDetailLog("{0},MoveLinear,limitMotorUp,distAbove={1},downForce={2}", | ||
771 | Prim.LocalID, distanceAboveGround, downForce); | ||
824 | } | 772 | } |
773 | #endregion // downForce | ||
774 | |||
775 | // If not changing some axis, reduce out velocity | ||
776 | if ((m_flags & (VehicleFlag.NO_X)) != 0) | ||
777 | m_newVelocity.X = 0; | ||
825 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) | 778 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) |
826 | { | 779 | m_newVelocity.Y = 0; |
827 | m_dir.Y = 0; | ||
828 | } | ||
829 | if ((m_flags & (VehicleFlag.NO_Z)) != 0) | 780 | if ((m_flags & (VehicleFlag.NO_Z)) != 0) |
781 | m_newVelocity.Z = 0; | ||
782 | |||
783 | // Clamp REALLY high or low velocities | ||
784 | if (m_newVelocity.LengthSquared() > 1e6f) | ||
830 | { | 785 | { |
831 | m_dir.Z = 0; | 786 | m_newVelocity /= m_newVelocity.Length(); |
787 | m_newVelocity *= 1000f; | ||
832 | } | 788 | } |
789 | else if (m_newVelocity.LengthSquared() < 1e-6f) | ||
790 | m_newVelocity = Vector3.Zero; | ||
833 | 791 | ||
834 | m_lastPositionVector = m_prim.Position; | 792 | // Stuff new linear velocity into the vehicle |
793 | Prim.ForceVelocity = m_newVelocity; | ||
794 | // Prim.ApplyForceImpulse((m_newVelocity - Prim.Velocity) * m_vehicleMass, false); // DEBUG DEBUG | ||
835 | 795 | ||
836 | // Apply velocity | 796 | Vector3 totalDownForce = downForce + grav; |
837 | m_prim.Velocity = m_dir; | 797 | if (totalDownForce != Vector3.Zero) |
838 | // apply gravity force | 798 | { |
839 | // Why is this set here? The physics engine already does gravity. | 799 | Prim.AddForce(totalDownForce * m_vehicleMass, false); |
840 | // m_prim.AddForce(grav, false); | 800 | // Prim.ApplyForceImpulse(totalDownForce * m_vehicleMass, false); |
841 | // m_prim.Force = grav; | 801 | } |
842 | |||
843 | // Apply friction | ||
844 | Vector3 decayamount = Vector3.One / (m_linearFrictionTimescale / pTimestep); | ||
845 | m_lastLinearVelocityVector -= m_lastLinearVelocityVector * decayamount; | ||
846 | 802 | ||
847 | DetailLog("{0},MoveLinear,done,pos={1},vel={2},force={3},decay={4}", | 803 | VDetailLog("{0},MoveLinear,done,lmDir={1},lmVel={2},newVel={3},primVel={4},totalDown={5}", |
848 | m_prim.LocalID, m_lastPositionVector, m_dir, grav, decayamount); | 804 | Prim.LocalID, m_linearMotorDirection, m_lastLinearVelocityVector, m_newVelocity, Prim.Velocity, totalDownForce); |
849 | 805 | ||
850 | } // end MoveLinear() | 806 | } // end MoveLinear() |
851 | 807 | ||
808 | // ======================================================================= | ||
809 | // Apply the effect of the angular motor. | ||
852 | private void MoveAngular(float pTimestep) | 810 | private void MoveAngular(float pTimestep) |
853 | { | 811 | { |
854 | // m_angularMotorDirection // angular velocity requested by LSL motor | 812 | // m_angularMotorDirection // angular velocity requested by LSL motor |
@@ -859,160 +817,263 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
859 | // m_angularFrictionTimescale // body angular velocity decay rate | 817 | // m_angularFrictionTimescale // body angular velocity decay rate |
860 | // m_lastAngularVelocity // what was last applied to body | 818 | // m_lastAngularVelocity // what was last applied to body |
861 | 819 | ||
862 | // Get what the body is doing, this includes 'external' influences | 820 | if (m_angularMotorDirection.LengthSquared() > 0.0001) |
863 | Vector3 angularVelocity = m_prim.RotationalVelocity; | ||
864 | |||
865 | if (m_angularMotorApply > 0) | ||
866 | { | 821 | { |
867 | // Rather than snapping the angular motor velocity from the old value to | 822 | Vector3 origVel = m_angularMotorVelocity; |
868 | // a newly set velocity, this routine steps the value from the previous | 823 | Vector3 origDir = m_angularMotorDirection; |
869 | // value (m_angularMotorVelocity) to the requested value (m_angularMotorDirection). | 824 | |
870 | // There are m_angularMotorApply steps. | 825 | // new velocity += error / ( time to get there / step interval) |
871 | Vector3 origAngularVelocity = m_angularMotorVelocity; | 826 | // requested direction - current vehicle direction |
872 | // ramp up to new value | 827 | m_angularMotorVelocity += (m_angularMotorDirection - m_angularMotorVelocity) / (m_angularMotorTimescale / pTimestep); |
873 | // current velocity += error / (time to get there / step interval) | 828 | // decay requested direction |
874 | // requested speed - last motor speed | 829 | m_angularMotorDirection *= (1.0f - (pTimestep * 1.0f/m_angularMotorDecayTimescale)); |
875 | m_angularMotorVelocity.X += (m_angularMotorDirection.X - m_angularMotorVelocity.X) / (m_angularMotorTimescale / pTimestep); | 830 | |
876 | m_angularMotorVelocity.Y += (m_angularMotorDirection.Y - m_angularMotorVelocity.Y) / (m_angularMotorTimescale / pTimestep); | 831 | VDetailLog("{0},MoveAngular,angularMotorApply,angTScale={1},timeStep={2},origvel={3},origDir={4},vel={5}", |
877 | m_angularMotorVelocity.Z += (m_angularMotorDirection.Z - m_angularMotorVelocity.Z) / (m_angularMotorTimescale / pTimestep); | 832 | Prim.LocalID, m_angularMotorTimescale, pTimestep, origVel, origDir, m_angularMotorVelocity); |
878 | |||
879 | DetailLog("{0},MoveAngular,angularMotorApply,apply={1},origvel={2},dir={3},vel={4}", | ||
880 | m_prim.LocalID,m_angularMotorApply,origAngularVelocity, m_angularMotorDirection, m_angularMotorVelocity); | ||
881 | |||
882 | m_angularMotorApply--; // This is done so that if script request rate is less than phys frame rate the expected | ||
883 | // velocity may still be acheived. | ||
884 | } | 833 | } |
885 | else | 834 | else |
886 | { | 835 | { |
887 | // No motor recently applied, keep the body velocity | 836 | m_angularMotorVelocity = Vector3.Zero; |
888 | // and decay the velocity | 837 | } |
889 | m_angularMotorVelocity -= m_angularMotorVelocity / (m_angularMotorDecayTimescale / pTimestep); | 838 | |
890 | } // end motor section | 839 | #region Vertical attactor |
891 | 840 | ||
892 | // Vertical attractor section | ||
893 | Vector3 vertattr = Vector3.Zero; | 841 | Vector3 vertattr = Vector3.Zero; |
894 | if (m_verticalAttractionTimescale < 300) | 842 | Vector3 deflection = Vector3.Zero; |
843 | Vector3 banking = Vector3.Zero; | ||
844 | |||
845 | // If vertical attaction timescale is reasonable and we applied an angular force last time... | ||
846 | if (m_verticalAttractionTimescale < 300 && m_lastAngularVelocity != Vector3.Zero) | ||
895 | { | 847 | { |
896 | float VAservo = 0.2f / (m_verticalAttractionTimescale * pTimestep); | 848 | float VAservo = pTimestep * 0.2f / m_verticalAttractionTimescale; |
897 | // get present body rotation | 849 | if (Prim.IsColliding) |
898 | Quaternion rotq = m_prim.Orientation; | 850 | VAservo = pTimestep * 0.05f / (m_verticalAttractionTimescale); |
899 | // make a vector pointing up | 851 | |
900 | Vector3 verterr = Vector3.Zero; | 852 | VAservo *= (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency); |
901 | verterr.Z = 1.0f; | 853 | |
902 | // rotate it to Body Angle | 854 | // Create a vector of the vehicle "up" in world coordinates |
903 | verterr = verterr * rotq; | 855 | Vector3 verticalError = Vector3.UnitZ * Prim.ForceOrientation; |
904 | // verterr.X and .Y are the World error ammounts. They are 0 when there is no error (Vehicle Body is 'vertical'), and .Z will be 1. | 856 | // verticalError.X and .Y are the World error amounts. They are 0 when there is no |
905 | // As the body leans to its side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall and .Z will go | 857 | // error (Vehicle Body is 'vertical'), and .Z will be 1. As the body leans to its |
906 | // negative. Similar for tilt and |.Y|. .X and .Y must be modulated to prevent a stable inverted body. | 858 | // side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall |
907 | if (verterr.Z < 0.0f) | 859 | // and .Z will go // negative. Similar for tilt and |.Y|. .X and .Y must be |
860 | // modulated to prevent a stable inverted body. | ||
861 | |||
862 | // Error is 0 (no error) to +/- 2 (max error) | ||
863 | if (verticalError.Z < 0.0f) | ||
908 | { | 864 | { |
909 | verterr.X = 2.0f - verterr.X; | 865 | verticalError.X = 2.0f - verticalError.X; |
910 | verterr.Y = 2.0f - verterr.Y; | 866 | verticalError.Y = 2.0f - verticalError.Y; |
911 | } | 867 | } |
912 | // Error is 0 (no error) to +/- 2 (max error) | 868 | // scale it by VAservo (timestep and timescale) |
913 | // scale it by VAservo | 869 | verticalError = verticalError * VAservo; |
914 | verterr = verterr * VAservo; | 870 | |
915 | 871 | // As the body rotates around the X axis, then verticalError.Y increases; Rotated around Y | |
916 | // As the body rotates around the X axis, then verterr.Y increases; Rotated around Y then .X increases, so | 872 | // then .X increases, so change Body angular velocity X based on Y, and Y based on X. |
917 | // Change Body angular velocity X based on Y, and Y based on X. Z is not changed. | 873 | // Z is not changed. |
918 | vertattr.X = verterr.Y; | 874 | vertattr.X = verticalError.Y; |
919 | vertattr.Y = - verterr.X; | 875 | vertattr.Y = - verticalError.X; |
920 | vertattr.Z = 0f; | 876 | vertattr.Z = 0f; |
921 | 877 | ||
922 | // scaling appears better usingsquare-law | 878 | // scaling appears better usingsquare-law |
879 | Vector3 angularVelocity = Prim.ForceRotationalVelocity; | ||
923 | float bounce = 1.0f - (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency); | 880 | float bounce = 1.0f - (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency); |
924 | vertattr.X += bounce * angularVelocity.X; | 881 | vertattr.X += bounce * angularVelocity.X; |
925 | vertattr.Y += bounce * angularVelocity.Y; | 882 | vertattr.Y += bounce * angularVelocity.Y; |
926 | 883 | ||
927 | DetailLog("{0},MoveAngular,verticalAttraction,verterr={1},bounce={2},vertattr={3}", | 884 | VDetailLog("{0},MoveAngular,verticalAttraction,VAservo={1},effic={2},verticalError={3},bounce={4},vertattr={5}", |
928 | m_prim.LocalID, verterr, bounce, vertattr); | 885 | Prim.LocalID, VAservo, m_verticalAttractionEfficiency, verticalError, bounce, vertattr); |
929 | 886 | ||
930 | } // else vertical attractor is off | 887 | } |
888 | #endregion // Vertical attactor | ||
889 | |||
890 | #region Deflection | ||
891 | |||
892 | if (m_angularDeflectionEfficiency != 0) | ||
893 | { | ||
894 | // Compute a scaled vector that points in the preferred axis (X direction) | ||
895 | Vector3 scaledDefaultDirection = | ||
896 | new Vector3((pTimestep * 10 * (m_angularDeflectionEfficiency / m_angularDeflectionTimescale)), 0, 0); | ||
897 | // Adding the current vehicle orientation and reference frame displaces the orientation to the frame. | ||
898 | // Rotate the scaled default axix relative to the actual vehicle direction giving where it should point. | ||
899 | Vector3 preferredAxisOfMotion = scaledDefaultDirection * Quaternion.Add(Prim.ForceOrientation, m_referenceFrame); | ||
900 | |||
901 | // Scale by efficiency and timescale | ||
902 | deflection = (preferredAxisOfMotion * (m_angularDeflectionEfficiency) / m_angularDeflectionTimescale) * pTimestep; | ||
903 | |||
904 | VDetailLog("{0},MoveAngular,Deflection,perfAxis={1},deflection={2}", | ||
905 | Prim.LocalID, preferredAxisOfMotion, deflection); | ||
906 | // This deflection computation is not correct. | ||
907 | deflection = Vector3.Zero; | ||
908 | } | ||
909 | |||
910 | #endregion | ||
911 | |||
912 | #region Banking | ||
913 | |||
914 | if (m_bankingEfficiency != 0) | ||
915 | { | ||
916 | Vector3 dir = Vector3.One * Prim.ForceOrientation; | ||
917 | float mult = (m_bankingMix*m_bankingMix)*-1*(m_bankingMix < 0 ? -1 : 1); | ||
918 | //Changes which way it banks in and out of turns | ||
931 | 919 | ||
932 | // m_lastVertAttractor = vertattr; | 920 | //Use the square of the efficiency, as it looks much more how SL banking works |
921 | float effSquared = (m_bankingEfficiency*m_bankingEfficiency); | ||
922 | if (m_bankingEfficiency < 0) | ||
923 | effSquared *= -1; //Keep the negative! | ||
933 | 924 | ||
934 | // Bank section tba | 925 | float mix = Math.Abs(m_bankingMix); |
926 | if (m_angularMotorVelocity.X == 0) | ||
927 | { | ||
928 | /*if (!parent.Orientation.ApproxEquals(this.m_referenceFrame, 0.25f)) | ||
929 | { | ||
930 | Vector3 axisAngle; | ||
931 | float angle; | ||
932 | parent.Orientation.GetAxisAngle(out axisAngle, out angle); | ||
933 | Vector3 rotatedVel = parent.Velocity * parent.Orientation; | ||
934 | if ((rotatedVel.X < 0 && axisAngle.Y > 0) || (rotatedVel.X > 0 && axisAngle.Y < 0)) | ||
935 | m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (1f) * 10; | ||
936 | else | ||
937 | m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (-1f) * 10; | ||
938 | }*/ | ||
939 | } | ||
940 | else | ||
941 | banking.Z += (effSquared*(mult*mix))*(m_angularMotorVelocity.X) * 4; | ||
942 | if (!Prim.IsColliding && Math.Abs(m_angularMotorVelocity.X) > mix) | ||
943 | //If they are colliding, we probably shouldn't shove the prim around... probably | ||
944 | { | ||
945 | float angVelZ = m_angularMotorVelocity.X*-1; | ||
946 | /*if(angVelZ > mix) | ||
947 | angVelZ = mix; | ||
948 | else if(angVelZ < -mix) | ||
949 | angVelZ = -mix;*/ | ||
950 | //This controls how fast and how far the banking occurs | ||
951 | Vector3 bankingRot = new Vector3(angVelZ*(effSquared*mult), 0, 0); | ||
952 | if (bankingRot.X > 3) | ||
953 | bankingRot.X = 3; | ||
954 | else if (bankingRot.X < -3) | ||
955 | bankingRot.X = -3; | ||
956 | bankingRot *= Prim.ForceOrientation; | ||
957 | banking += bankingRot; | ||
958 | } | ||
959 | m_angularMotorVelocity.X *= m_bankingEfficiency == 1 ? 0.0f : 1 - m_bankingEfficiency; | ||
960 | VDetailLog("{0},MoveAngular,Banking,bEff={1},angMotVel={2},banking={3}", | ||
961 | Prim.LocalID, m_bankingEfficiency, m_angularMotorVelocity, banking); | ||
962 | } | ||
935 | 963 | ||
936 | // Deflection section tba | 964 | #endregion |
965 | |||
966 | m_lastVertAttractor = vertattr; | ||
937 | 967 | ||
938 | // Sum velocities | 968 | // Sum velocities |
939 | m_lastAngularVelocity = m_angularMotorVelocity + vertattr; // + bank + deflection | 969 | m_lastAngularVelocity = m_angularMotorVelocity + vertattr + banking + deflection; |
940 | 970 | ||
971 | #region Linear Motor Offset | ||
972 | |||
973 | //Offset section | ||
974 | if (m_linearMotorOffset != Vector3.Zero) | ||
975 | { | ||
976 | //Offset of linear velocity doesn't change the linear velocity, | ||
977 | // but causes a torque to be applied, for example... | ||
978 | // | ||
979 | // IIIII >>> IIIII | ||
980 | // IIIII >>> IIIII | ||
981 | // IIIII >>> IIIII | ||
982 | // ^ | ||
983 | // | Applying a force at the arrow will cause the object to move forward, but also rotate | ||
984 | // | ||
985 | // | ||
986 | // The torque created is the linear velocity crossed with the offset | ||
987 | |||
988 | // NOTE: this computation does should be in the linear section | ||
989 | // because there we know the impulse being applied. | ||
990 | Vector3 torqueFromOffset = Vector3.Zero; | ||
991 | // torqueFromOffset = Vector3.Cross(m_linearMotorOffset, appliedImpulse); | ||
992 | if (float.IsNaN(torqueFromOffset.X)) | ||
993 | torqueFromOffset.X = 0; | ||
994 | if (float.IsNaN(torqueFromOffset.Y)) | ||
995 | torqueFromOffset.Y = 0; | ||
996 | if (float.IsNaN(torqueFromOffset.Z)) | ||
997 | torqueFromOffset.Z = 0; | ||
998 | torqueFromOffset *= m_vehicleMass; | ||
999 | Prim.ApplyTorqueImpulse(torqueFromOffset, true); | ||
1000 | VDetailLog("{0},BSDynamic.MoveAngular,motorOffset,applyTorqueImpulse={1}", Prim.LocalID, torqueFromOffset); | ||
1001 | } | ||
1002 | |||
1003 | #endregion | ||
1004 | |||
941 | if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) | 1005 | if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0) |
942 | { | 1006 | { |
943 | m_lastAngularVelocity.X = 0; | 1007 | m_lastAngularVelocity.X = 0; |
944 | m_lastAngularVelocity.Y = 0; | 1008 | m_lastAngularVelocity.Y = 0; |
945 | DetailLog("{0},MoveAngular,noDeflectionUp,lastAngular={1}", m_prim.LocalID, m_lastAngularVelocity); | 1009 | VDetailLog("{0},MoveAngular,noDeflectionUp,lastAngular={1}", Prim.LocalID, m_lastAngularVelocity); |
946 | } | 1010 | } |
947 | 1011 | ||
948 | if (m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f)) | 1012 | if (m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f)) |
949 | { | 1013 | { |
950 | m_lastAngularVelocity = Vector3.Zero; // Reduce small value to zero. | 1014 | m_lastAngularVelocity = Vector3.Zero; // Reduce small value to zero. |
951 | DetailLog("{0},MoveAngular,zeroSmallValues,lastAngular={1}", m_prim.LocalID, m_lastAngularVelocity); | 1015 | Prim.ZeroAngularMotion(true); |
1016 | VDetailLog("{0},MoveAngular,zeroAngularMotion,lastAngular={1}", Prim.LocalID, m_lastAngularVelocity); | ||
1017 | } | ||
1018 | else | ||
1019 | { | ||
1020 | // Apply to the body. | ||
1021 | // The above calculates the absolute angular velocity needed. Angular velocity is massless. | ||
1022 | // Since we are stuffing the angular velocity directly into the object, the computed | ||
1023 | // velocity needs to be scaled by the timestep. | ||
1024 | Vector3 applyAngularForce = ((m_lastAngularVelocity * pTimestep) - Prim.ForceRotationalVelocity); | ||
1025 | Prim.ForceRotationalVelocity = applyAngularForce; | ||
1026 | |||
1027 | // Decay the angular movement for next time | ||
1028 | Vector3 decayamount = (Vector3.One / m_angularFrictionTimescale) * pTimestep; | ||
1029 | m_lastAngularVelocity *= Vector3.One - decayamount; | ||
1030 | |||
1031 | VDetailLog("{0},MoveAngular,done,newRotVel={1},decay={2},lastAngular={3}", | ||
1032 | Prim.LocalID, applyAngularForce, decayamount, m_lastAngularVelocity); | ||
952 | } | 1033 | } |
953 | |||
954 | // apply friction | ||
955 | Vector3 decayamount = Vector3.One / (m_angularFrictionTimescale / pTimestep); | ||
956 | m_lastAngularVelocity -= m_lastAngularVelocity * decayamount; | ||
957 | |||
958 | // Apply to the body | ||
959 | m_prim.RotationalVelocity = m_lastAngularVelocity; | ||
960 | |||
961 | DetailLog("{0},MoveAngular,done,decay={1},lastAngular={2}", m_prim.LocalID, decayamount, m_lastAngularVelocity); | ||
962 | } //end MoveAngular | 1034 | } //end MoveAngular |
963 | 1035 | ||
964 | internal void LimitRotation(float timestep) | 1036 | internal void LimitRotation(float timestep) |
965 | { | 1037 | { |
966 | Quaternion rotq = m_prim.Orientation; | 1038 | Quaternion rotq = Prim.ForceOrientation; |
967 | Quaternion m_rot = rotq; | 1039 | Quaternion m_rot = rotq; |
968 | bool changed = false; | ||
969 | if (m_RollreferenceFrame != Quaternion.Identity) | 1040 | if (m_RollreferenceFrame != Quaternion.Identity) |
970 | { | 1041 | { |
971 | if (rotq.X >= m_RollreferenceFrame.X) | 1042 | if (rotq.X >= m_RollreferenceFrame.X) |
972 | { | 1043 | { |
973 | m_rot.X = rotq.X - (m_RollreferenceFrame.X / 2); | 1044 | m_rot.X = rotq.X - (m_RollreferenceFrame.X / 2); |
974 | changed = true; | ||
975 | } | 1045 | } |
976 | if (rotq.Y >= m_RollreferenceFrame.Y) | 1046 | if (rotq.Y >= m_RollreferenceFrame.Y) |
977 | { | 1047 | { |
978 | m_rot.Y = rotq.Y - (m_RollreferenceFrame.Y / 2); | 1048 | m_rot.Y = rotq.Y - (m_RollreferenceFrame.Y / 2); |
979 | changed = true; | ||
980 | } | 1049 | } |
981 | if (rotq.X <= -m_RollreferenceFrame.X) | 1050 | if (rotq.X <= -m_RollreferenceFrame.X) |
982 | { | 1051 | { |
983 | m_rot.X = rotq.X + (m_RollreferenceFrame.X / 2); | 1052 | m_rot.X = rotq.X + (m_RollreferenceFrame.X / 2); |
984 | changed = true; | ||
985 | } | 1053 | } |
986 | if (rotq.Y <= -m_RollreferenceFrame.Y) | 1054 | if (rotq.Y <= -m_RollreferenceFrame.Y) |
987 | { | 1055 | { |
988 | m_rot.Y = rotq.Y + (m_RollreferenceFrame.Y / 2); | 1056 | m_rot.Y = rotq.Y + (m_RollreferenceFrame.Y / 2); |
989 | changed = true; | ||
990 | } | 1057 | } |
991 | changed = true; | ||
992 | } | 1058 | } |
993 | if ((m_flags & VehicleFlag.LOCK_ROTATION) != 0) | 1059 | if ((m_flags & VehicleFlag.LOCK_ROTATION) != 0) |
994 | { | 1060 | { |
995 | m_rot.X = 0; | 1061 | m_rot.X = 0; |
996 | m_rot.Y = 0; | 1062 | m_rot.Y = 0; |
997 | changed = true; | ||
998 | } | 1063 | } |
999 | if ((m_flags & VehicleFlag.LOCK_ROTATION) != 0) | 1064 | if (rotq != m_rot) |
1000 | { | 1065 | { |
1001 | m_rot.X = 0; | 1066 | Prim.ForceOrientation = m_rot; |
1002 | m_rot.Y = 0; | 1067 | VDetailLog("{0},LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot); |
1003 | changed = true; | ||
1004 | } | 1068 | } |
1005 | if (changed) | ||
1006 | m_prim.Orientation = m_rot; | ||
1007 | 1069 | ||
1008 | DetailLog("{0},LimitRotation,done,changed={1},orig={2},new={3}", m_prim.LocalID, changed, rotq, m_rot); | ||
1009 | } | 1070 | } |
1010 | 1071 | ||
1011 | // Invoke the detailed logger and output something if it's enabled. | 1072 | // Invoke the detailed logger and output something if it's enabled. |
1012 | private void DetailLog(string msg, params Object[] args) | 1073 | private void VDetailLog(string msg, params Object[] args) |
1013 | { | 1074 | { |
1014 | if (m_prim.Scene.VehicleLoggingEnabled) | 1075 | if (Prim.PhysicsScene.VehicleLoggingEnabled) |
1015 | m_prim.Scene.PhysicsLogging.Write(msg, args); | 1076 | Prim.PhysicsScene.DetailLog(msg, args); |
1016 | } | 1077 | } |
1017 | } | 1078 | } |
1018 | } | 1079 | } |