79723711

Date: 2025-08-02 23:47:56
Score: 1.5
Natty:
Report link

any possibility of adding a up vector to this function?

also here's my THREE js interpretation with NaN protection

function rotLookAt(dir, obj)
{
    let x = new THREE.Vector3(1,0,0);
    let y = new THREE.Vector3(0,1,0);
    let z = new THREE.Vector3(0,0,1);
    
// Checks if we are about to divide by zero
    if(dir.length() == 0)
    {
        console.log("dir equal zero dummy :(")
        return obj.rotation;
    }
    
    let phi1 = dir.dot(x)/dir.length();
    let phi2 = dir.dot(y)/dir.length();
    let phi3 = dir.dot(z)/dir.length();
    
    let zAngle = Math.atan(phi2/phi1);
    let yAngle = Math.atan2(phi3, phi1);
    let xAngle = Math.atan(phi2/phi3);
    
    return new THREE.Euler(zAngle, -yAngle, obj.rotation.x, "ZYX");
}
Reasons:
  • Blacklisted phrase (1): :(
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: perspective_shift