You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If vectors are vertical - they are parallel to up vector so cross product is zero, need to add check for lookAt and targetTo methods of mat4 if x and z of position and target are strictly equal then add small offset (ex. 0.000000001) to x or z component of position or target vectors.
Code to test
const{mat4, glMatrix}=require("gl-matrix")glMatrix.setMatrixArrayType(Array);// for easier testconstm1=mat4.create();console.log(mat4.lookAt(m1,[10,38,2],[10,8,2],[0,1,0]));// doesnt workconsole.log(mat4.lookAt(m1,[10,38,2],[10,8,2+0.000000001],[0,1,0]));// slight offset fixes thisconstm2=mat4.create();console.log(mat4.targetTo(m2,[10,38,2],[10,8,2],[0,1,0]));// doesnt workconsole.log(mat4.targetTo(m2,[10,38,2],[10,8,2+0.000000001],[0,1,0]));// slight offset fixes this
Possible fix
Looks like:
// x and z are strictly equalif(position[0]===target[0]&&position[2]===target[2]){target[2]+=0.000000001;}
The text was updated successfully, but these errors were encountered:
psnet
changed the title
Bug: lookAt and targeTo will not work if position and target are vertical
Bug: lookAt and targetTo will not work if position and target are vertical
Mar 16, 2024
Problem
If vectors are vertical - they are parallel to up vector so cross product is zero, need to add check for
lookAt
andtargetTo
methods ofmat4
ifx
andz
ofposition
andtarget
are strictly equal then add small offset (ex.0.000000001
) tox
orz
component ofposition
ortarget
vectors.Code to test
Possible fix
Looks like:
The text was updated successfully, but these errors were encountered: