diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/KeyframeMotion.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/KeyframeMotion.cs | 208 |
1 files changed, 120 insertions, 88 deletions
diff --git a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs index f0e639d..902e60b 100644 --- a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs +++ b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs | |||
@@ -1,6 +1,29 @@ | |||
1 | // Proprietary code of Avination Virtual Limited | 1 | /* |
2 | // (c) 2012 Melanie Thielker | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | // | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
4 | 27 | ||
5 | using System; | 28 | using System; |
6 | using System.Timers; | 29 | using System.Timers; |
@@ -32,7 +55,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
32 | private object m_lockObject = new object(); | 55 | private object m_lockObject = new object(); |
33 | private object m_timerLock = new object(); | 56 | private object m_timerLock = new object(); |
34 | private const double m_tickDuration = 50.0; | 57 | private const double m_tickDuration = 50.0; |
35 | private Scene m_scene; | ||
36 | 58 | ||
37 | public double TickDuration | 59 | public double TickDuration |
38 | { | 60 | { |
@@ -46,8 +68,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
46 | m_timer.AutoReset = true; | 68 | m_timer.AutoReset = true; |
47 | m_timer.Elapsed += OnTimer; | 69 | m_timer.Elapsed += OnTimer; |
48 | 70 | ||
49 | m_scene = scene; | ||
50 | |||
51 | m_timer.Start(); | 71 | m_timer.Start(); |
52 | } | 72 | } |
53 | 73 | ||
@@ -71,13 +91,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
71 | { | 91 | { |
72 | m.OnTimer(TickDuration); | 92 | m.OnTimer(TickDuration); |
73 | } | 93 | } |
74 | catch (Exception inner) | 94 | catch (Exception) |
75 | { | 95 | { |
76 | // Don't stop processing | 96 | // Don't stop processing |
77 | } | 97 | } |
78 | } | 98 | } |
79 | } | 99 | } |
80 | catch (Exception e) | 100 | catch (Exception) |
81 | { | 101 | { |
82 | // Keep running no matter what | 102 | // Keep running no matter what |
83 | } | 103 | } |
@@ -134,7 +154,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
134 | [Serializable] | 154 | [Serializable] |
135 | public class KeyframeMotion | 155 | public class KeyframeMotion |
136 | { | 156 | { |
137 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 157 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
138 | 158 | ||
139 | public enum PlayMode : int | 159 | public enum PlayMode : int |
140 | { | 160 | { |
@@ -303,22 +323,25 @@ namespace OpenSim.Region.Framework.Scenes | |||
303 | m_group = grp; | 323 | m_group = grp; |
304 | m_scene = grp.Scene; | 324 | m_scene = grp.Scene; |
305 | 325 | ||
306 | Vector3 grppos = grp.AbsolutePosition; | 326 | lock (m_frames) |
307 | Vector3 offset = grppos - m_serializedPosition; | 327 | { |
308 | // avoid doing it more than once | 328 | Vector3 grppos = grp.AbsolutePosition; |
309 | // current this will happen draging a prim to other region | 329 | Vector3 offset = grppos - m_serializedPosition; |
310 | m_serializedPosition = grppos; | 330 | // avoid doing it more than once |
331 | // current this will happen draging a prim to other region | ||
332 | m_serializedPosition = grppos; | ||
311 | 333 | ||
312 | m_basePosition += offset; | 334 | m_basePosition += offset; |
313 | m_currentFrame.Position += offset; | 335 | m_currentFrame.Position += offset; |
314 | 336 | ||
315 | m_nextPosition += offset; | 337 | m_nextPosition += offset; |
316 | 338 | ||
317 | for (int i = 0; i < m_frames.Count; i++) | 339 | for (int i = 0; i < m_frames.Count; i++) |
318 | { | 340 | { |
319 | Keyframe k = m_frames[i]; | 341 | Keyframe k = m_frames[i]; |
320 | k.Position += offset; | 342 | k.Position += offset; |
321 | m_frames[i]=k; | 343 | m_frames[i] = k; |
344 | } | ||
322 | } | 345 | } |
323 | 346 | ||
324 | if (m_running) | 347 | if (m_running) |
@@ -363,25 +386,28 @@ namespace OpenSim.Region.Framework.Scenes | |||
363 | m_keyframes.CopyTo(newmotion.m_keyframes, 0); | 386 | m_keyframes.CopyTo(newmotion.m_keyframes, 0); |
364 | } | 387 | } |
365 | 388 | ||
366 | newmotion.m_frames = new List<Keyframe>(m_frames); | 389 | lock (m_frames) |
390 | { | ||
391 | newmotion.m_frames = new List<Keyframe>(m_frames); | ||
367 | 392 | ||
368 | newmotion.m_basePosition = m_basePosition; | 393 | newmotion.m_basePosition = m_basePosition; |
369 | newmotion.m_baseRotation = m_baseRotation; | 394 | newmotion.m_baseRotation = m_baseRotation; |
370 | 395 | ||
371 | if (m_selected) | 396 | if (m_selected) |
372 | newmotion.m_serializedPosition = m_serializedPosition; | ||
373 | else | ||
374 | { | ||
375 | if (m_group != null) | ||
376 | newmotion.m_serializedPosition = m_group.AbsolutePosition; | ||
377 | else | ||
378 | newmotion.m_serializedPosition = m_serializedPosition; | 397 | newmotion.m_serializedPosition = m_serializedPosition; |
379 | } | 398 | else |
399 | { | ||
400 | if (m_group != null) | ||
401 | newmotion.m_serializedPosition = m_group.AbsolutePosition; | ||
402 | else | ||
403 | newmotion.m_serializedPosition = m_serializedPosition; | ||
404 | } | ||
380 | 405 | ||
381 | newmotion.m_currentFrame = m_currentFrame; | 406 | newmotion.m_currentFrame = m_currentFrame; |
382 | 407 | ||
383 | newmotion.m_iterations = m_iterations; | 408 | newmotion.m_iterations = m_iterations; |
384 | newmotion.m_running = m_running; | 409 | newmotion.m_running = m_running; |
410 | } | ||
385 | 411 | ||
386 | if (m_running && !m_waitingCrossing) | 412 | if (m_running && !m_waitingCrossing) |
387 | StartTimer(); | 413 | StartTimer(); |
@@ -633,27 +659,29 @@ namespace OpenSim.Region.Framework.Scenes | |||
633 | 659 | ||
634 | if (m_frames.Count == 0) | 660 | if (m_frames.Count == 0) |
635 | { | 661 | { |
636 | GetNextList(); | 662 | lock (m_frames) |
637 | |||
638 | if (m_frames.Count == 0) | ||
639 | { | 663 | { |
640 | Done(); | 664 | GetNextList(); |
641 | Scene scene = m_group.Scene; | ||
642 | 665 | ||
643 | IScriptModule[] scriptModules = scene.RequestModuleInterfaces<IScriptModule>(); | 666 | if (m_frames.Count == 0) |
644 | foreach (IScriptModule m in scriptModules) | ||
645 | { | 667 | { |
646 | if (m == null) | 668 | Done(); |
647 | continue; | 669 | Scene scene = m_group.Scene; |
648 | m.PostObjectEvent(m_group.RootPart.UUID, "moving_end", new object[0]); | ||
649 | } | ||
650 | 670 | ||
651 | return; | 671 | IScriptModule[] scriptModules = scene.RequestModuleInterfaces<IScriptModule>(); |
652 | } | 672 | foreach (IScriptModule m in scriptModules) |
673 | { | ||
674 | if (m == null) | ||
675 | continue; | ||
676 | m.PostObjectEvent(m_group.RootPart.UUID, "moving_end", new object[0]); | ||
677 | } | ||
653 | 678 | ||
654 | m_currentFrame = m_frames[0]; | 679 | return; |
655 | m_currentFrame.TimeMS += (int)tickDuration; | 680 | } |
656 | 681 | ||
682 | m_currentFrame = m_frames[0]; | ||
683 | m_currentFrame.TimeMS += (int)tickDuration; | ||
684 | } | ||
657 | //force a update on a keyframe transition | 685 | //force a update on a keyframe transition |
658 | update = true; | 686 | update = true; |
659 | } | 687 | } |
@@ -662,7 +690,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
662 | 690 | ||
663 | // Do the frame processing | 691 | // Do the frame processing |
664 | double steps = (double)m_currentFrame.TimeMS / tickDuration; | 692 | double steps = (double)m_currentFrame.TimeMS / tickDuration; |
665 | 693 | ||
666 | if (steps <= 0.0) | 694 | if (steps <= 0.0) |
667 | { | 695 | { |
668 | m_group.RootPart.Velocity = Vector3.Zero; | 696 | m_group.RootPart.Velocity = Vector3.Zero; |
@@ -675,9 +703,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
675 | // m_group.UpdateGroupRotationR((Quaternion)m_currentFrame.Rotation); | 703 | // m_group.UpdateGroupRotationR((Quaternion)m_currentFrame.Rotation); |
676 | 704 | ||
677 | m_group.RootPart.RotationOffset = (Quaternion)m_currentFrame.Rotation; | 705 | m_group.RootPart.RotationOffset = (Quaternion)m_currentFrame.Rotation; |
678 | m_frames.RemoveAt(0); | 706 | |
679 | if (m_frames.Count > 0) | 707 | lock (m_frames) |
680 | m_currentFrame = m_frames[0]; | 708 | { |
709 | m_frames.RemoveAt(0); | ||
710 | if (m_frames.Count > 0) | ||
711 | m_currentFrame = m_frames[0]; | ||
712 | } | ||
681 | 713 | ||
682 | update = true; | 714 | update = true; |
683 | } | 715 | } |
@@ -693,7 +725,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
693 | { | 725 | { |
694 | // m_group.AbsolutePosition += motionThisFrame; | 726 | // m_group.AbsolutePosition += motionThisFrame; |
695 | m_nextPosition = m_group.AbsolutePosition + motionThisFrame; | 727 | m_nextPosition = m_group.AbsolutePosition + motionThisFrame; |
696 | m_group.AbsolutePosition = m_nextPosition; | ||
697 | 728 | ||
698 | //m_group.RootPart.Velocity = v; | 729 | //m_group.RootPart.Velocity = v; |
699 | update = true; | 730 | update = true; |
@@ -705,43 +736,43 @@ namespace OpenSim.Region.Framework.Scenes | |||
705 | 736 | ||
706 | Quaternion step = Quaternion.Slerp(m_currentFrame.StartRotation, (Quaternion)m_currentFrame.Rotation, complete); | 737 | Quaternion step = Quaternion.Slerp(m_currentFrame.StartRotation, (Quaternion)m_currentFrame.Rotation, complete); |
707 | step.Normalize(); | 738 | step.Normalize(); |
708 | /* use simpler change detection | 739 | /* use simpler change detection |
709 | * float angle = 0; | 740 | * float angle = 0; |
710 | 741 | ||
711 | float aa = current.X * current.X + current.Y * current.Y + current.Z * current.Z + current.W * current.W; | 742 | float aa = current.X * current.X + current.Y * current.Y + current.Z * current.Z + current.W * current.W; |
712 | float bb = step.X * step.X + step.Y * step.Y + step.Z * step.Z + step.W * step.W; | 743 | float bb = step.X * step.X + step.Y * step.Y + step.Z * step.Z + step.W * step.W; |
713 | float aa_bb = aa * bb; | 744 | float aa_bb = aa * bb; |
714 | 745 | ||
715 | if (aa_bb == 0) | 746 | if (aa_bb == 0) |
716 | { | 747 | { |
717 | angle = 0; | 748 | angle = 0; |
718 | } | 749 | } |
719 | else | 750 | else |
720 | { | 751 | { |
721 | float ab = current.X * step.X + | 752 | float ab = current.X * step.X + |
722 | current.Y * step.Y + | 753 | current.Y * step.Y + |
723 | current.Z * step.Z + | 754 | current.Z * step.Z + |
724 | current.W * step.W; | 755 | current.W * step.W; |
725 | float q = (ab * ab) / aa_bb; | 756 | float q = (ab * ab) / aa_bb; |
726 | 757 | ||
727 | if (q > 1.0f) | 758 | if (q > 1.0f) |
728 | { | 759 | { |
729 | angle = 0; | 760 | angle = 0; |
730 | } | 761 | } |
731 | else | 762 | else |
732 | { | 763 | { |
733 | angle = (float)Math.Acos(2 * q - 1); | 764 | angle = (float)Math.Acos(2 * q - 1); |
734 | } | 765 | } |
735 | } | 766 | } |
736 | 767 | ||
737 | if (angle > 0.01f) | 768 | if (angle > 0.01f) |
738 | */ | 769 | */ |
739 | if (Math.Abs(step.X - current.X) > 0.001f | 770 | if (Math.Abs(step.X - current.X) > 0.001f |
740 | || Math.Abs(step.Y - current.Y) > 0.001f | 771 | || Math.Abs(step.Y - current.Y) > 0.001f |
741 | || Math.Abs(step.Z - current.Z) > 0.001f) | 772 | || Math.Abs(step.Z - current.Z) > 0.001f) |
742 | // assuming w is a dependente var | 773 | // assuming w is a dependente var |
743 | { | 774 | { |
744 | // m_group.UpdateGroupRotationR(step); | 775 | // m_group.UpdateGroupRotationR(step); |
745 | m_group.RootPart.RotationOffset = step; | 776 | m_group.RootPart.RotationOffset = step; |
746 | 777 | ||
747 | //m_group.RootPart.UpdateAngularVelocity(m_currentFrame.AngularVelocity / 2); | 778 | //m_group.RootPart.UpdateAngularVelocity(m_currentFrame.AngularVelocity / 2); |
@@ -752,6 +783,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
752 | 783 | ||
753 | if (update) | 784 | if (update) |
754 | { | 785 | { |
786 | m_group.AbsolutePosition = m_nextPosition; | ||
755 | m_group.SendGroupRootTerseUpdate(); | 787 | m_group.SendGroupRootTerseUpdate(); |
756 | } | 788 | } |
757 | } | 789 | } |