Skip to content
Snippets Groups Projects
Commit 9f99a2c4 authored by David Sehnal's avatar David Sehnal
Browse files

mol-math: fixed makeRotation edge case

parent 1b377eae
No related branches found
No related tags found
No related merge requests found
......@@ -452,9 +452,15 @@ namespace Vec3 {
}
const rotTemp = zero();
const flipMatrix = Mat4.fromScaling(Mat4.zero(), create(-1, -1, -1))
export function makeRotation(mat: Mat4, a: Vec3, b: Vec3): Mat4 {
const by = angle(a, b);
if (Math.abs(by) < 0.0001) return Mat4.setIdentity(mat);
if (Math.abs(by - Math.PI) < EPSILON.Value) {
// here, axis can be [0,0,0] but the rotation is a simple flip
Mat4.copy(mat, flipMatrix);
return mat;
}
const axis = cross(rotTemp, a, b);
return Mat4.fromRotation(mat, by, axis);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment