diff options
author | UbitUmarov | 2014-09-29 20:17:05 +0100 |
---|---|---|
committer | UbitUmarov | 2014-09-29 20:17:05 +0100 |
commit | 3052a5388954592861e0a55681844115485b6ae7 (patch) | |
tree | fa3fafcc33826448978f27e71bdf9151a755b23a /OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs | |
parent | change permitions again (diff) | |
download | opensim-SC_OLD-3052a5388954592861e0a55681844115485b6ae7.zip opensim-SC_OLD-3052a5388954592861e0a55681844115485b6ae7.tar.gz opensim-SC_OLD-3052a5388954592861e0a55681844115485b6ae7.tar.bz2 opensim-SC_OLD-3052a5388954592861e0a55681844115485b6ae7.tar.xz |
change avatar physics and motion control. Still not that good :(
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs | 147 |
1 files changed, 99 insertions, 48 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs index db3b834..6003e92 100644 --- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs +++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs | |||
@@ -56,11 +56,13 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
56 | /// The current movement animation | 56 | /// The current movement animation |
57 | /// </value> | 57 | /// </value> |
58 | public string CurrentMovementAnimation { get; private set; } | 58 | public string CurrentMovementAnimation { get; private set; } |
59 | 59 | ||
60 | private int m_animTickFall; | 60 | private int m_animTickFall; |
61 | public int m_animTickJump; // ScenePresence has to see this to control +Z force | 61 | private int m_animTickLand; |
62 | private int m_animTickJump; | ||
63 | |||
62 | public bool m_jumping = false; | 64 | public bool m_jumping = false; |
63 | public float m_jumpVelocity = 0f; | 65 | |
64 | // private int m_landing = 0; | 66 | // private int m_landing = 0; |
65 | 67 | ||
66 | /// <summary> | 68 | /// <summary> |
@@ -68,7 +70,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
68 | /// </summary> | 70 | /// </summary> |
69 | public bool Falling { get; private set; } | 71 | public bool Falling { get; private set; } |
70 | 72 | ||
71 | private float m_fallHeight; | 73 | private float m_lastFallVelocity; |
72 | 74 | ||
73 | /// <value> | 75 | /// <value> |
74 | /// The scene presence that this animator applies to | 76 | /// The scene presence that this animator applies to |
@@ -205,7 +207,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
205 | 207 | ||
206 | if (aoSitGndAnim != UUID.Zero) | 208 | if (aoSitGndAnim != UUID.Zero) |
207 | { | 209 | { |
208 | avnChangeAnim(aoSitGndAnim, false, false); | 210 | avnChangeAnim(aoSitGndAnim, false, true); |
209 | aoSitGndAnim = UUID.Zero; | 211 | aoSitGndAnim = UUID.Zero; |
210 | } | 212 | } |
211 | 213 | ||
@@ -258,20 +260,38 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
258 | return ret; | 260 | return ret; |
259 | } | 261 | } |
260 | 262 | ||
263 | public enum motionControlStates : byte | ||
264 | { | ||
265 | sitted = 0, | ||
266 | flying, | ||
267 | falling, | ||
268 | jumping, | ||
269 | landing, | ||
270 | onsurface | ||
271 | } | ||
272 | |||
273 | public motionControlStates currentControlState = motionControlStates.onsurface; | ||
274 | |||
261 | /// <summary> | 275 | /// <summary> |
262 | /// This method determines the proper movement related animation | 276 | /// This method determines the proper movement related animation |
263 | /// </summary> | 277 | /// </summary> |
264 | private string DetermineMovementAnimation() | 278 | private string DetermineMovementAnimation() |
265 | { | 279 | { |
266 | const float FALL_DELAY = 800f; | 280 | const int FALL_DELAY = 800; |
267 | const float PREJUMP_DELAY = 200f; | 281 | const int PREJUMP_DELAY = 200; |
268 | const float JUMP_PERIOD = 800f; | 282 | const int JUMP_PERIOD = 800; |
269 | #region Inputs | 283 | #region Inputs |
270 | 284 | ||
271 | if (m_scenePresence.SitGround) | 285 | if (m_scenePresence.SitGround) |
286 | { | ||
287 | currentControlState = motionControlStates.sitted; | ||
272 | return "SITGROUND"; | 288 | return "SITGROUND"; |
289 | } | ||
273 | if (m_scenePresence.ParentID != 0 || m_scenePresence.ParentUUID != UUID.Zero) | 290 | if (m_scenePresence.ParentID != 0 || m_scenePresence.ParentUUID != UUID.Zero) |
291 | { | ||
292 | currentControlState = motionControlStates.sitted; | ||
274 | return "SIT"; | 293 | return "SIT"; |
294 | } | ||
275 | 295 | ||
276 | AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; | 296 | AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; |
277 | PhysicsActor actor = m_scenePresence.PhysicsActor; | 297 | PhysicsActor actor = m_scenePresence.PhysicsActor; |
@@ -311,17 +331,31 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
311 | // bool moving = (move != Vector3.Zero); | 331 | // bool moving = (move != Vector3.Zero); |
312 | #endregion Inputs | 332 | #endregion Inputs |
313 | 333 | ||
334 | // no physics actor case | ||
335 | if (actor == null) | ||
336 | { | ||
337 | // well what to do? | ||
338 | |||
339 | currentControlState = motionControlStates.onsurface; | ||
340 | if (move.X != 0f || move.Y != 0f) | ||
341 | return "WALK"; | ||
342 | |||
343 | return "STAND"; | ||
344 | } | ||
345 | |||
346 | |||
314 | #region Flying | 347 | #region Flying |
315 | 348 | ||
316 | if (actor != null && actor.Flying) | 349 | bool isColliding = actor.IsColliding; |
350 | |||
351 | if (actor.Flying) | ||
317 | { | 352 | { |
318 | m_animTickFall = 0; | 353 | m_animTickFall = 0; |
319 | m_animTickJump = 0; | 354 | m_animTickJump = 0; |
320 | m_jumping = false; | 355 | m_jumping = false; |
321 | Falling = false; | 356 | Falling = false; |
322 | m_jumpVelocity = 0f; | 357 | |
323 | actor.Selected = false; | 358 | currentControlState = motionControlStates.flying; |
324 | m_fallHeight = actor.Position.Z; // save latest flying height | ||
325 | 359 | ||
326 | if (move.X != 0f || move.Y != 0f) | 360 | if (move.X != 0f || move.Y != 0f) |
327 | { | 361 | { |
@@ -333,8 +367,13 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
333 | } | 367 | } |
334 | else if (move.Z < 0f) | 368 | else if (move.Z < 0f) |
335 | { | 369 | { |
336 | if (actor != null && actor.IsColliding) | 370 | if (isColliding) |
371 | { | ||
372 | actor.Flying = false; | ||
373 | currentControlState = motionControlStates.landing; | ||
374 | m_animTickLand = Environment.TickCount; | ||
337 | return "LAND"; | 375 | return "LAND"; |
376 | } | ||
338 | else | 377 | else |
339 | return "HOVER_DOWN"; | 378 | return "HOVER_DOWN"; |
340 | } | 379 | } |
@@ -343,29 +382,41 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
343 | return "HOVER"; | 382 | return "HOVER"; |
344 | } | 383 | } |
345 | } | 384 | } |
385 | else | ||
386 | { | ||
387 | if (isColliding && currentControlState == motionControlStates.flying) | ||
388 | { | ||
389 | currentControlState = motionControlStates.landing; | ||
390 | m_animTickLand = Environment.TickCount; | ||
391 | return "LAND"; | ||
392 | } | ||
393 | } | ||
346 | 394 | ||
347 | #endregion Flying | 395 | #endregion Flying |
348 | 396 | ||
349 | #region Falling/Floating/Landing | 397 | #region Falling/Floating/Landing |
350 | 398 | ||
351 | if ((actor == null || !actor.IsColliding) && !m_jumping) | 399 | if (!isColliding && currentControlState != motionControlStates.jumping) |
352 | { | 400 | { |
353 | float fallElapsed = (float)(Environment.TickCount - m_animTickFall); | 401 | float fallVelocity = actor.Velocity.Z; |
354 | float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f; | ||
355 | 402 | ||
356 | if (!m_jumping && (fallVelocity < -3.0f)) | 403 | if (fallVelocity < -2.5f) |
357 | Falling = true; | 404 | Falling = true; |
358 | 405 | ||
359 | if (m_animTickFall == 0 || (fallVelocity >= 0.0f)) | 406 | if (m_animTickFall == 0 || (fallVelocity >= -0.5f)) |
360 | { | 407 | { |
361 | // not falling yet, or going up | ||
362 | // reset start of fall time | ||
363 | m_animTickFall = Environment.TickCount; | 408 | m_animTickFall = Environment.TickCount; |
364 | } | 409 | } |
365 | else if (!m_jumping && (fallElapsed > FALL_DELAY) && (fallVelocity < -3.0f) && (m_scenePresence.WasFlying)) | 410 | else |
366 | { | 411 | { |
367 | // Falling long enough to trigger the animation | 412 | int fallElapsed = (Environment.TickCount - m_animTickFall); |
368 | return "FALLDOWN"; | 413 | if ((fallElapsed > FALL_DELAY) && (fallVelocity < -3.0f)) |
414 | { | ||
415 | currentControlState = motionControlStates.falling; | ||
416 | m_lastFallVelocity = fallVelocity; | ||
417 | // Falling long enough to trigger the animation | ||
418 | return "FALLDOWN"; | ||
419 | } | ||
369 | } | 420 | } |
370 | 421 | ||
371 | // Check if the user has stopped walking just now | 422 | // Check if the user has stopped walking just now |
@@ -375,49 +426,44 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
375 | return CurrentMovementAnimation; | 426 | return CurrentMovementAnimation; |
376 | } | 427 | } |
377 | 428 | ||
378 | #endregion Falling/Floating/Landing | 429 | m_animTickFall = 0; |
379 | 430 | ||
431 | #endregion Falling/Floating/Landing | ||
380 | 432 | ||
381 | #region Jumping // section added for jumping... | 433 | #region Jumping // section added for jumping... |
382 | 434 | ||
383 | int jumptime; | 435 | if (isColliding && move.Z > 0f && currentControlState != motionControlStates.jumping) |
384 | jumptime = Environment.TickCount - m_animTickJump; | ||
385 | |||
386 | if ((move.Z > 0f) && (!m_jumping)) | ||
387 | { | 436 | { |
388 | // Start jumping, prejump | 437 | // Start jumping, prejump |
389 | m_animTickFall = 0; | 438 | currentControlState = motionControlStates.jumping; |
390 | m_jumping = true; | 439 | m_jumping = true; |
391 | Falling = false; | 440 | Falling = false; |
392 | actor.Selected = true; // borrowed for jumping flag | ||
393 | m_animTickJump = Environment.TickCount; | 441 | m_animTickJump = Environment.TickCount; |
394 | m_jumpVelocity = 0.35f; | ||
395 | return "PREJUMP"; | 442 | return "PREJUMP"; |
396 | } | 443 | } |
397 | 444 | ||
398 | if (m_jumping) | 445 | if (currentControlState == motionControlStates.jumping) |
399 | { | 446 | { |
447 | int jumptime = Environment.TickCount - m_animTickJump; | ||
400 | if ((jumptime > (JUMP_PERIOD * 1.5f)) && actor.IsColliding) | 448 | if ((jumptime > (JUMP_PERIOD * 1.5f)) && actor.IsColliding) |
401 | { | 449 | { |
402 | // end jumping | 450 | // end jumping |
403 | m_jumping = false; | 451 | m_jumping = false; |
404 | Falling = false; | 452 | Falling = false; |
405 | actor.Selected = false; // borrowed for jumping flag | 453 | actor.Selected = false; // borrowed for jumping flag |
406 | m_jumpVelocity = 0f; | 454 | m_animTickLand = Environment.TickCount; |
407 | m_animTickFall = Environment.TickCount; | 455 | currentControlState = motionControlStates.landing; |
408 | return "LAND"; | 456 | return "LAND"; |
409 | } | 457 | } |
410 | else if (jumptime > JUMP_PERIOD) | 458 | else if (jumptime > JUMP_PERIOD) |
411 | { | 459 | { |
412 | // jump down | 460 | // jump down |
413 | m_jumpVelocity = 0f; | ||
414 | return "JUMP"; | 461 | return "JUMP"; |
415 | } | 462 | } |
416 | else if (jumptime > PREJUMP_DELAY) | 463 | else if (jumptime > PREJUMP_DELAY) |
417 | { | 464 | { |
418 | // jump up | 465 | // jump up |
419 | m_jumping = true; | 466 | m_jumping = true; |
420 | m_jumpVelocity = 10f; | ||
421 | return "JUMP"; | 467 | return "JUMP"; |
422 | } | 468 | } |
423 | } | 469 | } |
@@ -426,42 +472,48 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
426 | 472 | ||
427 | #region Ground Movement | 473 | #region Ground Movement |
428 | 474 | ||
429 | if (CurrentMovementAnimation == "FALLDOWN") | 475 | if (currentControlState == motionControlStates.falling) |
430 | { | 476 | { |
431 | Falling = false; | 477 | Falling = false; |
432 | m_animTickFall = Environment.TickCount; | 478 | currentControlState = motionControlStates.landing; |
479 | m_animTickLand = Environment.TickCount; | ||
433 | // TODO: SOFT_LAND support | 480 | // TODO: SOFT_LAND support |
434 | float fallHeight = m_fallHeight - actor.Position.Z; | 481 | float fallVsq =m_lastFallVelocity*m_lastFallVelocity; |
435 | if (fallHeight > 15.0f) | 482 | if (fallVsq > 300f) // aprox 20*h |
436 | return "STANDUP"; | 483 | return "STANDUP"; |
437 | else if (fallHeight > 8.0f) | 484 | else if (fallVsq > 160f) |
438 | return "SOFT_LAND"; | 485 | return "SOFT_LAND"; |
439 | else | 486 | else |
440 | return "LAND"; | 487 | return "LAND"; |
441 | } | 488 | } |
442 | else if ((CurrentMovementAnimation == "LAND") || (CurrentMovementAnimation == "SOFT_LAND") || (CurrentMovementAnimation == "STANDUP")) | 489 | |
490 | |||
491 | if (currentControlState == motionControlStates.landing) | ||
443 | { | 492 | { |
444 | int landElapsed = Environment.TickCount - m_animTickFall; | 493 | Falling = false; |
494 | int landElapsed = Environment.TickCount - m_animTickLand; | ||
445 | int limit = 1000; | 495 | int limit = 1000; |
446 | if (CurrentMovementAnimation == "LAND") | 496 | if (CurrentMovementAnimation == "LAND") |
447 | limit = 350; | 497 | limit = 350; |
448 | // NB if the above is set too long a weird anim reset from some place prevents STAND from being sent to client | 498 | // NB if the above is set too long a weird anim reset from some place prevents STAND from being sent to client |
449 | 499 | ||
450 | if ((m_animTickFall != 0) && (landElapsed <= limit)) | 500 | if ((m_animTickLand != 0) && (landElapsed <= limit)) |
451 | { | 501 | { |
452 | return CurrentMovementAnimation; | 502 | return CurrentMovementAnimation; |
453 | } | 503 | } |
454 | else | 504 | else |
455 | { | 505 | { |
456 | m_fallHeight = actor.Position.Z; // save latest flying height | 506 | currentControlState = motionControlStates.onsurface; |
507 | m_animTickLand = 0; | ||
457 | return "STAND"; | 508 | return "STAND"; |
458 | } | 509 | } |
459 | } | 510 | } |
460 | 511 | ||
512 | |||
461 | // next section moved outside paren. and realigned for jumping | 513 | // next section moved outside paren. and realigned for jumping |
462 | if (move.X != 0f || move.Y != 0f) | 514 | if (move.X != 0f || move.Y != 0f) |
463 | { | 515 | { |
464 | m_fallHeight = actor.Position.Z; // save latest flying height | 516 | currentControlState = motionControlStates.onsurface; |
465 | Falling = false; | 517 | Falling = false; |
466 | // Walking / crouchwalking / running | 518 | // Walking / crouchwalking / running |
467 | if (move.Z < 0f) | 519 | if (move.Z < 0f) |
@@ -480,6 +532,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
480 | } | 532 | } |
481 | else if (!m_jumping) | 533 | else if (!m_jumping) |
482 | { | 534 | { |
535 | currentControlState = motionControlStates.onsurface; | ||
483 | Falling = false; | 536 | Falling = false; |
484 | // Not walking | 537 | // Not walking |
485 | if (move.Z < 0) | 538 | if (move.Z < 0) |
@@ -493,8 +546,6 @@ namespace OpenSim.Region.Framework.Scenes.Animation | |||
493 | } | 546 | } |
494 | #endregion Ground Movement | 547 | #endregion Ground Movement |
495 | 548 | ||
496 | Falling = false; | ||
497 | |||
498 | return CurrentMovementAnimation; | 549 | return CurrentMovementAnimation; |
499 | } | 550 | } |
500 | 551 | ||