1 using Microsoft.Xna.Framework;
13 [
Serialize(0.0f,
IsPropertySaveable.Yes, description:
"0 = no falloff, the entire sprite is stretched, 1 = stretching the center of the sprite has no effect at the edges."),
Editable(MinValueFloat = 0.0f, MaxValueFloat = 1.0f)]
32 [
Serialize(0.05f,
IsPropertySaveable.Yes, description:
"How fast the sprite returns back to normal after stretching ends"),
Editable(MinValueFloat = 0.0f, MaxValueFloat = 10.0f)]
57 public override void Update(
float deltaTime)
59 if (positionalDeformationParams.
RecoverSpeed <= 0.0f) {
return; }
77 public void Deform(Vector2 worldPosition, Vector2 amount,
float deltaTime, Matrix transformMatrix)
79 Vector2 pos = Vector2.Transform(worldPosition, transformMatrix);
80 Point deformIndex =
new Point((
int)(pos.X * (
Resolution.X - 1)), (
int)(pos.Y * (
Resolution.Y - 1)));
82 if (deformIndex.X < 0 || deformIndex.Y < 0) {
return; }
85 amount = amount.ClampLength(positionalDeformationParams.
MaxDeformation);
87 float invFalloff = 1.0f - positionalDeformationParams.
Falloff;
91 float normalizedDiffX = Math.Abs(x - deformIndex.X) / (
Resolution.X * 0.5f);
94 float normalizedDiffY = Math.Abs(y - deformIndex.Y) / (
Resolution.Y * 0.5f);
95 Vector2 targetDeformation = amount * MathHelper.Clamp(1.0f -
new Vector2(normalizedDiffX, normalizedDiffY).Length() * positionalDeformationParams.
Falloff, 0.0f, 1.0f);
97 Vector2 diff = targetDeformation -
Deformation[x, y];
103 protected override void GetDeformation(out Vector2[,] deformation, out
float multiplier,
bool inverse)