浏览代码

added initNormal()

Nicolas Cannasse 4 年之前
父节点
当前提交
fed4dea47d
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      h3d/Quat.hx

+ 11 - 0
h3d/Quat.hx

@@ -63,6 +63,17 @@ class Quat {
 		normalize();
 		normalize();
 	}
 	}
 
 
+	public function initNormal( dir : h3d.col.Point ) {
+		var dir = dir.normalized();
+		if( dir.x*dir.x+dir.y*dir.y < Math.EPSILON )
+			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());
+		}
+	}
+
 	public function initDirection( dir : Vector ) {
 	public function initDirection( dir : Vector ) {
 		// inlined version of initRotationMatrix(Matrix.lookAtX(dir))
 		// inlined version of initRotationMatrix(Matrix.lookAtX(dir))
 		var ax = dir.clone().normalized();
 		var ax = dir.clone().normalized();