Skip to content

Commit

Permalink
LemonUtil: Velocity to Eular Angles to properly update facing for MD3…
Browse files Browse the repository at this point in the history
…s in real time
  • Loading branch information
Lemon-King committed Oct 24, 2023
1 parent b347f65 commit 3bfce98
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions resources/assets/zscript/lib/lemonutil.zs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,23 @@ class LemonUtil {
return atan2(y, x) * (180.0 / M_PI);
}

static vector3 Vector3ToEularAngles(Vector3 v) {
double angle = atan2(v.y, v.x);
double pitch = atan2(-v.z, sqrt(v.x ** 2 + v.y ** 2));
double roll = atan2(
v.x * sin(angle) - v.y * cos(angle),
v.x * cos(angle) + v.y * sin(angle)
);

return (angle, pitch, roll);
}

// Used to convert Velocity to Facing Angle, Pitch, and Roll
static vector3 GetEularFromVelocity(Vector3 v) {
vector3 norm = LemonUtil.v3normalize(v);
return Vector3ToEularAngles(norm);
}


// Easings
static double Easing_Quadradic_In(double val) {
Expand All @@ -294,4 +311,12 @@ class LemonUtil {
return 7.5625*(val -= (2.625/2.75))*val + 0.984375;
}
}

static double MathPI() {
return 3.141592653589793238462643383279502884197;
}

static double GetDegrees() {
return 180.0 / LemonUtil.MathPI();
}
}

0 comments on commit 3bfce98

Please sign in to comment.