PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/XSpriterPipelineExtensions/ProcessorHelpers.cs

https://bitbucket.org/dylanwolf/xspriter
C# | 114 lines | 93 code | 21 blank | 0 comment | 0 complexity | 3dca39338dc200e68ec90e74146df6eb MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. namespace FuncWorks.XNA.XSpriter
  7. {
  8. static class ProcessorHelpers
  9. {
  10. static public FrameImageContent CloneFrameImage(this FrameImageContent fimg)
  11. {
  12. return fimg.CloneFrameImage(null, null, null);
  13. }
  14. static public FrameImageContent CloneFrameImage(this FrameImageContent fimg, int? zindex, int? timelineId, int? parent)
  15. {
  16. return new FrameImageContent()
  17. {
  18. Angle = fimg.Angle,
  19. Clockwise = fimg.Clockwise,
  20. Pivot = fimg.Pivot,
  21. Position = fimg.Position,
  22. TextureFile = fimg.TextureFile,
  23. TextureFolder = fimg.TextureFolder,
  24. TextureName = fimg.TextureName,
  25. Tweened = fimg.Tweened,
  26. ZIndex = zindex.HasValue ? zindex.Value : fimg.ZIndex,
  27. TimelineId = timelineId.HasValue ? timelineId.Value : fimg.TimelineId,
  28. Parent = parent.HasValue ? parent.Value : fimg.Parent,
  29. Scale = fimg.Scale
  30. };
  31. }
  32. static public Bone CloneBone(this Bone bone)
  33. {
  34. return bone.CloneBone(null, null);
  35. }
  36. static public Bone CloneBone(this Bone bone, int? timelineId, int? parentId)
  37. {
  38. return new Bone()
  39. {
  40. Id = bone.Id,
  41. Parent = parentId.HasValue ? parentId.Value : bone.Parent,
  42. Angle = bone.Angle,
  43. Position = bone.Position,
  44. TimelineId = timelineId.HasValue ? timelineId.Value : bone.TimelineId,
  45. Name = bone.Name,
  46. Clockwise = bone.Clockwise,
  47. Scale = bone.Scale
  48. };
  49. }
  50. static public Vector2 Rotate(this Vector2 position, Vector2 pivot, float angle)
  51. {
  52. Quaternion rot = new Quaternion(pivot.X, pivot.Y, 0, angle);
  53. return Vector2.Transform(position, rot);
  54. }
  55. static public FrameImageContent Tween(this FrameImageContent prev, FrameImageContent next, float pct)
  56. {
  57. FrameImageContent result = new FrameImageContent();
  58. result.TextureFolder = prev.TextureFolder;
  59. result.TextureFile = prev.TextureFile;
  60. result.Clockwise = prev.Clockwise;
  61. result.Pivot = prev.Pivot;
  62. result.Parent = prev.Parent;
  63. result.TimelineId = prev.TimelineId;
  64. result.Scale.X = MathHelper.Lerp(prev.Scale.X, next.Scale.X, pct);
  65. result.Scale.Y = MathHelper.Lerp(prev.Scale.Y, next.Scale.Y, pct);
  66. result.Position.X = MathHelper.Lerp(prev.Position.X, next.Position.X, pct);
  67. result.Position.Y = MathHelper.Lerp(prev.Position.Y, next.Position.Y, pct);
  68. double angleB = prev.Clockwise
  69. ? ((next.Angle - prev.Angle < 0) ? (next.Angle + MathHelper.TwoPi) : next.Angle)
  70. : ((next.Angle - prev.Angle > 0) ? (next.Angle - MathHelper.TwoPi) : next.Angle);
  71. result.Angle = MathHelper.Lerp(prev.Angle, (float)angleB, pct);
  72. return result;
  73. }
  74. static public Bone Tween(this Bone prev, Bone next, float pct)
  75. {
  76. Bone result = new Bone();
  77. result.Clockwise = prev.Clockwise;
  78. result.Id = prev.Id;
  79. result.Parent = prev.Parent;
  80. result.TimelineId = prev.TimelineId;
  81. result.Name = prev.Name;
  82. result.Position.X = MathHelper.Lerp(prev.Position.X, next.Position.X, pct);
  83. result.Position.Y = MathHelper.Lerp(prev.Position.Y, next.Position.Y, pct);
  84. result.Scale.X = MathHelper.Lerp(prev.Scale.X, next.Scale.X, pct);
  85. result.Scale.Y = MathHelper.Lerp(prev.Scale.Y, next.Scale.Y, pct);
  86. double angleB = prev.Clockwise
  87. ? ((next.Angle - prev.Angle < 0) ? (next.Angle + MathHelper.TwoPi) : next.Angle)
  88. : ((next.Angle - prev.Angle > 0) ? (next.Angle - MathHelper.TwoPi) : next.Angle);
  89. result.Angle = MathHelper.Lerp(prev.Angle, (float)angleB, pct);
  90. return result;
  91. }
  92. }
  93. }