gl-matrix icon indicating copy to clipboard operation
gl-matrix copied to clipboard

Nan when up is aligned with target

Open anvaka opened this issue 3 years ago • 1 comments

I'm not sure what's the right way to fix this or even whether a fix is necessary. Just wanted to log it here:

// glMatrix version 3.3.0

// Note that both `up` and `direction` are the same
let q = mat4.getRotation([], mat4.targetTo([], [0, 0, -1], [0, 0, 0], [0, 0, 1]))

// Now all quaternion components are not numbers
assert(Number.isNaN(q[0]))
assert(Number.isNaN(q[1]))
assert(Number.isNaN(q[2]))
assert(Number.isNaN(q[3]))

anvaka avatar May 10 '21 01:05 anvaka

I have the same issue. Seems like it doesn't work when target is at 0, 0, 0. Why is that?

const matrix = glMatrix.mat4.targetTo(glMatrix.mat4.create(),
    [0, 5, 0], [0, 0, 0], [0, 1, 0])
let rot = glMatrix.mat4.getRotation(glMatrix.quat.create(), matrix)
console.log(rot) // Float32Array(4) [NaN, NaN, NaN, NaN]

This results in a quat with "NaN, NaN, NaN, NaN"

jnsmalm avatar Aug 09 '21 19:08 jnsmalm