diff options
author | UbitUmarov | 2015-09-01 14:54:35 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 14:54:35 +0100 |
commit | 371c9dd2af01a2e7422ec901ee1f80757284a78c (patch) | |
tree | 058d2a513cacb12efcce0c0df0ae14ad135dbfe2 /OpenSim/Region/Framework/Scenes/KeyframeMotion.cs | |
parent | remove lixo (diff) | |
parent | dont change camera on crossings (diff) | |
download | opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.zip opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.gz opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.bz2 opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.xz |
bad merge?
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/KeyframeMotion.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/KeyframeMotion.cs | 222 |
1 files changed, 189 insertions, 33 deletions
diff --git a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs index 646403f..2b95a4c 100644 --- a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs +++ b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs | |||
@@ -292,14 +292,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
292 | 292 | ||
293 | private void StartTimer() | 293 | private void StartTimer() |
294 | { | 294 | { |
295 | KeyframeTimer.Add(this); | 295 | lock (m_frames) |
296 | m_timerStopped = false; | 296 | { |
297 | KeyframeTimer.Add(this); | ||
298 | m_timerStopped = false; | ||
299 | } | ||
297 | } | 300 | } |
298 | 301 | ||
299 | private void StopTimer() | 302 | private void StopTimer() |
300 | { | 303 | { |
301 | m_timerStopped = true; | 304 | lock (m_frames) |
302 | KeyframeTimer.Remove(this); | 305 | m_timerStopped = true; |
303 | } | 306 | } |
304 | 307 | ||
305 | public static KeyframeMotion FromData(SceneObjectGroup grp, Byte[] data) | 308 | public static KeyframeMotion FromData(SceneObjectGroup grp, Byte[] data) |
@@ -348,6 +351,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
348 | m_group = grp; | 351 | m_group = grp; |
349 | m_scene = grp.Scene; | 352 | m_scene = grp.Scene; |
350 | 353 | ||
354 | <<<<<<< HEAD | ||
351 | Vector3 grppos = grp.AbsolutePosition; | 355 | Vector3 grppos = grp.AbsolutePosition; |
352 | Vector3 offset = grppos - m_serializedPosition; | 356 | Vector3 offset = grppos - m_serializedPosition; |
353 | // avoid doing it more than once | 357 | // avoid doing it more than once |
@@ -366,6 +370,27 @@ namespace OpenSim.Region.Framework.Scenes | |||
366 | k.StartPosition += offset; | 370 | k.StartPosition += offset; |
367 | k.Position += offset; | 371 | k.Position += offset; |
368 | m_frames[i]=k; | 372 | m_frames[i]=k; |
373 | ======= | ||
374 | lock (m_frames) | ||
375 | { | ||
376 | Vector3 grppos = grp.AbsolutePosition; | ||
377 | Vector3 offset = grppos - m_serializedPosition; | ||
378 | // avoid doing it more than once | ||
379 | // current this will happen draging a prim to other region | ||
380 | m_serializedPosition = grppos; | ||
381 | |||
382 | m_basePosition += offset; | ||
383 | m_currentFrame.Position += offset; | ||
384 | |||
385 | m_nextPosition += offset; | ||
386 | |||
387 | for (int i = 0; i < m_frames.Count; i++) | ||
388 | { | ||
389 | Keyframe k = m_frames[i]; | ||
390 | k.Position += offset; | ||
391 | m_frames[i] = k; | ||
392 | } | ||
393 | >>>>>>> avn/ubitvar | ||
369 | } | 394 | } |
370 | 395 | ||
371 | if (m_running) | 396 | if (m_running) |
@@ -410,25 +435,28 @@ namespace OpenSim.Region.Framework.Scenes | |||
410 | m_keyframes.CopyTo(newmotion.m_keyframes, 0); | 435 | m_keyframes.CopyTo(newmotion.m_keyframes, 0); |
411 | } | 436 | } |
412 | 437 | ||
413 | newmotion.m_frames = new List<Keyframe>(m_frames); | 438 | lock (m_frames) |
439 | { | ||
440 | newmotion.m_frames = new List<Keyframe>(m_frames); | ||
414 | 441 | ||
415 | newmotion.m_basePosition = m_basePosition; | 442 | newmotion.m_basePosition = m_basePosition; |
416 | newmotion.m_baseRotation = m_baseRotation; | 443 | newmotion.m_baseRotation = m_baseRotation; |
417 | 444 | ||
418 | if (m_selected) | 445 | if (m_selected) |
419 | newmotion.m_serializedPosition = m_serializedPosition; | ||
420 | else | ||
421 | { | ||
422 | if (m_group != null) | ||
423 | newmotion.m_serializedPosition = m_group.AbsolutePosition; | ||
424 | else | ||
425 | newmotion.m_serializedPosition = m_serializedPosition; | 446 | newmotion.m_serializedPosition = m_serializedPosition; |
426 | } | 447 | else |
448 | { | ||
449 | if (m_group != null) | ||
450 | newmotion.m_serializedPosition = m_group.AbsolutePosition; | ||
451 | else | ||
452 | newmotion.m_serializedPosition = m_serializedPosition; | ||
453 | } | ||
427 | 454 | ||
428 | newmotion.m_currentFrame = m_currentFrame; | 455 | newmotion.m_currentFrame = m_currentFrame; |
429 | 456 | ||
430 | newmotion.m_iterations = m_iterations; | 457 | newmotion.m_iterations = m_iterations; |
431 | newmotion.m_running = m_running; | 458 | newmotion.m_running = m_running; |
459 | } | ||
432 | 460 | ||
433 | if (m_running && !m_waitingCrossing) | 461 | if (m_running && !m_waitingCrossing) |
434 | StartTimer(); | 462 | StartTimer(); |
@@ -458,19 +486,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
458 | } | 486 | } |
459 | else | 487 | else |
460 | { | 488 | { |
461 | m_running = false; | ||
462 | StopTimer(); | 489 | StopTimer(); |
490 | m_running = false; | ||
463 | } | 491 | } |
464 | } | 492 | } |
465 | 493 | ||
466 | public void Stop() | 494 | public void Stop() |
467 | { | 495 | { |
496 | StopTimer(); | ||
468 | m_running = false; | 497 | m_running = false; |
469 | m_isCrossing = false; | 498 | m_isCrossing = false; |
470 | m_waitingCrossing = false; | 499 | m_waitingCrossing = false; |
471 | 500 | ||
472 | StopTimer(); | ||
473 | |||
474 | m_basePosition = m_group.AbsolutePosition; | 501 | m_basePosition = m_group.AbsolutePosition; |
475 | m_baseRotation = m_group.GroupRotation; | 502 | m_baseRotation = m_group.GroupRotation; |
476 | 503 | ||
@@ -483,14 +510,34 @@ namespace OpenSim.Region.Framework.Scenes | |||
483 | 510 | ||
484 | public void Pause() | 511 | public void Pause() |
485 | { | 512 | { |
486 | m_running = false; | ||
487 | StopTimer(); | 513 | StopTimer(); |
514 | m_running = false; | ||
488 | 515 | ||
489 | m_group.RootPart.Velocity = Vector3.Zero; | 516 | m_group.RootPart.Velocity = Vector3.Zero; |
490 | m_group.RootPart.AngularVelocity = Vector3.Zero; | 517 | m_group.RootPart.AngularVelocity = Vector3.Zero; |
491 | m_group.SendGroupRootTerseUpdate(); | 518 | m_group.SendGroupRootTerseUpdate(); |
492 | // m_group.RootPart.ScheduleTerseUpdate(); | 519 | // m_group.RootPart.ScheduleTerseUpdate(); |
520 | } | ||
493 | 521 | ||
522 | public void Suspend() | ||
523 | { | ||
524 | lock (m_frames) | ||
525 | { | ||
526 | if (m_timerStopped) | ||
527 | return; | ||
528 | m_timerStopped = true; | ||
529 | } | ||
530 | } | ||
531 | |||
532 | public void Resume() | ||
533 | { | ||
534 | lock (m_frames) | ||
535 | { | ||
536 | if (!m_timerStopped) | ||
537 | return; | ||
538 | if (m_running && !m_waitingCrossing) | ||
539 | StartTimer(); | ||
540 | } | ||
494 | } | 541 | } |
495 | 542 | ||
496 | private void GetNextList() | 543 | private void GetNextList() |
@@ -581,6 +628,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
581 | 628 | ||
582 | pos = (Vector3)k.Position; | 629 | pos = (Vector3)k.Position; |
583 | rot = (Quaternion)k.Rotation; | 630 | rot = (Quaternion)k.Rotation; |
631 | |||
584 | } | 632 | } |
585 | 633 | ||
586 | m_basePosition = pos; | 634 | m_basePosition = pos; |
@@ -592,15 +640,41 @@ namespace OpenSim.Region.Framework.Scenes | |||
592 | 640 | ||
593 | public void OnTimer(double tickDuration) | 641 | public void OnTimer(double tickDuration) |
594 | { | 642 | { |
643 | if (!Monitor.TryEnter(m_frames)) | ||
644 | return; | ||
645 | if (m_timerStopped) | ||
646 | KeyframeTimer.Remove(this); | ||
647 | else | ||
648 | DoOnTimer(tickDuration); | ||
649 | Monitor.Exit(m_frames); | ||
650 | } | ||
651 | |||
652 | private void Done() | ||
653 | { | ||
654 | KeyframeTimer.Remove(this); | ||
655 | m_timerStopped = true; | ||
656 | m_running = false; | ||
657 | m_isCrossing = false; | ||
658 | m_waitingCrossing = false; | ||
659 | |||
660 | m_basePosition = m_group.AbsolutePosition; | ||
661 | m_baseRotation = m_group.GroupRotation; | ||
662 | |||
663 | m_group.RootPart.Velocity = Vector3.Zero; | ||
664 | m_group.RootPart.AngularVelocity = Vector3.Zero; | ||
665 | m_group.SendGroupRootTerseUpdate(); | ||
666 | // m_group.RootPart.ScheduleTerseUpdate(); | ||
667 | m_frames.Clear(); | ||
668 | } | ||
669 | |||
670 | private void DoOnTimer(double tickDuration) | ||
671 | { | ||
595 | if (m_skipLoops > 0) | 672 | if (m_skipLoops > 0) |
596 | { | 673 | { |
597 | m_skipLoops--; | 674 | m_skipLoops--; |
598 | return; | 675 | return; |
599 | } | 676 | } |
600 | 677 | ||
601 | if (m_timerStopped) // trap events still in air even after a timer.stop | ||
602 | return; | ||
603 | |||
604 | if (m_group == null) | 678 | if (m_group == null) |
605 | return; | 679 | return; |
606 | 680 | ||
@@ -612,7 +686,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
612 | { | 686 | { |
613 | m_group.RootPart.Velocity = Vector3.Zero; | 687 | m_group.RootPart.Velocity = Vector3.Zero; |
614 | m_group.SendGroupRootTerseUpdate(); | 688 | m_group.SendGroupRootTerseUpdate(); |
615 | |||
616 | } | 689 | } |
617 | return; | 690 | return; |
618 | } | 691 | } |
@@ -635,6 +708,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
635 | 708 | ||
636 | if (m_frames.Count == 0) | 709 | if (m_frames.Count == 0) |
637 | { | 710 | { |
711 | <<<<<<< HEAD | ||
638 | if (!m_running) return; | 712 | if (!m_running) return; |
639 | 713 | ||
640 | GetNextList(); | 714 | GetNextList(); |
@@ -656,11 +730,33 @@ namespace OpenSim.Region.Framework.Scenes | |||
656 | 730 | ||
657 | return; | 731 | return; |
658 | } | 732 | } |
733 | ======= | ||
734 | lock (m_frames) | ||
735 | { | ||
736 | GetNextList(); | ||
659 | 737 | ||
660 | m_currentFrame = m_frames[0]; | 738 | if (m_frames.Count == 0) |
661 | m_currentFrame.TimeMS += (int)tickDuration; | 739 | { |
740 | Done(); | ||
741 | Scene scene = m_group.Scene; | ||
662 | 742 | ||
743 | IScriptModule[] scriptModules = scene.RequestModuleInterfaces<IScriptModule>(); | ||
744 | foreach (IScriptModule m in scriptModules) | ||
745 | { | ||
746 | if (m == null) | ||
747 | continue; | ||
748 | m.PostObjectEvent(m_group.RootPart.UUID, "moving_end", new object[0]); | ||
749 | } | ||
750 | >>>>>>> avn/ubitvar | ||
751 | |||
752 | return; | ||
753 | } | ||
754 | |||
755 | m_currentFrame = m_frames[0]; | ||
756 | m_currentFrame.TimeMS += (int)tickDuration; | ||
757 | } | ||
663 | //force a update on a keyframe transition | 758 | //force a update on a keyframe transition |
759 | m_nextPosition = m_group.AbsolutePosition; | ||
664 | update = true; | 760 | update = true; |
665 | } | 761 | } |
666 | 762 | ||
@@ -681,9 +777,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
681 | // m_group.UpdateGroupRotationR((Quaternion)m_currentFrame.Rotation); | 777 | // m_group.UpdateGroupRotationR((Quaternion)m_currentFrame.Rotation); |
682 | 778 | ||
683 | m_group.RootPart.RotationOffset = (Quaternion)m_currentFrame.Rotation; | 779 | m_group.RootPart.RotationOffset = (Quaternion)m_currentFrame.Rotation; |
684 | m_frames.RemoveAt(0); | 780 | |
685 | if (m_frames.Count > 0) | 781 | lock (m_frames) |
686 | m_currentFrame = m_frames[0]; | 782 | { |
783 | m_frames.RemoveAt(0); | ||
784 | if (m_frames.Count > 0) | ||
785 | m_currentFrame = m_frames[0]; | ||
786 | } | ||
687 | 787 | ||
688 | update = true; | 788 | update = true; |
689 | } | 789 | } |
@@ -695,14 +795,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
695 | Vector3 positionThisStep = m_currentFrame.StartPosition + (m_currentFrame.Position.Value - m_currentFrame.StartPosition) * completed; | 795 | Vector3 positionThisStep = m_currentFrame.StartPosition + (m_currentFrame.Position.Value - m_currentFrame.StartPosition) * completed; |
696 | Vector3 motionThisStep = positionThisStep - m_group.AbsolutePosition; | 796 | Vector3 motionThisStep = positionThisStep - m_group.AbsolutePosition; |
697 | 797 | ||
798 | <<<<<<< HEAD | ||
698 | float mag = Vector3.Mag(motionThisStep); | 799 | float mag = Vector3.Mag(motionThisStep); |
699 | 800 | ||
700 | if ((mag >= 0.02f) || lastStep) | 801 | if ((mag >= 0.02f) || lastStep) |
701 | { | 802 | { |
702 | m_nextPosition = m_group.AbsolutePosition + motionThisStep; | 803 | m_nextPosition = m_group.AbsolutePosition + motionThisStep; |
703 | m_group.AbsolutePosition = m_nextPosition; | 804 | m_group.AbsolutePosition = m_nextPosition; |
805 | ======= | ||
806 | m_nextPosition = m_group.AbsolutePosition + motionThisFrame; | ||
807 | |||
808 | if (Vector3.Mag(motionThisFrame) >= 0.05f) | ||
809 | >>>>>>> avn/ubitvar | ||
704 | update = true; | 810 | update = true; |
705 | } | ||
706 | 811 | ||
707 | //int totalSteps = m_currentFrame.TimeTotal / (int)tickDuration; | 812 | //int totalSteps = m_currentFrame.TimeTotal / (int)tickDuration; |
708 | //m_log.DebugFormat("KeyframeMotion.OnTimer: step {0}/{1}, curPosition={2}, finalPosition={3}, motionThisStep={4} (scene {5})", | 813 | //m_log.DebugFormat("KeyframeMotion.OnTimer: step {0}/{1}, curPosition={2}, finalPosition={3}, motionThisStep={4} (scene {5})", |
@@ -714,6 +819,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
714 | 819 | ||
715 | Quaternion step = Quaternion.Slerp(m_currentFrame.StartRotation, (Quaternion)m_currentFrame.Rotation, completed); | 820 | Quaternion step = Quaternion.Slerp(m_currentFrame.StartRotation, (Quaternion)m_currentFrame.Rotation, completed); |
716 | step.Normalize(); | 821 | step.Normalize(); |
822 | <<<<<<< HEAD | ||
717 | /* use simpler change detection | 823 | /* use simpler change detection |
718 | * float angle = 0; | 824 | * float angle = 0; |
719 | 825 | ||
@@ -751,8 +857,45 @@ namespace OpenSim.Region.Framework.Scenes | |||
751 | || lastStep) | 857 | || lastStep) |
752 | // assuming w is a dependente var | 858 | // assuming w is a dependente var |
753 | 859 | ||
860 | ======= | ||
861 | /* use simpler change detection | ||
862 | * float angle = 0; | ||
863 | |||
864 | float aa = current.X * current.X + current.Y * current.Y + current.Z * current.Z + current.W * current.W; | ||
865 | float bb = step.X * step.X + step.Y * step.Y + step.Z * step.Z + step.W * step.W; | ||
866 | float aa_bb = aa * bb; | ||
867 | |||
868 | if (aa_bb == 0) | ||
869 | { | ||
870 | angle = 0; | ||
871 | } | ||
872 | else | ||
873 | { | ||
874 | float ab = current.X * step.X + | ||
875 | current.Y * step.Y + | ||
876 | current.Z * step.Z + | ||
877 | current.W * step.W; | ||
878 | float q = (ab * ab) / aa_bb; | ||
879 | |||
880 | if (q > 1.0f) | ||
881 | { | ||
882 | angle = 0; | ||
883 | } | ||
884 | else | ||
885 | { | ||
886 | angle = (float)Math.Acos(2 * q - 1); | ||
887 | } | ||
888 | } | ||
889 | |||
890 | if (angle > 0.01f) | ||
891 | */ | ||
892 | if (Math.Abs(step.X - current.X) > 0.001f | ||
893 | || Math.Abs(step.Y - current.Y) > 0.001f | ||
894 | || Math.Abs(step.Z - current.Z) > 0.001f) | ||
895 | // assuming w is a dependente var | ||
896 | >>>>>>> avn/ubitvar | ||
754 | { | 897 | { |
755 | // m_group.UpdateGroupRotationR(step); | 898 | // m_group.UpdateGroupRotationR(step); |
756 | m_group.RootPart.RotationOffset = step; | 899 | m_group.RootPart.RotationOffset = step; |
757 | 900 | ||
758 | //m_group.RootPart.UpdateAngularVelocity(m_currentFrame.AngularVelocity / 2); | 901 | //m_group.RootPart.UpdateAngularVelocity(m_currentFrame.AngularVelocity / 2); |
@@ -763,18 +906,31 @@ namespace OpenSim.Region.Framework.Scenes | |||
763 | 906 | ||
764 | if (update) | 907 | if (update) |
765 | { | 908 | { |
909 | m_group.AbsolutePosition = m_nextPosition; | ||
766 | m_group.SendGroupRootTerseUpdate(); | 910 | m_group.SendGroupRootTerseUpdate(); |
767 | } | 911 | } |
768 | } | 912 | } |
769 | 913 | ||
770 | public Byte[] Serialize() | 914 | public Byte[] Serialize() |
771 | { | 915 | { |
916 | bool timerWasStopped; | ||
917 | lock (m_frames) | ||
918 | { | ||
919 | timerWasStopped = m_timerStopped; | ||
920 | } | ||
772 | StopTimer(); | 921 | StopTimer(); |
773 | 922 | ||
774 | SceneObjectGroup tmp = m_group; | 923 | SceneObjectGroup tmp = m_group; |
775 | m_group = null; | 924 | m_group = null; |
776 | if (!m_selected && tmp != null) | 925 | if (!m_selected && tmp != null) |
777 | m_serializedPosition = tmp.AbsolutePosition; | 926 | m_serializedPosition = tmp.AbsolutePosition; |
927 | <<<<<<< HEAD | ||
928 | ======= | ||
929 | fmt.Serialize(ms, this); | ||
930 | m_group = tmp; | ||
931 | if (!timerWasStopped && m_running && !m_waitingCrossing) | ||
932 | StartTimer(); | ||
933 | >>>>>>> avn/ubitvar | ||
778 | 934 | ||
779 | using (MemoryStream ms = new MemoryStream()) | 935 | using (MemoryStream ms = new MemoryStream()) |
780 | { | 936 | { |