setFromUnitVectors method

Quat setFromUnitVectors(
  1. Vec3 v1,
  2. Vec3 v2
)

Set Quant from v1 and v2

Implementation

Quat setFromUnitVectors(Vec3 v1, Vec3 v2 ) {
  var vx = Vec3();
  var r = v1.dot( v2 ) + 1;

  if ( r < Math.eps2 ) {
    r = 0;
    if (v1.x.abs() >v1.z.abs() ){ vx.set( - v1.y, v1.x, 0 );}
    else{ vx.set( 0, - v1.z, v1.y );}
  }
  else {
    vx.crossVectors( v1, v2 );
  }

  x = vx.x;
  y = vx.y;
  z = vx.z;
  w = r;

  return normalize();
}