diff options
| author | Benji <[email protected]> | 2024-04-15 17:08:09 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-04-15 23:08:09 +0200 |
| commit | 4e37c8e370f9c3846dc1136047809ed5d8886a90 (patch) | |
| tree | 0b96b26c737ea9a1059b40c49e41a8480d071c41 /src/raymath.h | |
| parent | 289e7d3a6c5b9ee05ff9e4f77db6de7f897e49ec (diff) | |
| download | raylib-4e37c8e370f9c3846dc1136047809ed5d8886a90.tar.gz raylib-4e37c8e370f9c3846dc1136047809ed5d8886a90.zip | |
Added missing interpolation types for GLTF animation channels (#3919)
Diffstat (limited to 'src/raymath.h')
| -rw-r--r-- | src/raymath.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/raymath.h b/src/raymath.h index 3bafab51..8b2bbed5 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -955,6 +955,22 @@ RMAPI Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount) return result; } +// Calculate cubic hermite interpolation between two vectors and their tangents +// taken directly from: https://en.wikipedia.org/wiki/Cubic_Hermite_spline +RMAPI Vector3 Vector3CubicHermite(Vector3 v1, Vector3 tangent1, Vector3 v2, Vector3 tangent2, float amount) +{ + Vector3 result = { 0 }; + + float amountPow2 = amount * amount; + float amountPow3 = amount * amount * amount; + + result.x = (2 * amountPow3 - 3 * amountPow2 + 1) * v1.x + (amountPow3 - 2 * amountPow2 + amount) * tangent1.x + (-2 * amountPow3 + 3 * amountPow2) * v2.x + (amountPow3 - amountPow2) * tangent2.x; + result.y = (2 * amountPow3 - 3 * amountPow2 + 1) * v1.y + (amountPow3 - 2 * amountPow2 + amount) * tangent1.y + (-2 * amountPow3 + 3 * amountPow2) * v2.y + (amountPow3 - amountPow2) * tangent2.y; + result.z = (2 * amountPow3 - 3 * amountPow2 + 1) * v1.z + (amountPow3 - 2 * amountPow2 + amount) * tangent1.z + (-2 * amountPow3 + 3 * amountPow2) * v2.z + (amountPow3 - amountPow2) * tangent2.z; + + return result; +} + // Calculate reflected vector to normal RMAPI Vector3 Vector3Reflect(Vector3 v, Vector3 normal) { @@ -2197,6 +2213,18 @@ RMAPI Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount) return result; } +// Calculate quaternion cubic spline interpolation using the SQUAD algorithm +// roughly adapted from the SQUAD algorithm presented here: https://roboop.sourceforge.io/htmldoc/robotse9.html +RMAPI Quaternion QuaternionCubicSpline(Quaternion q1, Quaternion tangent1, Quaternion q2, Quaternion tangent2, float amount) +{ + Quaternion slerp1 = QuaternionSlerp(q1, q2, amount); + Quaternion slerp2 = QuaternionSlerp(tangent1, tangent2, amount); + float t = 2 * amount * (1 - amount); + + Quaternion result = QuaternionSlerp(slerp1, slerp2, t); + return result; +} + // Calculate quaternion based on the rotation from one vector to another RMAPI Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to) { |
