setFromTwoVectors method
Implementation
void setFromTwoVectors(Vector3 a, Vector3 b) {
final Vector3 v1 = a.normalized();
final Vector3 v2 = b.normalized();
final double c = v1.dot(v2);
double angle = math.acos(c);
Vector3 axis = v1.cross(v2);
if ((1.0 + c).abs() < 0.0005) {
angle = math.pi;
if (v1.x > v1.y && v1.x > v1.z) {
axis = v1.cross(new Vector3(0.0, 1.0, 0.0));
} else {
axis = v1.cross(new Vector3(1.0, 0.0, 0.0));
}
} else if ((1.0 - c).abs() < 0.0005) {
angle = 0.0;
axis = new Vector3(1.0, 0.0, 0.0);
}
setAxisAngle(axis.normalized(), angle);
}