Skip to content

Commit

Permalink
[Mono] Rename LinearInterpolate to Lerp
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Apr 29, 2020
1 parent 10273e9 commit ad3c3e1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 24 deletions.
28 changes: 19 additions & 9 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,26 @@ public Color Lightened(float amount)
return res;
}

public Color LinearInterpolate(Color c, float t)
{
var res = this;

res.r += t * (c.r - r);
res.g += t * (c.g - g);
res.b += t * (c.b - b);
res.a += t * (c.a - a);
public Color Lerp(Color to, float weight)
{
return new Color
(
Mathf.Lerp(r, to.r, weight),
Mathf.Lerp(g, to.g, weight),
Mathf.Lerp(b, to.b, weight),
Mathf.Lerp(a, to.a, weight)
);
}

return res;
public Color Lerp(Color to, Color weight)
{
return new Color
(
Mathf.Lerp(r, to.r, weight.r),
Mathf.Lerp(g, to.g, weight.g),
Mathf.Lerp(b, to.b, weight.b),
Mathf.Lerp(a, to.a, weight.a)
);
}

public uint ToAbgr32()
Expand Down
4 changes: 2 additions & 2 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public Transform InterpolateWith(Transform transform, real_t c)
Vector3 destinationLocation = transform.origin;

var interpolated = new Transform();
interpolated.basis.SetQuatScale(sourceRotation.Slerp(destinationRotation, c).Normalized(), sourceScale.LinearInterpolate(destinationScale, c));
interpolated.origin = sourceLocation.LinearInterpolate(destinationLocation, c);
interpolated.basis.SetQuatScale(sourceRotation.Slerp(destinationRotation, c).Normalized(), sourceScale.Lerp(destinationScale, c));
interpolated.origin = sourceLocation.Lerp(destinationLocation, c);

return interpolated;
}
Expand Down
6 changes: 3 additions & 3 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public Transform2D InterpolateWith(Transform2D m, real_t c)
if (dot > 0.9995f)
{
// Linearly interpolate to avoid numerical precision issues
v = v1.LinearInterpolate(v2, c).Normalized();
v = v1.Lerp(v2, c).Normalized();
}
else
{
Expand All @@ -186,8 +186,8 @@ public Transform2D InterpolateWith(Transform2D m, real_t c)
Vector2 p2 = m.origin;

// Construct matrix
var res = new Transform2D(Mathf.Atan2(v.y, v.x), p1.LinearInterpolate(p2, c));
Vector2 scale = s1.LinearInterpolate(s2, c);
var res = new Transform2D(Mathf.Atan2(v.y, v.x), p1.Lerp(p2, c));
Vector2 scale = s1.Lerp(s2, c);
res.x *= scale;
res.y *= scale;

Expand Down
20 changes: 14 additions & 6 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,22 @@ public real_t LengthSquared()
return x * x + y * y;
}

public Vector2 LinearInterpolate(Vector2 b, real_t t)
public Vector2 Lerp(Vector2 to, real_t weight)
{
var res = this;

res.x += t * (b.x - x);
res.y += t * (b.y - y);
return new Vector2
(
Mathf.Lerp(x, to.x, weight),
Mathf.Lerp(y, to.y, weight)
);
}

return res;
public Vector2 Lerp(Vector2 to, Vector2 weight)
{
return new Vector2
(
Mathf.Lerp(x, to.x, weight.x),
Mathf.Lerp(y, to.y, weight.y)
);
}

public Vector2 MoveToward(Vector2 to, real_t delta)
Expand Down
18 changes: 14 additions & 4 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,23 @@ public real_t LengthSquared()
return x2 + y2 + z2;
}

public Vector3 LinearInterpolate(Vector3 b, real_t t)
public Vector3 Lerp(Vector3 to, real_t weight)
{
return new Vector3
(
x + t * (b.x - x),
y + t * (b.y - y),
z + t * (b.z - z)
Mathf.Lerp(x, to.x, weight),
Mathf.Lerp(y, to.y, weight),
Mathf.Lerp(z, to.z, weight)
);
}

public Vector3 Lerp(Vector3 to, Vector3 weight)
{
return new Vector3
(
Mathf.Lerp(x, to.x, weight.x),
Mathf.Lerp(y, to.y, weight.y),
Mathf.Lerp(z, to.z, weight.z)
);
}

Expand Down

0 comments on commit ad3c3e1

Please sign in to comment.