2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
11 [
Editable(MinValueFloat = 0.0f, MaxValueFloat = 10.0f),
13 "For example, if the sprite is stretched up, setting this value above zero would make it do a wave-like movement up and down.")]
26 private List<Vector2[]> deformRows =
new List<Vector2[]>();
43 phase = Rand.Range(0.0f, MathHelper.TwoPi);
47 deformRows.Add(
new Vector2[] { Vector2.Zero, Vector2.Zero });
48 deformRows.Add(
new Vector2[] { Vector2.Zero, Vector2.Zero });
52 for (
int i = 0; ; i++)
54 string row = element.GetAttributeString(
"row" + i,
"");
55 if (
string.IsNullOrWhiteSpace(row))
break;
57 string[] splitRow = row.Split(
' ');
58 Vector2[] rowVectors =
new Vector2[splitRow.Length];
59 for (
int j = 0; j < splitRow.Length; j++)
61 rowVectors[j] = XMLExtensions.ParseVector2(splitRow[j]);
63 deformRows.Add(rowVectors);
67 if (deformRows.Count() == 0 || deformRows.First() ==
null || deformRows.First().Length == 0)
72 var configDeformation =
new Vector2[deformRows.First().Length, deformRows.Count];
73 for (
int x = 0; x < configDeformation.GetLength(0); x++)
75 for (
int y = 0; y < configDeformation.GetLength(1); y++)
77 configDeformation[x, y] = deformRows[y][x];
87 float normalizedX = x / (float)(
Resolution.X - 1);
90 float normalizedY = y / (float)(
Resolution.Y - 1);
92 Point indexTopLeft =
new Point(
93 Math.Min((
int)Math.Floor(normalizedX * (configDeformation.GetLength(0) - 1)), configDeformation.GetLength(0) - 1),
94 Math.Min((
int)Math.Floor(normalizedY * (configDeformation.GetLength(1) - 1)), configDeformation.GetLength(1) - 1));
95 Point indexBottomRight =
new Point(
96 Math.Min(indexTopLeft.X + 1, configDeformation.GetLength(0) - 1),
97 Math.Min(indexTopLeft.Y + 1, configDeformation.GetLength(1) - 1));
99 Vector2 deformTopLeft = configDeformation[indexTopLeft.X, indexTopLeft.Y];
100 Vector2 deformTopRight = configDeformation[indexBottomRight.X, indexTopLeft.Y];
101 Vector2 deformBottomLeft = configDeformation[indexTopLeft.X, indexBottomRight.Y];
102 Vector2 deformBottomRight = configDeformation[indexBottomRight.X, indexBottomRight.Y];
105 Vector2.Lerp(deformTopLeft, deformTopRight, (normalizedX % divX) / divX),
106 Vector2.Lerp(deformBottomLeft, deformBottomRight, (normalizedX % divX) / divX),
107 (normalizedY % divY) / divY);
112 protected override void GetDeformation(out Vector2[,] deformation, out
float multiplier,
bool inverse)
121 public override void Update(
float deltaTime)
126 phase %= MathHelper.TwoPi;
130 public override void Save(XElement element)
133 for (
int i = 0; i < deformRows.Count; i++)
135 element.Add(
new XAttribute(
"row" + i,
string.Join(
" ", deformRows[i].
Select(r => XMLExtensions.Vector2ToString(r)))));