mono: add Slerp method to vector classes, expose Cross method for Vector2, and fix unnecessary casts in Basis

(cherry picked from commit b335274bcd)
This commit is contained in:
Kelly Thomas 2018-05-20 18:29:54 +08:00 committed by Hein-Pieter van Braam
parent 5d2ad1e5c7
commit d00926894e
4 changed files with 17 additions and 5 deletions

View File

@ -453,15 +453,15 @@ namespace Godot
c = Mathf.Cos(euler.x); c = Mathf.Cos(euler.x);
s = Mathf.Sin(euler.x); s = Mathf.Sin(euler.x);
var xmat = new Basis((real_t)1.0, (real_t)0.0, (real_t)0.0, (real_t)0.0, c, -s, (real_t)0.0, s, c); var xmat = new Basis(1, 0, 0, 0, c, -s, 0, s, c);
c = Mathf.Cos(euler.y); c = Mathf.Cos(euler.y);
s = Mathf.Sin(euler.y); s = Mathf.Sin(euler.y);
var ymat = new Basis(c, (real_t)0.0, s, (real_t)0.0, (real_t)1.0, (real_t)0.0, -s, (real_t)0.0, c); var ymat = new Basis(c, 0, s, 0, 1, 0, -s, 0, c);
c = Mathf.Cos(euler.z); c = Mathf.Cos(euler.z);
s = Mathf.Sin(euler.z); s = Mathf.Sin(euler.z);
var zmat = new Basis(c, -s, (real_t)0.0, s, c, (real_t)0.0, (real_t)0.0, (real_t)0.0, (real_t)1.0); var zmat = new Basis(c, -s, 0, s, c, 0, 0, 0, 1);
this = ymat * xmat * zmat; this = ymat * xmat * zmat;
} }

View File

@ -1 +1 @@
2 3

View File

@ -62,7 +62,7 @@ namespace Godot
} }
} }
private real_t Cross(Vector2 b) public real_t Cross(Vector2 b)
{ {
return x * b.y - y * b.x; return x * b.y - y * b.x;
} }
@ -201,6 +201,12 @@ namespace Godot
y = v.y; y = v.y;
} }
public Vector2 Slerp(Vector2 b, real_t t)
{
real_t theta = AngleTo(b);
return Rotated(theta * t);
}
public Vector2 Slide(Vector2 n) public Vector2 Slide(Vector2 n)
{ {
return this - n * Dot(n); return this - n * Dot(n);

View File

@ -237,6 +237,12 @@ namespace Godot
z = v.z; z = v.z;
} }
public Vector3 Slerp(Vector3 b, real_t t)
{
real_t theta = AngleTo(b);
return Rotated(Cross(b), theta * t);
}
public Vector3 Slide(Vector3 n) public Vector3 Slide(Vector3 n)
{ {
return this - n * Dot(n); return this - n * Dot(n);