diff options
author | KT <tran0563@umn.edu> | 2021-09-21 10:05:57 -0500 |
---|---|---|
committer | KT <tran0563@umn.edu> | 2021-09-21 10:05:57 -0500 |
commit | a75b08b76f91451bb586b154fdca872955d8a57a (patch) | |
tree | dd1c30f65162c1e12b8f6481bbd102d69f5c7196 /dev/MinGfx/src/quaternion.cc | |
parent | Upload a1 (diff) | |
download | csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.gz csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.bz2 csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.lz csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.xz csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.tar.zst csci4611-a75b08b76f91451bb586b154fdca872955d8a57a.zip |
publish a2
Diffstat (limited to 'dev/MinGfx/src/quaternion.cc')
-rw-r--r-- | dev/MinGfx/src/quaternion.cc | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/dev/MinGfx/src/quaternion.cc b/dev/MinGfx/src/quaternion.cc index 4f2998f..24830c8 100644 --- a/dev/MinGfx/src/quaternion.cc +++ b/dev/MinGfx/src/quaternion.cc @@ -116,12 +116,13 @@ Quaternion Quaternion::Slerp(const Quaternion &other, float alpha) const { return result; } - GfxMath::Clamp(dot, -1, 1); // Robustness: Stay within domain of acos() - float theta_0 = acos(dot); // theta_0 = angle between input vectors - float theta = theta_0 * alpha; // theta = angle between v0 and result + GfxMath::Clamp(dot, -1, 1); // Robustness: Stay within domain of acos() + float theta_0 = GfxMath::acos(dot); // theta_0 = angle between input vectors + float theta = theta_0 * alpha; // theta = angle between v0 and result - float s0 = cos(theta) - dot * sin(theta) / sin(theta_0); // == sin(theta_0 - theta) / sin(theta_0) - float s1 = sin(theta) / sin(theta_0); + float s0 = GfxMath::cos(theta) - dot + * GfxMath::sin(theta) / GfxMath::sin(theta_0); // == sin(theta_0 - theta) / sin(theta_0) + float s1 = GfxMath::sin(theta) / GfxMath::sin(theta_0); return (s0 * v0) + (s1 * v1); } @@ -177,10 +178,10 @@ Quaternion Quaternion::Conjugate() const { Quaternion Quaternion::FromAxisAngle(const Vector3 &axis, float angle) { // [qx, qy, qz, qw] = [sin(a/2) * vx, sin(a/2)* vy, sin(a/2) * vz, cos(a/2)] - float x = sin(angle/2.0f) * axis[0]; - float y = sin(angle/2.0f) * axis[1]; - float z = sin(angle/2.0f) * axis[2]; - float w = cos(angle/2.0f); + float x = GfxMath::sin(angle/2.0) * axis[0]; + float y = GfxMath::sin(angle/2.0) * axis[1]; + float z = GfxMath::sin(angle/2.0) * axis[2]; + float w = GfxMath::cos(angle/2.0); return Quaternion(x,y,z,w); } |