diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/KeyframeMotion.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/KeyframeMotion.cs | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs index ab1e7fa..2d489ea 100644 --- a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs +++ b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs | |||
@@ -180,7 +180,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
180 | [Serializable] | 180 | [Serializable] |
181 | public class KeyframeMotion | 181 | public class KeyframeMotion |
182 | { | 182 | { |
183 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 183 | //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
184 | 184 | ||
185 | public enum PlayMode : int | 185 | public enum PlayMode : int |
186 | { | 186 | { |
@@ -206,6 +206,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
206 | public int TimeMS; | 206 | public int TimeMS; |
207 | public int TimeTotal; | 207 | public int TimeTotal; |
208 | public Vector3 AngularVelocity; | 208 | public Vector3 AngularVelocity; |
209 | public Vector3 StartPosition; | ||
209 | }; | 210 | }; |
210 | 211 | ||
211 | private Vector3 m_serializedPosition; | 212 | private Vector3 m_serializedPosition; |
@@ -279,7 +280,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
279 | if (!m_selected) | 280 | if (!m_selected) |
280 | { | 281 | { |
281 | StopTimer(); | 282 | StopTimer(); |
282 | m_serializedPosition = m_group.AbsolutePosition; | 283 | m_serializedPosition = m_group.AbsolutePosition; |
283 | } | 284 | } |
284 | } | 285 | } |
285 | } | 286 | } |
@@ -344,24 +345,26 @@ namespace OpenSim.Region.Framework.Scenes | |||
344 | return; | 345 | return; |
345 | 346 | ||
346 | m_group = grp; | 347 | m_group = grp; |
347 | m_scene = grp.Scene; | 348 | m_scene = grp.Scene; |
348 | 349 | ||
349 | Vector3 grppos = grp.AbsolutePosition; | 350 | Vector3 grppos = grp.AbsolutePosition; |
350 | Vector3 offset = grppos - m_serializedPosition; | 351 | Vector3 offset = grppos - m_serializedPosition; |
351 | // avoid doing it more than once | 352 | // avoid doing it more than once |
352 | // current this will happen draging a prim to other region | 353 | // current this will happen dragging a prim to other region |
353 | m_serializedPosition = grppos; | 354 | m_serializedPosition = grppos; |
354 | 355 | ||
355 | m_basePosition += offset; | 356 | m_basePosition += offset; |
356 | m_currentFrame.Position += offset; | ||
357 | |||
358 | m_nextPosition += offset; | 357 | m_nextPosition += offset; |
358 | |||
359 | m_currentFrame.StartPosition += offset; | ||
360 | m_currentFrame.Position += offset; | ||
359 | 361 | ||
360 | for (int i = 0; i < m_frames.Count; i++) | 362 | for (int i = 0; i < m_frames.Count; i++) |
361 | { | 363 | { |
362 | Keyframe k = m_frames[i]; | 364 | Keyframe k = m_frames[i]; |
365 | k.StartPosition += offset; | ||
363 | k.Position += offset; | 366 | k.Position += offset; |
364 | m_frames[i]=k; | 367 | m_frames[i]=k; |
365 | } | 368 | } |
366 | 369 | ||
367 | if (m_running) | 370 | if (m_running) |
@@ -513,6 +516,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
513 | { | 516 | { |
514 | Keyframe k = m_keyframes[i]; | 517 | Keyframe k = m_keyframes[i]; |
515 | 518 | ||
519 | k.StartPosition = pos; | ||
516 | if (k.Position.HasValue) | 520 | if (k.Position.HasValue) |
517 | { | 521 | { |
518 | k.Position = (k.Position * direction); | 522 | k.Position = (k.Position * direction); |
@@ -523,7 +527,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
523 | { | 527 | { |
524 | k.Position = pos; | 528 | k.Position = pos; |
525 | // k.Velocity = Vector3.Zero; | 529 | // k.Velocity = Vector3.Zero; |
526 | } | 530 | } |
527 | 531 | ||
528 | k.StartRotation = rot; | 532 | k.StartRotation = rot; |
529 | if (k.Rotation.HasValue) | 533 | if (k.Rotation.HasValue) |
@@ -657,9 +661,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
657 | m_currentFrame.TimeMS -= (int)tickDuration; | 661 | m_currentFrame.TimeMS -= (int)tickDuration; |
658 | 662 | ||
659 | // Do the frame processing | 663 | // Do the frame processing |
660 | double steps = (double)m_currentFrame.TimeMS / tickDuration; | 664 | double remainingSteps = (double)m_currentFrame.TimeMS / tickDuration; |
661 | 665 | ||
662 | if (steps <= 0.0) | 666 | if (remainingSteps <= 0.0) |
663 | { | 667 | { |
664 | m_group.RootPart.Velocity = Vector3.Zero; | 668 | m_group.RootPart.Velocity = Vector3.Zero; |
665 | m_group.RootPart.AngularVelocity = Vector3.Zero; | 669 | m_group.RootPart.AngularVelocity = Vector3.Zero; |
@@ -679,27 +683,30 @@ namespace OpenSim.Region.Framework.Scenes | |||
679 | } | 683 | } |
680 | else | 684 | else |
681 | { | 685 | { |
682 | float complete = ((float)m_currentFrame.TimeTotal - (float)m_currentFrame.TimeMS) / (float)m_currentFrame.TimeTotal; | 686 | float completed = ((float)m_currentFrame.TimeTotal - (float)m_currentFrame.TimeMS) / (float)m_currentFrame.TimeTotal; |
687 | bool lastStep = m_currentFrame.TimeMS <= tickDuration; | ||
688 | |||
689 | Vector3 positionThisStep = m_currentFrame.StartPosition + (m_currentFrame.Position.Value - m_currentFrame.StartPosition) * completed; | ||
690 | Vector3 motionThisStep = positionThisStep - m_group.AbsolutePosition; | ||
683 | 691 | ||
684 | Vector3 v = (Vector3)m_currentFrame.Position - m_group.AbsolutePosition; | 692 | float mag = Vector3.Mag(motionThisStep); |
685 | Vector3 motionThisFrame = v / (float)steps; | ||
686 | v = v * 1000 / m_currentFrame.TimeMS; | ||
687 | 693 | ||
688 | if (Vector3.Mag(motionThisFrame) >= 0.05f) | 694 | if ((mag >= 0.02f) || lastStep) |
689 | { | 695 | { |
690 | // m_group.AbsolutePosition += motionThisFrame; | 696 | m_nextPosition = m_group.AbsolutePosition + motionThisStep; |
691 | m_nextPosition = m_group.AbsolutePosition + motionThisFrame; | ||
692 | m_group.AbsolutePosition = m_nextPosition; | 697 | m_group.AbsolutePosition = m_nextPosition; |
693 | |||
694 | //m_group.RootPart.Velocity = v; | ||
695 | update = true; | 698 | update = true; |
696 | } | 699 | } |
697 | 700 | ||
701 | //int totalSteps = m_currentFrame.TimeTotal / (int)tickDuration; | ||
702 | //m_log.DebugFormat("KeyframeMotion.OnTimer: step {0}/{1}, curPosition={2}, finalPosition={3}, motionThisStep={4} (scene {5})", | ||
703 | // totalSteps - remainingSteps + 1, totalSteps, m_group.AbsolutePosition, m_currentFrame.Position, motionThisStep, m_scene.RegionInfo.RegionName); | ||
704 | |||
698 | if ((Quaternion)m_currentFrame.Rotation != m_group.GroupRotation) | 705 | if ((Quaternion)m_currentFrame.Rotation != m_group.GroupRotation) |
699 | { | 706 | { |
700 | Quaternion current = m_group.GroupRotation; | 707 | Quaternion current = m_group.GroupRotation; |
701 | 708 | ||
702 | Quaternion step = Quaternion.Slerp(m_currentFrame.StartRotation, (Quaternion)m_currentFrame.Rotation, complete); | 709 | Quaternion step = Quaternion.Slerp(m_currentFrame.StartRotation, (Quaternion)m_currentFrame.Rotation, completed); |
703 | step.Normalize(); | 710 | step.Normalize(); |
704 | /* use simpler change detection | 711 | /* use simpler change detection |
705 | * float angle = 0; | 712 | * float angle = 0; |
@@ -734,7 +741,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
734 | */ | 741 | */ |
735 | if(Math.Abs(step.X - current.X) > 0.001f | 742 | if(Math.Abs(step.X - current.X) > 0.001f |
736 | || Math.Abs(step.Y - current.Y) > 0.001f | 743 | || Math.Abs(step.Y - current.Y) > 0.001f |
737 | || Math.Abs(step.Z - current.Z) > 0.001f) | 744 | || Math.Abs(step.Z - current.Z) > 0.001f |
745 | || lastStep) | ||
738 | // assuming w is a dependente var | 746 | // assuming w is a dependente var |
739 | 747 | ||
740 | { | 748 | { |
@@ -760,9 +768,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
760 | 768 | ||
761 | BinaryFormatter fmt = new BinaryFormatter(); | 769 | BinaryFormatter fmt = new BinaryFormatter(); |
762 | SceneObjectGroup tmp = m_group; | 770 | SceneObjectGroup tmp = m_group; |
763 | m_group = null; | 771 | m_group = null; |
764 | if (!m_selected && tmp != null) | 772 | if (!m_selected && tmp != null) |
765 | m_serializedPosition = tmp.AbsolutePosition; | 773 | m_serializedPosition = tmp.AbsolutePosition; |
766 | fmt.Serialize(ms, this); | 774 | fmt.Serialize(ms, this); |
767 | m_group = tmp; | 775 | m_group = tmp; |
768 | if (m_running && !m_waitingCrossing) | 776 | if (m_running && !m_waitingCrossing) |