Browse Source

added initDirection up vector and getUpAxis

Nicolas Cannasse 2 years ago
parent
commit
fd4ceac7b9
1 changed files with 6 additions and 2 deletions
  1. 6 2
      h3d/Quat.hx

+ 6 - 2
h3d/Quat.hx

@@ -74,10 +74,10 @@ class Quat {
 		}
 	}
 
-	public function initDirection( dir : Vector ) {
+	public function initDirection( dir : Vector, ?up : Vector ) {
 		// inlined version of initRotationMatrix(Matrix.lookAtX(dir))
 		var ax = dir.clone().normalized();
-		var ay = new Vector(-ax.y, ax.x, 0).normalized();
+		var ay = up == null ? new Vector(-ax.y, ax.x, 0).normalized() : up.cross(ax).normalized();
 		if( ay.lengthSq() < Math.EPSILON ) {
 			ay.x = ax.y;
 			ay.y = ax.z;
@@ -290,6 +290,10 @@ class Quat {
 		return new h3d.Vector(1 - 2 * ( y * y + z * z ), 2 * ( x * y + z * w ), 2 * ( x * z - y * w ));
 	}
 
+	public inline function getUpAxis() {
+		return new h3d.Vector(2 * ( x*z + y*w ),2 * ( y*z - x*w ), 1 - 2 * ( x*x + y*y ));
+	}
+
 	/**
 		Save to a Left-Handed matrix
 	**/