Bläddra i källkod

Fix initNormal for Quat and added rotate param

TothBenoit 1 år sedan
förälder
incheckning
5ba2e18f28
1 ändrade filer med 11 tillägg och 2 borttagningar
  1. 11 2
      h3d/Quat.hx

+ 11 - 2
h3d/Quat.hx

@@ -63,14 +63,23 @@ class Quat {
 		normalize();
 	}
 
-	public function initNormal( dir : h3d.col.Point ) {
+	public function initNormal( dir : h3d.col.Point, rotate : Float = 0.0 ) {
 		var dir = dir.normalized();
 		if( dir.x*dir.x+dir.y*dir.y < Math.EPSILON2 )
 			initDirection(new h3d.Vector(1,0,0));
 		else {
 			var ay = new h3d.col.Point(dir.x, dir.y, 0).normalized();
 			var az = dir.cross(ay);
-			initDirection(dir.cross(az).toVector());
+			var ax = dir.cross(az).toVector();
+			if (dir.z < 0.0) 
+				initDirection(ax, new Vector(0.0, 0.0, -1.0));
+			else 
+				initDirection(ax);
+		}
+		if ( rotate != 0.0) {
+			var quat = new Quat();
+			quat.initRotateAxis(dir.x, dir.y, dir.z, rotate);
+			multiply(quat, this);
 		}
 	}