Skip to content
Snippets Groups Projects
Unverified Commit b1d75f1c authored by Jamie Temple's avatar Jamie Temple
Browse files

fix: SLERP is now stable

parent 956681a2
Branches
No related tags found
1 merge request!1feat: base project
...@@ -102,45 +102,46 @@ export class Quaternion { ...@@ -102,45 +102,46 @@ export class Quaternion {
return Quaternion.add(Quaternion.multiplyScalar(qa, 1 - t), Quaternion.multiplyScalar(qb, t)); return Quaternion.add(Quaternion.multiplyScalar(qa, 1 - t), Quaternion.multiplyScalar(qb, t));
} else { } else {
const theta = Math.acos(cosTheta); const theta = Math.acos(cosTheta);
const thetap = theta * t; const sinTheta = Math.sin(theta);
const qperp = Quaternion.normalize(Quaternion.subtract(qb, Quaternion.multiplyScalar(qa, cosTheta))); const sinThetaA = Math.sin(theta * (1 - t));
return Quaternion.add(Quaternion.multiplyScalar(qa, Math.cos(thetap)), Quaternion.multiplyScalar(qperp, Math.sin(thetap))); const sinThetaB = Math.sin(theta * t);
return Quaternion.add(Quaternion.multiplyScalar(qa, sinThetaA / sinTheta), Quaternion.multiplyScalar(qb, sinThetaB / sinTheta));
} }
} }
// public static slerp(qa: Quaternion, qb: Quaternion, t: number): Quaternion { public static slerpCG3(qa: Quaternion, qb: Quaternion, t: number): Quaternion {
// let cq1 = qa.clone(); let cq1 = qa.clone();
// let cq2 = qb.clone(); let cq2 = qb.clone();
// cq1 = Quaternion.normalize(cq1); cq1 = Quaternion.normalize(cq1);
// cq2 = Quaternion.normalize(cq2); cq2 = Quaternion.normalize(cq2);
// let dot = Quaternion.dot(cq1, cq2); let dot = Quaternion.dot(cq1, cq2);
// if (dot < 0.0) { if (dot < 0.0) {
// cq2 = Quaternion.inverse(cq2); cq2 = Quaternion.inverse(cq2);
// dot = -dot; dot = -dot;
// } }
// if (dot > 0.9995) { if (dot > 0.9995) {
// return Quaternion.add(cq1, Quaternion.multiplyScalar( return Quaternion.add(cq1, Quaternion.multiplyScalar(
// Quaternion.subtract(cq2, cq1), t)); Quaternion.subtract(cq2, cq1), t));
// } }
// const theta0 = Math.acos(dot); const theta0 = Math.acos(dot);
// const theta = theta0 * t; const theta = theta0 * t;
// const sinTheta0 = Math.sin(theta0); const sinTheta0 = Math.sin(theta0);
// const sinTheta = Math.sin(theta); const sinTheta = Math.sin(theta);
// const s0 = Math.cos(theta0) - dot * sinTheta / sinTheta0; const s0 = Math.cos(theta0) - dot * sinTheta / sinTheta0;
// const s1 = sinTheta / sinTheta0; const s1 = sinTheta / sinTheta0;
// return Quaternion.add( return Quaternion.add(
// Quaternion.multiplyScalar(cq1, s0), Quaternion.multiplyScalar(cq1, s0),
// Quaternion.multiplyScalar(cq2, s1) Quaternion.multiplyScalar(cq2, s1)
// ) )
// } }
public static add(qa: Quaternion, qb: Quaternion): Quaternion { public static add(qa: Quaternion, qb: Quaternion): Quaternion {
return new Quaternion(qa._x + qb._x, qa._y + qb._y, qa._z + qb._z, qa._w + qb._w); return new Quaternion(qa._x + qb._x, qa._y + qb._y, qa._z + qb._z, qa._w + qb._w);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment