/// <summary> /// 将镜头中心平移到指定的区块 /// </summary> /// <param name="r">区块的横向编号,值域[0, 14],其中7是屏幕纵向正中</param> /// <param name="c">区块的纵向编号,值域[0, 32],其中0是屏幕横向正中</param> public static void Translate(int r, int c) { // 计算运动轨迹 var orgPoint = SCamera3D.GetScreenCoordination(SCamera3D.lastFocusRow, SCamera3D.lastFocusCol); var destPoint = SCamera3D.GetScreenCoordination(r, c); var delta = SCamera3D.GetManhattanDistance(destPoint, orgPoint); var actualBeginPoint = ViewManager.View3D.ST3D_Camera.Position; // 动画 Point3DAnimationUsingKeyFrames v3dAni = new Point3DAnimationUsingKeyFrames(); EasingPoint3DKeyFrame k1 = new EasingPoint3DKeyFrame() { Value = new Point3D(actualBeginPoint.X, actualBeginPoint.Y, SCamera3D.lastZIndex), KeyTime = TimeSpan.FromMilliseconds(0), EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; EasingPoint3DKeyFrame k2 = new EasingPoint3DKeyFrame() { Value = new Point3D(actualBeginPoint.X + delta.X, actualBeginPoint.Y + delta.Y, SCamera3D.lastZIndex), KeyTime = TimeSpan.FromMilliseconds(SCamera3D.animationTimeMS), EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; v3dAni.KeyFrames.Add(k1); v3dAni.KeyFrames.Add(k2); v3dAni.FillBehavior = FillBehavior.Stop; AnimationClock aniClock = v3dAni.CreateClock(); lock (SCamera3D.AnimatingStorySet) { SCamera3D.AnimatingStorySet.Add(aniClock); } v3dAni.Completed += delegate { lock (SCamera3D.AnimatingStorySet) { SCamera3D.AnimatingStorySet.Remove(aniClock); } ViewManager.View3D.ST3D_Camera.Position = new Point3D(actualBeginPoint.X + delta.X, actualBeginPoint.Y + delta.Y, SCamera3D.lastZIndex); }; ViewManager.View3D.ST3D_Camera.BeginAnimation(ProjectionCamera.PositionProperty, v3dAni); // 更新后台 Director.ScrMana.SCameraFocusRow = SCamera3D.lastFocusRow = r; Director.ScrMana.SCameraFocusCol = SCamera3D.lastFocusCol = c; Director.ScrMana.SCameraScale = SCamera3D.lastZIndex; }
/// <summary> /// 重置镜头将中央和焦点都对准屏幕中心并采用1.0的对焦比例 /// </summary> /// <param name="doubledDuration">是否2倍动画时间</param> public static void ResetFocus(bool doubledDuration) { int aniTime = doubledDuration ? SCamera3D.animationTimeMS * 2 : SCamera3D.animationTimeMS; var actualBeginPoint = ViewManager.View3D.ST3D_Camera.Position; Point3DAnimationUsingKeyFrames v3dAni = new Point3DAnimationUsingKeyFrames(); EasingPoint3DKeyFrame k1 = new EasingPoint3DKeyFrame() { Value = new Point3D(actualBeginPoint.X, actualBeginPoint.Y, SCamera3D.lastZIndex), KeyTime = TimeSpan.FromMilliseconds(0), EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; EasingPoint3DKeyFrame k2 = new EasingPoint3DKeyFrame() { Value = new Point3D(0, 0, SCamera3D.orginalCameraZIndex), KeyTime = TimeSpan.FromMilliseconds(aniTime), EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; v3dAni.KeyFrames.Add(k1); v3dAni.KeyFrames.Add(k2); v3dAni.FillBehavior = FillBehavior.Stop; AnimationClock aniClock = v3dAni.CreateClock(); lock (SCamera3D.AnimatingStorySet) { SCamera3D.AnimatingStorySet.Add(aniClock); } v3dAni.Completed += delegate { lock (SCamera3D.AnimatingStorySet) { SCamera3D.AnimatingStorySet.Remove(aniClock); } ViewManager.View3D.ST3D_Camera.Position = new Point3D(0, 0, SCamera3D.orginalCameraZIndex); }; ViewManager.View3D.ST3D_Camera.BeginAnimation(ProjectionCamera.PositionProperty, v3dAni); // 更新后台 Director.ScrMana.SCameraFocusRow = SCamera3D.lastFocusRow = GlobalConfigContext.GAME_SCAMERA_SCR_ROWCOUNT / 2; Director.ScrMana.SCameraFocusCol = SCamera3D.lastFocusCol = 0; Director.ScrMana.SCameraScale = SCamera3D.lastZIndex = SCamera3D.orginalCameraZIndex; }
/// <summary> /// 以某个区块为焦点调整焦距 /// </summary> /// <param name="r">区块的横向编号,值域[0, 4],其中2是屏幕纵向正中</param> /// <param name="c">区块的纵向编号,值域[0, 32],其中0是屏幕横向正中</param> /// <param name="ratio">缩放的倍率,值域[0.0, +∞],原始尺寸对应于1.0,原始尺寸指设置中所定义的立绘原始缩放比</param> /// <param name="immediate">是否立即执行完毕</param> public static void FocusOn(int r, int c, double ratio, bool immediate = false) { var aniTime = immediate ? 1 : PreviewSCamera3D.animationTimeMS; // 计算运动轨迹 var orgPoint = PreviewSCamera3D.GetScreenCoordination(PreviewSCamera3D.SCameraFocusRow, PreviewSCamera3D.SCameraFocusCol); var destPoint = PreviewSCamera3D.GetScreenCoordination(r, c); var destZ = PreviewSCamera3D.GetCameraZIndex(ratio); var deltaXY = PreviewSCamera3D.GetManhattanDistance(destPoint, orgPoint); var actualBeginPoint = PreviewSCamera3D.ST3D_Camera.Position; // 动画 Point3DAnimationUsingKeyFrames v3dAni = new Point3DAnimationUsingKeyFrames(); EasingPoint3DKeyFrame k1 = new EasingPoint3DKeyFrame() { Value = new Point3D(actualBeginPoint.X, actualBeginPoint.Y, PreviewSCamera3D.SCameraScale), KeyTime = TimeSpan.FromMilliseconds(0), EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; EasingPoint3DKeyFrame k2 = new EasingPoint3DKeyFrame() { Value = new Point3D(actualBeginPoint.X + deltaXY.X, actualBeginPoint.Y + deltaXY.Y, destZ), KeyTime = TimeSpan.FromMilliseconds(aniTime), EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; v3dAni.KeyFrames.Add(k1); v3dAni.KeyFrames.Add(k2); v3dAni.FillBehavior = FillBehavior.Stop; v3dAni.Completed += delegate { lock (PreviewSCamera3D.AnimatingStorySet) { PreviewSCamera3D.AnimatingStorySet.Remove(v3dAni); } PreviewSCamera3D.ST3D_Camera.Position = new Point3D(actualBeginPoint.X + deltaXY.X, actualBeginPoint.Y + deltaXY.Y, destZ); }; PreviewSCamera3D.ST3D_Camera.BeginAnimation(ProjectionCamera.PositionProperty, v3dAni); // 更新后台 PreviewSCamera3D.SCameraFocusRow = r; PreviewSCamera3D.SCameraFocusCol = c; PreviewSCamera3D.SCameraScale = destZ; }
/// <summary> /// 重置镜头将中央和焦点都对准屏幕中心并采用1.0的对焦比例 /// </summary> /// <param name="doubledDuration">是否2倍动画时间</param> public static void ResetFocus(bool doubledDuration) { int aniTime = doubledDuration ? PreviewSCamera3D.animationTimeMS * 2 : PreviewSCamera3D.animationTimeMS; var actualBeginPoint = PreviewSCamera3D.ST3D_Camera.Position; Point3DAnimationUsingKeyFrames v3dAni = new Point3DAnimationUsingKeyFrames(); EasingPoint3DKeyFrame k1 = new EasingPoint3DKeyFrame() { Value = new Point3D(actualBeginPoint.X, actualBeginPoint.Y, PreviewSCamera3D.SCameraScale), KeyTime = TimeSpan.FromMilliseconds(0), EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; EasingPoint3DKeyFrame k2 = new EasingPoint3DKeyFrame() { Value = new Point3D(0, 0, PreviewSCamera3D.orginalCameraZIndex), KeyTime = TimeSpan.FromMilliseconds(aniTime), EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; v3dAni.KeyFrames.Add(k1); v3dAni.KeyFrames.Add(k2); v3dAni.FillBehavior = FillBehavior.Stop; v3dAni.Completed += delegate { lock (PreviewSCamera3D.AnimatingStorySet) { PreviewSCamera3D.AnimatingStorySet.Remove(v3dAni); } PreviewSCamera3D.ST3D_Camera.Position = new Point3D(0, 0, PreviewSCamera3D.orginalCameraZIndex); }; PreviewSCamera3D.ST3D_Camera.BeginAnimation(ProjectionCamera.PositionProperty, v3dAni); // 更新后台 PreviewSCamera3D.SCameraFocusRow = PreviewSCamera3D.GAME_SCAMERA_SCR_ROWCOUNT / 2; PreviewSCamera3D.SCameraFocusCol = 0; PreviewSCamera3D.SCameraScale = PreviewSCamera3D.orginalCameraZIndex; }