diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs | 217 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 6 |
2 files changed, 136 insertions, 87 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs index e9e1845..0410150 100644 --- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs +++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Threading; | ||
29 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
30 | using System.Reflection; | 31 | using System.Reflection; |
31 | using log4net; | 32 | using log4net; |
@@ -42,7 +43,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
42 | /// </summary> | 43 | /// </summary> |
43 | public class ScenePresenceAnimator | 44 | public class ScenePresenceAnimator |
44 | { | 45 | { |
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 47 | ||
47 | public AnimationSet Animations | 48 | public AnimationSet Animations |
48 | { | 49 | { |
@@ -57,11 +58,19 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
57 | { | 58 | { |
58 | get { return m_movementAnimation; } | 59 | get { return m_movementAnimation; } |
59 | } | 60 | } |
60 | protected string m_movementAnimation = "DEFAULT"; | 61 | protected string m_movementAnimation = "CROUCH"; |
61 | |||
62 | private int m_animTickFall; | 62 | private int m_animTickFall; |
63 | private int m_animTickJump; | 63 | public int m_animTickJump; // ScenePresence has to see this to control +Z force |
64 | 64 | public bool m_jumping = false; | |
65 | public float m_jumpVelocity = 0f; | ||
66 | private int m_landing = 0; | ||
67 | public bool Falling | ||
68 | { | ||
69 | get { return m_falling; } | ||
70 | } | ||
71 | private bool m_falling = false; | ||
72 | private float m_fallHeight; | ||
73 | |||
65 | /// <value> | 74 | /// <value> |
66 | /// The scene presence that this animator applies to | 75 | /// The scene presence that this animator applies to |
67 | /// </value> | 76 | /// </value> |
@@ -122,7 +131,9 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
122 | 131 | ||
123 | public void ResetAnimations() | 132 | public void ResetAnimations() |
124 | { | 133 | { |
134 | Console.WriteLine("ResetA............."); | ||
125 | m_animations.Clear(); | 135 | m_animations.Clear(); |
136 | TrySetMovementAnimation("STAND"); | ||
126 | } | 137 | } |
127 | 138 | ||
128 | /// <summary> | 139 | /// <summary> |
@@ -152,15 +163,13 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
152 | /// </summary> | 163 | /// </summary> |
153 | public string GetMovementAnimation() | 164 | public string GetMovementAnimation() |
154 | { | 165 | { |
155 | const float FALL_DELAY = 0.33f; | 166 | const float FALL_DELAY = 800f; |
156 | const float PREJUMP_DELAY = 0.25f; | 167 | const float PREJUMP_DELAY = 200f; |
157 | 168 | const float JUMP_PERIOD = 800f; | |
158 | #region Inputs | 169 | #region Inputs |
159 | if (m_scenePresence.SitGround) | 170 | |
160 | { | ||
161 | return "SIT_GROUND_CONSTRAINED"; | ||
162 | } | ||
163 | AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; | 171 | AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; |
172 | // m_log.DebugFormat("[ANIM]: Control flags: {0}", controlFlags); | ||
164 | PhysicsActor actor = m_scenePresence.PhysicsActor; | 173 | PhysicsActor actor = m_scenePresence.PhysicsActor; |
165 | 174 | ||
166 | // Create forward and left vectors from the current avatar rotation | 175 | // Create forward and left vectors from the current avatar rotation |
@@ -169,13 +178,12 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
169 | Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); | 178 | Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); |
170 | 179 | ||
171 | // Check control flags | 180 | // Check control flags |
172 | bool heldForward = | 181 | bool heldForward = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS); |
173 | (((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) || ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS)); | 182 | bool heldBack = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG); |
174 | bool heldBack = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG; | 183 | bool heldLeft = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS); |
175 | bool heldLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS; | 184 | bool heldRight = ((controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG || (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG); |
176 | bool heldRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG; | 185 | //bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT; |
177 | bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT; | 186 | //bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT; |
178 | bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT; | ||
179 | bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; | 187 | bool heldUp = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; |
180 | bool heldDown = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG; | 188 | bool heldDown = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG; |
181 | //bool flying = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY; | 189 | //bool flying = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY; |
@@ -183,17 +191,15 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
183 | 191 | ||
184 | // Direction in which the avatar is trying to move | 192 | // Direction in which the avatar is trying to move |
185 | Vector3 move = Vector3.Zero; | 193 | Vector3 move = Vector3.Zero; |
186 | if (heldForward) { move.X += fwd.X; move.Y += fwd.Y; } | ||
187 | if (heldBack) { move.X -= fwd.X; move.Y -= fwd.Y; } | 194 | if (heldBack) { move.X -= fwd.X; move.Y -= fwd.Y; } |
188 | if (heldLeft) { move.X += left.X; move.Y += left.Y; } | 195 | if (heldLeft) { move.X += left.X; move.Y += left.Y; } |
189 | if (heldRight) { move.X -= left.X; move.Y -= left.Y; } | 196 | if (heldRight) { move.X -= left.X; move.Y -= left.Y; } |
190 | if (heldUp) { move.Z += 1; } | 197 | if (heldUp) { move.Z += 1; } |
191 | if (heldDown) { move.Z -= 1; } | 198 | if (heldDown) { move.Z -= 1; } |
199 | if (heldForward) { move.X += fwd.X; move.Y += fwd.Y; } | ||
192 | 200 | ||
193 | // Is the avatar trying to move? | 201 | // Is the avatar trying to move? |
194 | // bool moving = (move != Vector3.Zero); | 202 | // bool moving = (move != Vector3.Zero); |
195 | bool jumping = m_animTickJump != 0; | ||
196 | |||
197 | #endregion Inputs | 203 | #endregion Inputs |
198 | 204 | ||
199 | #region Flying | 205 | #region Flying |
@@ -202,6 +208,11 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
202 | { | 208 | { |
203 | m_animTickFall = 0; | 209 | m_animTickFall = 0; |
204 | m_animTickJump = 0; | 210 | m_animTickJump = 0; |
211 | m_jumping = false; | ||
212 | m_falling = true; | ||
213 | m_jumpVelocity = 0f; | ||
214 | actor.Selected = false; | ||
215 | m_fallHeight = actor.Position.Z; // save latest flying height | ||
205 | 216 | ||
206 | if (move.X != 0f || move.Y != 0f) | 217 | if (move.X != 0f || move.Y != 0f) |
207 | { | 218 | { |
@@ -213,8 +224,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
213 | } | 224 | } |
214 | else if (move.Z < 0f) | 225 | else if (move.Z < 0f) |
215 | { | 226 | { |
216 | if (actor != null && actor.IsColliding) | 227 | if (actor != null && actor.IsColliding) |
228 | { | ||
217 | return "LAND"; | 229 | return "LAND"; |
230 | } | ||
218 | else | 231 | else |
219 | return "HOVER_DOWN"; | 232 | return "HOVER_DOWN"; |
220 | } | 233 | } |
@@ -228,107 +241,141 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
228 | 241 | ||
229 | #region Falling/Floating/Landing | 242 | #region Falling/Floating/Landing |
230 | 243 | ||
231 | if (actor == null || !actor.IsColliding) | 244 | if ((actor == null || !actor.IsColliding) && !m_jumping) |
232 | { | 245 | { |
233 | float fallElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f; | 246 | float fallElapsed = (float)(Environment.TickCount - m_animTickFall); |
234 | float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f; | 247 | float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f; |
235 | 248 | ||
236 | if (m_animTickFall == 0 || (fallElapsed > FALL_DELAY && fallVelocity >= 0.0f)) | 249 | if (!m_jumping && (fallVelocity < -3.0f) ) m_falling = true; |
250 | |||
251 | if (m_animTickFall == 0 || (fallVelocity >= 0.0f)) | ||
237 | { | 252 | { |
238 | // Just started falling | 253 | // not falling yet, or going up |
254 | // reset start of fall time | ||
239 | m_animTickFall = Environment.TickCount; | 255 | m_animTickFall = Environment.TickCount; |
240 | } | 256 | } |
241 | else if (!jumping && fallElapsed > FALL_DELAY) | 257 | else if (!m_jumping && (fallElapsed > FALL_DELAY) && (fallVelocity < -3.0f) && (m_scenePresence.WasFlying)) |
242 | { | 258 | { |
243 | // Falling long enough to trigger the animation | 259 | // Falling long enough to trigger the animation |
244 | return "FALLDOWN"; | 260 | return "FALLDOWN"; |
245 | } | 261 | } |
246 | else if (m_animTickJump == -1) | ||
247 | { | ||
248 | m_animTickJump = 0; | ||
249 | return "STAND"; | ||
250 | } | ||
251 | 262 | ||
252 | return m_movementAnimation; | 263 | return m_movementAnimation; |
253 | } | 264 | } |
254 | 265 | ||
255 | #endregion Falling/Floating/Landing | 266 | #endregion Falling/Floating/Landing |
256 | 267 | ||
257 | #region Ground Movement | ||
258 | 268 | ||
259 | if (m_movementAnimation == "FALLDOWN") | 269 | #region Jumping // section added for jumping... |
260 | { | ||
261 | m_animTickFall = Environment.TickCount; | ||
262 | 270 | ||
263 | // TODO: SOFT_LAND support | 271 | int jumptime; |
264 | return "LAND"; | 272 | jumptime = Environment.TickCount - m_animTickJump; |
265 | } | 273 | |
266 | else if (m_movementAnimation == "LAND") | 274 | |
275 | if ((move.Z > 0f) && (!m_jumping)) | ||
267 | { | 276 | { |
268 | float landElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f; | 277 | // Start jumping, prejump |
269 | if ((m_animTickFall != 0) && (landElapsed <= FALL_DELAY)) | 278 | m_animTickFall = 0; |
270 | return "LAND"; | 279 | m_jumping = true; |
280 | m_falling = false; | ||
281 | actor.Selected = true; // borrowed for jumping flag | ||
282 | m_animTickJump = Environment.TickCount; | ||
283 | m_jumpVelocity = 0.35f; | ||
284 | return "PREJUMP"; | ||
271 | } | 285 | } |
272 | 286 | ||
273 | m_animTickFall = 0; | 287 | if(m_jumping) |
274 | |||
275 | if (move.Z > 0.2f) | ||
276 | { | 288 | { |
277 | // Jumping | 289 | if ( (jumptime > (JUMP_PERIOD * 1.5f)) && actor.IsColliding) |
278 | if (!jumping) | ||
279 | { | 290 | { |
280 | // Begin prejump | 291 | // end jumping |
281 | m_animTickJump = Environment.TickCount; | 292 | m_jumping = false; |
282 | return "PREJUMP"; | 293 | m_falling = false; |
294 | actor.Selected = false; // borrowed for jumping flag | ||
295 | m_jumpVelocity = 0f; | ||
296 | m_animTickFall = Environment.TickCount; | ||
297 | return "LAND"; | ||
283 | } | 298 | } |
284 | else if (Environment.TickCount - m_animTickJump > PREJUMP_DELAY * 1000.0f) | 299 | else if (jumptime > JUMP_PERIOD) |
285 | { | 300 | { |
286 | // Start actual jump | 301 | // jump down |
287 | if (m_animTickJump == -1) | 302 | m_jumpVelocity = 0f; |
288 | { | ||
289 | // Already jumping! End the current jump | ||
290 | m_animTickJump = 0; | ||
291 | return "JUMP"; | ||
292 | } | ||
293 | |||
294 | m_animTickJump = -1; | ||
295 | return "JUMP"; | 303 | return "JUMP"; |
296 | } | 304 | } |
297 | else | 305 | else if (jumptime > PREJUMP_DELAY) |
306 | { | ||
307 | // jump up | ||
308 | m_jumping = true; | ||
309 | m_jumpVelocity = 10f; | ||
298 | return "JUMP"; | 310 | return "JUMP"; |
311 | } | ||
299 | } | 312 | } |
300 | else | 313 | |
314 | #endregion Jumping | ||
315 | |||
316 | #region Ground Movement | ||
317 | |||
318 | if (m_movementAnimation == "FALLDOWN") | ||
301 | { | 319 | { |
302 | // Not jumping | 320 | m_falling = false; |
303 | m_animTickJump = 0; | 321 | m_animTickFall = Environment.TickCount; |
322 | // TODO: SOFT_LAND support | ||
323 | float fallHeight = m_fallHeight - actor.Position.Z; | ||
324 | if (fallHeight > 15.0f) | ||
325 | return "STANDUP"; | ||
326 | else if (fallHeight > 8.0f) | ||
327 | return "SOFT_LAND"; | ||
328 | else | ||
329 | return "LAND"; | ||
330 | } | ||
331 | else if ((m_movementAnimation == "LAND") || (m_movementAnimation == "SOFT_LAND") || (m_movementAnimation == "STANDUP")) | ||
332 | { | ||
333 | int landElapsed = Environment.TickCount - m_animTickFall; | ||
334 | int limit = 1000; | ||
335 | if(m_movementAnimation == "LAND") limit = 350; | ||
336 | // NB if the above is set too long a weird anim reset from some place prevents STAND from being sent to client | ||
304 | 337 | ||
305 | if (move.X != 0f || move.Y != 0f) | 338 | if ((m_animTickFall != 0) && (landElapsed <= limit)) |
306 | { | 339 | { |
307 | // Walking / crouchwalking / running | 340 | return m_movementAnimation; |
308 | if (move.Z < 0) | ||
309 | return "CROUCHWALK"; | ||
310 | else if (m_scenePresence.SetAlwaysRun) | ||
311 | return "RUN"; | ||
312 | else | ||
313 | return "WALK"; | ||
314 | } | 341 | } |
315 | else | 342 | else |
316 | { | 343 | { |
317 | // Not walking | 344 | m_fallHeight = actor.Position.Z; // save latest flying height |
318 | if (move.Z < 0) | 345 | return "STAND"; |
319 | return "CROUCH"; | ||
320 | else if (heldTurnLeft) | ||
321 | return "TURNLEFT"; | ||
322 | else if (heldTurnRight) | ||
323 | return "TURNRIGHT"; | ||
324 | else | ||
325 | return "STAND"; | ||
326 | } | 346 | } |
327 | } | 347 | } |
328 | 348 | ||
349 | // next section moved outside paren. and realigned for jumping | ||
350 | if (move.X != 0f || move.Y != 0f) | ||
351 | { | ||
352 | m_fallHeight = actor.Position.Z; // save latest flying height | ||
353 | m_falling = false; | ||
354 | // Walking / crouchwalking / running | ||
355 | if (move.Z < 0f) | ||
356 | return "CROUCHWALK"; | ||
357 | else if (m_scenePresence.SetAlwaysRun) | ||
358 | return "RUN"; | ||
359 | else | ||
360 | return "WALK"; | ||
361 | } | ||
362 | else if (!m_jumping) | ||
363 | { | ||
364 | m_falling = false; | ||
365 | // Not walking | ||
366 | if (move.Z < 0) | ||
367 | return "CROUCH"; | ||
368 | // else if (heldTurnLeft) | ||
369 | // return "TURNLEFT"; | ||
370 | // else if (heldTurnRight) | ||
371 | // return "TURNRIGHT"; | ||
372 | else | ||
373 | return "STAND"; | ||
374 | } | ||
329 | #endregion Ground Movement | 375 | #endregion Ground Movement |
330 | 376 | ||
331 | //return m_movementAnimation; | 377 | m_falling = false; |
378 | return m_movementAnimation; | ||
332 | } | 379 | } |
333 | 380 | ||
334 | /// <summary> | 381 | /// <summary> |
@@ -337,8 +384,6 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
337 | public void UpdateMovementAnimations() | 384 | public void UpdateMovementAnimations() |
338 | { | 385 | { |
339 | m_movementAnimation = GetMovementAnimation(); | 386 | m_movementAnimation = GetMovementAnimation(); |
340 | // m_log.DebugFormat( | ||
341 | // "[SCENE PRESENCE ANIMATOR]: Got animation {0} for {1}", m_movementAnimation, m_scenePresence.Name); | ||
342 | TrySetMovementAnimation(m_movementAnimation); | 387 | TrySetMovementAnimation(m_movementAnimation); |
343 | } | 388 | } |
344 | 389 | ||
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index ebb9b0a..287f637 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -2420,7 +2420,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
2420 | // m_log.Info("[AGENT]: Stop Flying"); | 2420 | // m_log.Info("[AGENT]: Stop Flying"); |
2421 | //} | 2421 | //} |
2422 | } | 2422 | } |
2423 | if (!PhysicsActor.Flying && PhysicsActor.IsColliding) | 2423 | if (Animator.Falling && m_wasFlying) // if falling from flying, disable motion add |
2424 | { | ||
2425 | direc *= 0.0f; | ||
2426 | } | ||
2427 | else if (!PhysicsActor.Flying && PhysicsActor.IsColliding) | ||
2424 | { | 2428 | { |
2425 | if (direc.Z > 2.0f) | 2429 | if (direc.Z > 2.0f) |
2426 | { | 2430 | { |