Browse Source

refactor h3d.FMath -> hxd.Math and h3d.prim.Point moved to h3d.col

ncannasse 12 years ago
parent
commit
243a5be7e3

+ 3 - 2
h2d/Graphics.hx

@@ -1,4 +1,5 @@
 package h2d;
 package h2d;
+import hxd.Math;
 
 
 private typedef GraphicsPoint = hxd.poly2tri.Point;
 private typedef GraphicsPoint = hxd.poly2tri.Point;
 
 
@@ -151,10 +152,10 @@ class Graphics extends Drawable {
 			var next = linePts[(i + 1) % linePts.length];
 			var next = linePts[(i + 1) % linePts.length];
 			var nx1 = prev.y - p.y;
 			var nx1 = prev.y - p.y;
 			var ny1 = p.x - prev.x;
 			var ny1 = p.x - prev.x;
-			var ns1 = h3d.FMath.isqrt(nx1 * nx1 + ny1 * ny1);
+			var ns1 = Math.isqrt(nx1 * nx1 + ny1 * ny1);
 			var nx2 = p.y - next.y;
 			var nx2 = p.y - next.y;
 			var ny2 = next.x - p.x;
 			var ny2 = next.x - p.x;
-			var ns2 = h3d.FMath.isqrt(nx2 * nx2 + ny2 * ny2);
+			var ns2 = Math.isqrt(nx2 * nx2 + ny2 * ny2);
 			
 			
 			var nx = (nx1 * ns1 + nx2 * ns2) * lineSize * 0.5;
 			var nx = (nx1 * ns1 + nx2 * ns2) * lineSize * 0.5;
 			var ny = (ny1 * ns1 + ny2 * ns2) * lineSize * 0.5;
 			var ny = (ny1 * ns1 + ny2 * ns2) * lineSize * 0.5;

+ 3 - 2
h2d/Scene.hx

@@ -1,4 +1,5 @@
 package h2d;
 package h2d;
+import hxd.Math;
 
 
 class Scene extends Layers implements h3d.IDrawable {
 class Scene extends Layers implements h3d.IDrawable {
 
 
@@ -319,8 +320,8 @@ class Scene extends Layers implements h3d.IDrawable {
 		
 		
 		// perform final rotation around center
 		// perform final rotation around center
 		if( rotation != 0 ) {
 		if( rotation != 0 ) {
-			var cr = h3d.FMath.cos(rotation);
-			var sr = h3d.FMath.sin(rotation);
+			var cr = Math.cos(rotation);
+			var sr = Math.sin(rotation);
 			var tmpA = matA * cr + matB * sr;
 			var tmpA = matA * cr + matB * sr;
 			var tmpB = matA * -sr + matB * cr;
 			var tmpB = matA * -sr + matB * cr;
 			var tmpC = matC * cr + matD * sr;
 			var tmpC = matC * cr + matD * sr;

+ 5 - 4
h2d/Sprite.hx

@@ -1,4 +1,5 @@
 package h2d;
 package h2d;
+import hxd.Math;
 
 
 @:allow(h2d.Tools)
 @:allow(h2d.Tools)
 class Sprite {
 class Sprite {
@@ -170,8 +171,8 @@ class Sprite {
 				matC = 0;
 				matC = 0;
 				matD = scaleY;
 				matD = scaleY;
 			} else {
 			} else {
-				cr = h3d.FMath.cos(rotation);
-				sr = h3d.FMath.sin(rotation);
+				cr = Math.cos(rotation);
+				sr = Math.sin(rotation);
 				matA = scaleX * cr;
 				matA = scaleX * cr;
 				matB = scaleX * -sr;
 				matB = scaleX * -sr;
 				matC = scaleY * sr;
 				matC = scaleY * sr;
@@ -188,8 +189,8 @@ class Sprite {
 				matC = scaleY * parent.matC;
 				matC = scaleY * parent.matC;
 				matD = scaleY * parent.matD;
 				matD = scaleY * parent.matD;
 			} else {
 			} else {
-				var cr = h3d.FMath.cos(rotation);
-				var sr = h3d.FMath.sin(rotation);
+				var cr = Math.cos(rotation);
+				var sr = Math.sin(rotation);
 				var tmpA = scaleX * cr;
 				var tmpA = scaleX * cr;
 				var tmpB = scaleX * -sr;
 				var tmpB = scaleX * -sr;
 				var tmpC = scaleY * sr;
 				var tmpC = scaleY * sr;

+ 2 - 1
h2d/col/Circle.hx

@@ -1,4 +1,5 @@
 package h2d.col;
 package h2d.col;
+import hxd.Math;
 
 
 class Circle {
 class Circle {
 
 
@@ -32,7 +33,7 @@ class Circle {
 	}
 	}
 
 
 	public function toString() {
 	public function toString() {
-		return "{" + h3d.FMath.fmt(x) + "," + h3d.FMath.fmt(y) + "," + h3d.FMath.fmt(ray) + "}";
+		return '{${Math.fmt(x)},${Math.fmt(y)},${Math.fmt(ray)}}';
 	}
 	}
 	
 	
 }
 }

+ 5 - 4
h2d/col/Point.hx

@@ -1,4 +1,5 @@
 package h2d.col;
 package h2d.col;
+import hxd.Math;
 
 
 class Point {
 class Point {
 	
 	
@@ -17,11 +18,11 @@ class Point {
 	}
 	}
 	
 	
 	public inline function distance( p : Point ) {
 	public inline function distance( p : Point ) {
-		return h3d.FMath.sqrt(distanceSq(p));
+		return Math.sqrt(distanceSq(p));
 	}
 	}
 	
 	
 	public function toString() {
 	public function toString() {
-		return "{" + h3d.FMath.fmt(x) + "," + h3d.FMath.fmt(y) + "}";
+		return "{" + Math.fmt(x) + "," + Math.fmt(y) + "}";
 	}
 	}
 		
 		
 	public inline function sub( p : Point ) {
 	public inline function sub( p : Point ) {
@@ -41,12 +42,12 @@ class Point {
 	}
 	}
 
 
 	public inline function length() {
 	public inline function length() {
-		return h3d.FMath.sqrt(lengthSq());
+		return Math.sqrt(lengthSq());
 	}
 	}
 
 
 	public function normalize() {
 	public function normalize() {
 		var k = lengthSq();
 		var k = lengthSq();
-		if( k < h3d.FMath.EPSILON ) k = 0 else k = h3d.FMath.isqrt(k);
+		if( k < Math.EPSILON ) k = 0 else k = Math.isqrt(k);
 		x *= k;
 		x *= k;
 		y *= k;
 		y *= k;
 	}
 	}

+ 2 - 1
h2d/col/Poly.hx

@@ -1,4 +1,5 @@
 package h2d.col;
 package h2d.col;
+import hxd.Math;
 
 
 class Poly {
 class Poly {
 
 
@@ -70,7 +71,7 @@ class Poly {
 	}
 	}
 	
 	
 	public inline function distance( p : Point ) {
 	public inline function distance( p : Point ) {
-		return h3d.FMath.sqrt(distanceSq(p));
+		return Math.sqrt(distanceSq(p));
 	}
 	}
 	
 	
 }
 }

+ 2 - 1
h2d/col/Seg.hx

@@ -1,4 +1,5 @@
 package h2d.col;
 package h2d.col;
+import hxd.Math;
 
 
 class Seg {
 class Seg {
 
 
@@ -41,7 +42,7 @@ class Seg {
 	}
 	}
 
 
 	public inline function distance( p : Point ) {
 	public inline function distance( p : Point ) {
-		return h3d.FMath.sqrt(distanceSq(p));
+		return Math.sqrt(distanceSq(p));
 	}
 	}
 	
 	
 	public inline function project( p : Point ) : Point {
 	public inline function project( p : Point ) : Point {

+ 2 - 1
h2d/col/Voronoi.hx

@@ -16,6 +16,7 @@
 	History: See https://github.com/gorhill/Javascript-Voronoi/CHANGELOG.md
 	History: See https://github.com/gorhill/Javascript-Voronoi/CHANGELOG.md
 */
 */
 package h2d.col;
 package h2d.col;
+import hxd.Math;
 
 
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------
 // Red-Black tree code (based on C version of "rbtree" by Franck Bui-Huu
 // Red-Black tree code (based on C version of "rbtree" by Franck Bui-Huu
@@ -347,7 +348,7 @@ class Cell {
 			var d = p.distanceSq(e.getStartpoint());
 			var d = p.distanceSq(e.getStartpoint());
 			if( d > r ) r = d;
 			if( d > r ) r = d;
 		}
 		}
-		return new Circle(p.x, p.y, h3d.FMath.sqrt(r));
+		return new Circle(p.x, p.y, Math.sqrt(r));
 	}
 	}
 
 
 	public function prepare() {
 	public function prepare() {

+ 0 - 78
h3d/FMath.hx

@@ -1,78 +0,0 @@
-package h3d;
-
-class FMath {
-	
-	public static inline var EPSILON = 1e-10;
-
-	// round to 4 significant digits, eliminates <1e-10
-	public static function fmt( v : Float ) {
-		var neg;
-		if( v < 0 ) {
-			neg = -1.0;
-			v = -v;
-		} else
-			neg = 1.0;
-		if( Math.isNaN(v) )
-			return v;
-		var digits = Std.int(4 - Math.log(v) / Math.log(10));
-		if( digits < 1 )
-			digits = 1;
-		else if( digits >= 10 )
-			return 0.;
-		var exp = Math.pow(10,digits);
-		return Math.floor(v * exp + .49999) * neg / exp;
-	}
-	
-	public static inline function clamp( f : Float, min = 0., max = 1. ) {
-		return f < min ? min : f > max ? max : f;
-	}
-	
-	public static inline function cos( f : Float ) {
-		return Math.cos(f);
-	}
-
-	public static inline function sin( f : Float ) {
-		return Math.sin(f);
-	}
-	
-	public static inline function sqrt( f : Float ) {
-		return Math.sqrt(f);
-	}
-
-	public static inline function isqrt( f : Float ) {
-		return 1. / sqrt(f);
-	}
-	
-	public static inline function atan2( dy : Float, dx : Float ) {
-		return Math.atan2(dy,dx);
-	}
-	
-	public static inline function abs( f : Float ) {
-		return f < 0 ? -f : f;
-	}
-
-	public static inline function max( a : Float, b : Float ) {
-		return a < b ? b : a;
-	}
-
-	public static inline function min( a : Float, b : Float ) {
-		return a > b ? b : a;
-	}
-	
-	public static inline function iabs( i : Int ) {
-		return i < 0 ? -i : i;
-	}
-
-	public static inline function imax( a : Int, b : Int ) {
-		return a < b ? b : a;
-	}
-
-	public static inline function imin( a : Int, b : Int ) {
-		return a > b ? b : a;
-	}
-
-	public static inline function iclamp( v : Int, min : Int, max : Int ) {
-		return v < min ? min : (v > max ? max : v);
-	}
-	
-}

+ 21 - 20
h3d/Matrix.hx

@@ -1,4 +1,5 @@
 package h3d;
 package h3d;
+import hxd.Math;
 
 
 class Matrix {
 class Matrix {
 	
 	
@@ -39,8 +40,8 @@ class Matrix {
 	}
 	}
 
 
 	public function initRotateX( a : Float ) {
 	public function initRotateX( a : Float ) {
-		var cos = FMath.cos(a);
-		var sin = FMath.sin(a);
+		var cos = Math.cos(a);
+		var sin = Math.sin(a);
 		_11 = 1.0; _12 = 0.0; _13 = 0.0; _14 = 0.0;
 		_11 = 1.0; _12 = 0.0; _13 = 0.0; _14 = 0.0;
 		_21 = 0.0; _22 = cos; _23 = sin; _24 = 0.0;
 		_21 = 0.0; _22 = cos; _23 = sin; _24 = 0.0;
 		_31 = 0.0; _32 = -sin; _33 = cos; _34 = 0.0;
 		_31 = 0.0; _32 = -sin; _33 = cos; _34 = 0.0;
@@ -48,8 +49,8 @@ class Matrix {
 	}
 	}
 
 
 	public function initRotateY( a : Float ) {
 	public function initRotateY( a : Float ) {
-		var cos = FMath.cos(a);
-		var sin = FMath.sin(a);
+		var cos = Math.cos(a);
+		var sin = Math.sin(a);
 		_11 = cos; _12 = 0.0; _13 = -sin; _14 = 0.0;
 		_11 = cos; _12 = 0.0; _13 = -sin; _14 = 0.0;
 		_21 = 0.0; _22 = 1.0; _23 = 0.0; _24 = 0.0;
 		_21 = 0.0; _22 = 1.0; _23 = 0.0; _24 = 0.0;
 		_31 = sin; _32 = 0.0; _33 = cos; _34 = 0.0;
 		_31 = sin; _32 = 0.0; _33 = cos; _34 = 0.0;
@@ -57,8 +58,8 @@ class Matrix {
 	}
 	}
 
 
 	public function initRotateZ( a : Float ) {
 	public function initRotateZ( a : Float ) {
-		var cos = FMath.cos(a);
-		var sin = FMath.sin(a);
+		var cos = Math.cos(a);
+		var sin = Math.sin(a);
 		_11 = cos; _12 = sin; _13 = 0.0; _14 = 0.0;
 		_11 = cos; _12 = sin; _13 = 0.0; _14 = 0.0;
 		_21 = -sin; _22 = cos; _23 = 0.0; _24 = 0.0;
 		_21 = -sin; _22 = cos; _23 = 0.0; _24 = 0.0;
 		_31 = 0.0; _32 = 0.0; _33 = 1.0; _34 = 0.0;
 		_31 = 0.0; _32 = 0.0; _33 = 1.0; _34 = 0.0;
@@ -80,11 +81,11 @@ class Matrix {
 	}
 	}
 
 
 	public function initRotateAxis( axis : Vector, angle : Float ) {
 	public function initRotateAxis( axis : Vector, angle : Float ) {
-		var cos = FMath.cos(angle), sin = FMath.sin(angle);
+		var cos = Math.cos(angle), sin = Math.sin(angle);
 		var cos1 = 1 - cos;
 		var cos1 = 1 - cos;
 		var x = -axis.x, y = -axis.y, z = -axis.z;
 		var x = -axis.x, y = -axis.y, z = -axis.z;
 		var xx = x * x, yy = y * y, zz = z * z;
 		var xx = x * x, yy = y * y, zz = z * z;
-		var len = FMath.isqrt(xx + yy + zz);
+		var len = Math.isqrt(xx + yy + zz);
 		x *= len;
 		x *= len;
 		y *= len;
 		y *= len;
 		z *= len;
 		z *= len;
@@ -105,12 +106,12 @@ class Matrix {
 	}
 	}
 	
 	
 	public function initRotate( x : Float, y : Float, z : Float ) {
 	public function initRotate( x : Float, y : Float, z : Float ) {
-		var cx = FMath.cos(x);
-		var sx = FMath.sin(x);
-		var cy = FMath.cos(y);
-		var sy = FMath.sin(y);
-		var cz = FMath.cos(z);
-		var sz = FMath.sin(z);
+		var cx = Math.cos(x);
+		var sx = Math.sin(x);
+		var cy = Math.cos(y);
+		var sy = Math.sin(y);
+		var cz = Math.cos(z);
+		var sz = Math.sin(z);
 		var cxsy = cx * sy;
 		var cxsy = cx * sy;
 		var sxsy = sx * sy;
 		var sxsy = sx * sy;
 		_11 = cy * cz;
 		_11 = cy * cz;
@@ -293,7 +294,7 @@ class Matrix {
 		_43 = -m._43;
 		_43 = -m._43;
 		_44 = 1;
 		_44 = 1;
 		var det = m11 * _11 + m12 * _21 + m13 * _31;
 		var det = m11 * _11 + m12 * _21 + m13 * _31;
-		if(	FMath.abs(det) < FMath.EPSILON ) {
+		if(	Math.abs(det) < Math.EPSILON ) {
 			zero();
 			zero();
 			return;
 			return;
 		}
 		}
@@ -327,7 +328,7 @@ class Matrix {
 		_44 = m11 * m22 * m33 - m11 * m23 * m32 - m21 * m12 * m33 + m21 * m13 * m32 + m31 * m12 * m23 - m31 * m13 * m22;
 		_44 = m11 * m22 * m33 - m11 * m23 * m32 - m21 * m12 * m33 + m21 * m13 * m32 + m31 * m12 * m23 - m31 * m13 * m22;
 
 
 		var det = m11 * _11 + m12 * _21 + m13 * _31 + m14 * _41;
 		var det = m11 * _11 + m12 * _21 + m13 * _31 + m14 * _41;
-		if(	FMath.abs(det) < FMath.EPSILON ) {
+		if(	Math.abs(det) < Math.EPSILON ) {
 			zero();
 			zero();
 			return;
 			return;
 		}
 		}
@@ -390,10 +391,10 @@ class Matrix {
 	
 	
 	public function toString() {
 	public function toString() {
 		return "MAT=[\n" +
 		return "MAT=[\n" +
-			"  [ " + FMath.fmt(_11) + ", " + FMath.fmt(_12) + ", " + FMath.fmt(_13) + ", " + FMath.fmt(_14) + " ]\n" +
-			"  [ " + FMath.fmt(_21) + ", " + FMath.fmt(_22) + ", " + FMath.fmt(_23) + ", " + FMath.fmt(_24) + " ]\n" +
-			"  [ " + FMath.fmt(_31) + ", " + FMath.fmt(_32) + ", " + FMath.fmt(_33) + ", " + FMath.fmt(_34) + " ]\n" +
-			"  [ " + FMath.fmt(_41) + ", " + FMath.fmt(_42) + ", " + FMath.fmt(_43) + ", " + FMath.fmt(_44) + " ]\n" +
+			"  [ " + Math.fmt(_11) + ", " + Math.fmt(_12) + ", " + Math.fmt(_13) + ", " + Math.fmt(_14) + " ]\n" +
+			"  [ " + Math.fmt(_21) + ", " + Math.fmt(_22) + ", " + Math.fmt(_23) + ", " + Math.fmt(_24) + " ]\n" +
+			"  [ " + Math.fmt(_31) + ", " + Math.fmt(_32) + ", " + Math.fmt(_33) + ", " + Math.fmt(_34) + " ]\n" +
+			"  [ " + Math.fmt(_41) + ", " + Math.fmt(_42) + ", " + Math.fmt(_43) + ", " + Math.fmt(_44) + " ]\n" +
 		"]";
 		"]";
 	}
 	}
 	
 	

+ 32 - 27
h3d/Quat.hx

@@ -1,4 +1,5 @@
 package h3d;
 package h3d;
+using hxd.Math;
 
 
 class Quat {
 class Quat {
 	
 	
@@ -26,8 +27,12 @@ class Quat {
 		w = 1;
 		w = 1;
 	}
 	}
 	
 	
-	public function length() {
-		return FMath.sqrt(x * x + y * y + z * z + w * w);
+	public inline function lengthSq() {
+		return x * x + y * y + z * z + w * w;
+	}
+	
+	public inline function length() {
+		return lengthSq().sqrt();
 	}
 	}
 	
 	
 	public function clone() {
 	public function clone() {
@@ -35,40 +40,40 @@ class Quat {
 	}
 	}
 	
 	
 	public function initRotateAxis( x : Float, y : Float, z : Float, a : Float ) {
 	public function initRotateAxis( x : Float, y : Float, z : Float, a : Float ) {
-		var sin = FMath.sin(a / 2);
-		var cos = FMath.cos(a / 2);
+		var sin = (a / 2).sin();
+		var cos = (a / 2).cos();
 		this.x = x * sin;
 		this.x = x * sin;
 		this.y = y * sin;
 		this.y = y * sin;
 		this.z = z * sin;
 		this.z = z * sin;
-		this.w = cos * FMath.sqrt(x * x + y * y + z * z); // allow not normalized axis
+		this.w = cos * (x * x + y * y + z * z).sqrt(); // allow not normalized axis
 		normalize();
 		normalize();
 	}
 	}
 	
 	
 	public function initRotateMatrix( m : Matrix ) {
 	public function initRotateMatrix( m : Matrix ) {
 		var tr = m._11 + m._22 + m._33;
 		var tr = m._11 + m._22 + m._33;
 		if( tr > 0 ) {
 		if( tr > 0 ) {
-			var s = FMath.sqrt(tr + 1.0) * 2;
+			var s = (tr + 1.0).sqrt() * 2;
 			var is = 1 / s;
 			var is = 1 / s;
 			x = (m._23 - m._32) * is;
 			x = (m._23 - m._32) * is;
 			y = (m._31 - m._13) * is;
 			y = (m._31 - m._13) * is;
 			z = (m._12 - m._21) * is;
 			z = (m._12 - m._21) * is;
 			w = 0.25 * s;
 			w = 0.25 * s;
 		} else if( m._11 > m._22 && m._11 > m._33 ) {
 		} else if( m._11 > m._22 && m._11 > m._33 ) {
-			var s = FMath.sqrt(1.0 + m._11 - m._22 - m._33) * 2;
+			var s = (1.0 + m._11 - m._22 - m._33).sqrt() * 2;
 			var is = 1 / s;
 			var is = 1 / s;
 			x = 0.25 * s;
 			x = 0.25 * s;
 			y = (m._21 + m._12) * is;
 			y = (m._21 + m._12) * is;
 			z = (m._31 + m._13) * is;
 			z = (m._31 + m._13) * is;
 			w = (m._23 - m._32) * is;
 			w = (m._23 - m._32) * is;
 		} else if( m._22 > m._33 ) {
 		} else if( m._22 > m._33 ) {
-			var s = FMath.sqrt(1.0 + m._22 - m._11 - m._33) * 2;
+			var s = (1.0 + m._22 - m._11 - m._33).sqrt() * 2;
 			var is = 1 / s;
 			var is = 1 / s;
 			x = (m._21 + m._12) * is;
 			x = (m._21 + m._12) * is;
 			y = 0.25 * s;
 			y = 0.25 * s;
 			z = (m._32 + m._23) * is;
 			z = (m._32 + m._23) * is;
 			w = (m._31 - m._13) * is;
 			w = (m._31 - m._13) * is;
 		} else {
 		} else {
-			var s = FMath.sqrt(1.0 + m._33 - m._11 - m._22) * 2;
+			var s = (1.0 + m._33 - m._11 - m._22).sqrt() * 2;
 			var is = 1 / s;
 			var is = 1 / s;
 			x = (m._31 + m._13) * is;
 			x = (m._31 + m._13) * is;
 			y = (m._32 + m._23) * is;
 			y = (m._32 + m._23) * is;
@@ -79,11 +84,11 @@ class Quat {
 	
 	
 	public function normalize() {
 	public function normalize() {
 		var len = x * x + y * y + z * z + w * w;
 		var len = x * x + y * y + z * z + w * w;
-		if( len < FMath.EPSILON ) {
+		if( len < hxd.Math.EPSILON ) {
 			x = y = z = 0;
 			x = y = z = 0;
 			w = 1;
 			w = 1;
 		} else {
 		} else {
-			var m = FMath.isqrt(len);
+			var m = len.isqrt();
 			x *= m;
 			x *= m;
 			y *= m;
 			y *= m;
 			z *= m;
 			z *= m;
@@ -92,12 +97,12 @@ class Quat {
 	}
 	}
 	
 	
 	public function initRotate( ax : Float, ay : Float, az : Float ) {
 	public function initRotate( ax : Float, ay : Float, az : Float ) {
-		var sinX = FMath.sin( ax * 0.5 );
-		var cosX = FMath.cos( ax * 0.5 );
-		var sinY = FMath.sin( ay * 0.5 );
-		var cosY = FMath.cos( ay * 0.5 );
-		var sinZ = FMath.sin( az * 0.5 );
-		var cosZ = FMath.cos( az * 0.5 );
+		var sinX = ( ax * 0.5 ).sin();
+		var cosX = ( ax * 0.5 ).cos();
+		var sinY = ( ay * 0.5 ).sin();
+		var cosY = ( ay * 0.5 ).cos();
+		var sinZ = ( az * 0.5 ).sin();
+		var cosZ = ( az * 0.5 ).cos();
 		var cosYZ = cosY * cosZ;
 		var cosYZ = cosY * cosZ;
 		var sinYZ = sinY * sinZ;
 		var sinYZ = sinY * sinZ;
 		x = sinX * cosYZ - cosX * sinYZ;
 		x = sinX * cosYZ - cosX * sinYZ;
@@ -125,9 +130,9 @@ class Quat {
 	
 	
 	public function toEuler() {
 	public function toEuler() {
 		return new Vector(
 		return new Vector(
-			FMath.atan2(2 * (y * w + x * z), 1 - 2 * (y * y + z * z)),
-			Math.asin(2 * (x * y + z * w)),
-			FMath.atan2(2 * (x * w - y * z), 1 - 2 * (x * x + z * z))
+			hxd.Math.atan2(2 * (y * w + x * z), 1 - 2 * (y * y + z * z)),
+			(2 * (x * y + z * w)).asin(),
+			hxd.Math.atan2(2 * (x * w - y * z), 1 - 2 * (x * x + z * z))
 		);
 		);
 	}
 	}
 	
 	
@@ -149,21 +154,21 @@ class Quat {
 
 
 	public function slerp( q1 : Quat, q2 : Quat, v : Float ) {
 	public function slerp( q1 : Quat, q2 : Quat, v : Float ) {
 		var cosHalfTheta = q1.dot(q2);
 		var cosHalfTheta = q1.dot(q2);
-		if( FMath.abs(cosHalfTheta) >= 1 ) {
+		if( cosHalfTheta.abs() >= 1 ) {
 			this.x = q1.x;
 			this.x = q1.x;
 			this.y = q1.y;
 			this.y = q1.y;
 			this.z = q1.z;
 			this.z = q1.z;
 			this.w = q1.w;
 			this.w = q1.w;
 			return;
 			return;
 		}
 		}
-		var halfTheta = Math.acos(cosHalfTheta);
-		var invSinHalfTheta = FMath.isqrt(1 - cosHalfTheta * cosHalfTheta);
-		if( FMath.abs(invSinHalfTheta) > 1e3 ) {
+		var halfTheta = cosHalfTheta.acos();
+		var invSinHalfTheta = (1 - cosHalfTheta * cosHalfTheta).isqrt();
+		if( invSinHalfTheta.abs() > 1e3 ) {
 			this.lerp(q1, q2, 0.5, true);
 			this.lerp(q1, q2, 0.5, true);
 			return;
 			return;
 		}
 		}
-		var a = Math.sin((1 - v) * halfTheta) * invSinHalfTheta;
-		var b = Math.sin(v * halfTheta) * invSinHalfTheta * (cosHalfTheta < 0 ? -1 : 1);
+		var a = ((1 - v) * halfTheta).sin() * invSinHalfTheta;
+		var b = (v * halfTheta).sin() * invSinHalfTheta * (cosHalfTheta < 0 ? -1 : 1);
 		this.x = q1.x * a + q2.x * b;
 		this.x = q1.x * a + q2.x * b;
 		this.y = q1.y * a + q2.y * b;
 		this.y = q1.y * a + q2.y * b;
 		this.z = q1.z * a + q2.z * b;
 		this.z = q1.z * a + q2.z * b;
@@ -223,7 +228,7 @@ class Quat {
 	}
 	}
 	
 	
 	public function toString() {
 	public function toString() {
-		return "{"+FMath.fmt(x)+","+FMath.fmt(y)+","+FMath.fmt(z)+","+FMath.fmt(w)+"}";
+		return '{${x.fmt()},${y.fmt()},${z.fmt()},${w.fmt()}}';
 	}
 	}
 	
 	
 }
 }

+ 5 - 4
h3d/Vector.hx

@@ -1,4 +1,5 @@
 package h3d;
 package h3d;
+using hxd.Math;
 
 
 class Vector {
 class Vector {
 
 
@@ -50,12 +51,12 @@ class Vector {
 	}
 	}
 
 
 	public inline function length() {
 	public inline function length() {
-		return FMath.sqrt(lengthSq());
+		return lengthSq().sqrt();
 	}
 	}
 
 
 	public function normalize() {
 	public function normalize() {
 		var k = lengthSq();
 		var k = lengthSq();
-		if( k < FMath.EPSILON ) k = 0 else k = FMath.isqrt(k);
+		if( k < hxd.Math.EPSILON ) k = 0 else k = k.isqrt();
 		x *= k;
 		x *= k;
 		y *= k;
 		y *= k;
 		z *= k;
 		z *= k;
@@ -114,7 +115,7 @@ class Vector {
 	}
 	}
 	
 	
 	public inline function toColor() {
 	public inline function toColor() {
-		return (Std.int(FMath.clamp(w) * 255) << 24) | (Std.int(FMath.clamp(x) * 255) << 16) | (Std.int(FMath.clamp(y) * 255) << 8) | Std.int(FMath.clamp(z) * 255);
+		return (Std.int(w.clamp() * 255) << 24) | (Std.int(x.clamp() * 255) << 16) | (Std.int(y.clamp() * 255) << 8) | Std.int(z.clamp() * 255);
 	}
 	}
 	
 	
 	public static inline function fromColor( c : Int, scale : Float = 1.0 ) {
 	public static inline function fromColor( c : Int, scale : Float = 1.0 ) {
@@ -127,7 +128,7 @@ class Vector {
 	}
 	}
 
 
 	public function toString() {
 	public function toString() {
-		return "{"+FMath.fmt(x)+","+FMath.fmt(y)+","+FMath.fmt(z)+","+FMath.fmt(w)+"}";
+		return '{${x.fmt()},${y.fmt()},${z.fmt()},${w.fmt()}}';
 	}
 	}
 
 
 }
 }

+ 11 - 10
h3d/col/Bounds.hx

@@ -1,4 +1,5 @@
 package h3d.col;
 package h3d.col;
+import hxd.Math;
 
 
 class Bounds {
 class Bounds {
 	
 	
@@ -126,7 +127,7 @@ class Bounds {
 		if( b.zMax > zMax ) zMax = b.zMax;
 		if( b.zMax > zMax ) zMax = b.zMax;
 	}
 	}
 
 
-	public inline function addPoint( p : Vector ) {
+	public inline function addPoint( p : Point ) {
 		if( p.x < xMin ) xMin = p.x;
 		if( p.x < xMin ) xMin = p.x;
 		if( p.x > xMax ) xMax = p.x;
 		if( p.x > xMax ) xMax = p.x;
 		if( p.y < yMin ) yMin = p.y;
 		if( p.y < yMin ) yMin = p.y;
@@ -136,12 +137,12 @@ class Bounds {
 	}
 	}
 	
 	
 	public function intersection( a : Bounds, b : Bounds ) {
 	public function intersection( a : Bounds, b : Bounds ) {
-		var xMin = FMath.max(a.xMin, b.xMin);
-		var yMin = FMath.max(a.yMin, b.yMin);
-		var zMin = FMath.max(a.zMin, b.zMin);
-		var xMax = FMath.max(a.xMax, b.xMax);
-		var yMax = FMath.max(a.yMax, b.yMax);
-		var zMax = FMath.max(a.zMax, b.zMax);
+		var xMin = Math.max(a.xMin, b.xMin);
+		var yMin = Math.max(a.yMin, b.yMin);
+		var zMin = Math.max(a.zMin, b.zMin);
+		var xMax = Math.max(a.xMax, b.xMax);
+		var yMax = Math.max(a.yMax, b.yMax);
+		var zMax = Math.max(a.zMax, b.zMax);
 		this.xMin = xMin;
 		this.xMin = xMin;
 		this.yMin = yMin;
 		this.yMin = yMin;
 		this.zMin = zMin;
 		this.zMin = zMin;
@@ -159,13 +160,13 @@ class Bounds {
 		zMax += dz;
 		zMax += dz;
 	}
 	}
 	
 	
-	public inline function setMin( p : Vector ) {
+	public inline function setMin( p : Point ) {
 		xMin = p.x;
 		xMin = p.x;
 		yMin = p.y;
 		yMin = p.y;
 		zMin = p.z;
 		zMin = p.z;
 	}
 	}
 
 
-	public inline function setMax( p : Vector ) {
+	public inline function setMax( p : Point ) {
 		xMax = p.x;
 		xMax = p.x;
 		yMax = p.y;
 		yMax = p.y;
 		zMax = p.z;
 		zMax = p.z;
@@ -244,7 +245,7 @@ class Bounds {
 		return "{" + getMin() + "," + getMax() + "}";
 		return "{" + getMin() + "," + getMax() + "}";
 	}
 	}
 	
 	
-	public static inline function fromPoints( min : Vector, max : Vector ) {
+	public static inline function fromPoints( min : Point, max : Point ) {
 		var b = new Bounds();
 		var b = new Bounds();
 		b.setMin(min);
 		b.setMin(min);
 		b.setMax(max);
 		b.setMax(max);

+ 15 - 11
h3d/col/Plane.hx

@@ -16,10 +16,14 @@ class Plane {
 	}
 	}
 	
 	
 	/**
 	/**
-		Returns the plan normal, with the distance in the w value
+		Returns the plan normal
 	**/
 	**/
 	public inline function getNormal() {
 	public inline function getNormal() {
-		return new h3d.Vector(nx, ny, nz, d);
+		return new Point(nx, ny, nz);
+	}
+	
+	public inline function getNormalDistance() {
+		return d;
 	}
 	}
 	
 	
 	/**
 	/**
@@ -34,37 +38,37 @@ class Plane {
 	}
 	}
 	
 	
 	public function toString() {
 	public function toString() {
-		return "{" + FMath.fmt(nx) + "," + FMath.fmt(ny) + "," + FMath.fmt(nz) + "," + FMath.fmt(d) + "}";
+		return "{" + getNormal()+","+ d + "}";
 	}
 	}
 	
 	
 	/**
 	/**
 		Returns the signed distance between a point an the plane. This requires the plan to be normalized. If the distance is negative it means that we are "under" the plan.
 		Returns the signed distance between a point an the plane. This requires the plan to be normalized. If the distance is negative it means that we are "under" the plan.
 	**/
 	**/
-	public inline function distance( p : Vector ) {
+	public inline function distance( p : Point ) {
 		return nx * p.x + ny * p.y + nz * p.z - d;
 		return nx * p.x + ny * p.y + nz * p.z - d;
 	}
 	}
 	
 	
-	public inline function project( p : Vector ) : Vector {
+	public inline function project( p : Point ) : Point {
 		var d = distance(p);
 		var d = distance(p);
-		return new Vector(p.x + d * nx, p.y + d * ny, p.z + d * nz);
+		return new Point(p.x + d * nx, p.y + d * ny, p.z + d * nz);
 	}
 	}
 
 
-	public inline function projectTo( p : Vector, out : Vector ) {
+	public inline function projectTo( p : Point, out : Point ) {
 		var d = distance(p);
 		var d = distance(p);
 		out.x = p.x + d * nx;
 		out.x = p.x + d * nx;
 		out.y = p.y + d * ny;
 		out.y = p.y + d * ny;
 		out.z = p.z + d * nz;
 		out.z = p.z + d * nz;
 	}
 	}
 	
 	
-	public static inline function fromPoints( p0 : Vector, p1 : Vector, p2 : Vector ) {
+	public static inline function fromPoints( p0 : Point, p1 : Point, p2 : Point ) {
 		var d1 = p1.sub(p0);
 		var d1 = p1.sub(p0);
 		var d2 = p2.sub(p0);
 		var d2 = p2.sub(p0);
 		var n = d1.cross(d2);
 		var n = d1.cross(d2);
-		return new Plane(n.x,n.y,n.z,n.dot3(p0));
+		return new Plane(n.x,n.y,n.z,n.dot(p0));
 	}
 	}
 	
 	
-	public static inline function fromNormalPoint( n : Vector, p : Vector ) {
-		return new Plane(n.x,n.y,n.z,n.dot3(p));
+	public static inline function fromNormalPoint( n : Point, p : Point ) {
+		return new Plane(n.x,n.y,n.z,n.dot(p));
 	}
 	}
 	
 	
 	public static inline function X(v:Float) {
 	public static inline function X(v:Float) {

+ 87 - 0
h3d/col/Point.hx

@@ -0,0 +1,87 @@
+package h3d.col;
+using hxd.Math;
+
+class Point {
+
+	public var x : Float;
+	public var y : Float;
+	public var z : Float;
+	
+	public inline function new(x=0.,y=0.,z=0.) {
+		this.x = x;
+		this.y = y;
+		this.z = z;
+	}
+	
+	public inline function set(x, y, z) {
+		this.x = x;
+		this.y = y;
+		this.z = z;
+	}
+	
+	public inline function sub( p : Point ) {
+		return new Point(x - p.x, y - p.y, z - p.z);
+	}
+
+	public inline function add( p : Point ) {
+		return new Point(x + p.x, y + p.y, z + p.z);
+	}
+	
+	public inline function cross( p : Point ) {
+		return new Point(y * p.z - z * p.y, z * p.x - x * p.z,  x * p.y - y * p.x);
+	}
+	
+	public inline function lengthSq() {
+		return x * x + y * y + z * z;
+	}
+	
+	public inline function length() {
+		return lengthSq().sqrt();
+	}
+
+	public inline function dot( p : Point ) {
+		return x * p.x + y * p.y + z * p.z;
+	}
+	
+	public inline function distanceSq( p : Point ) {
+		var dx = p.x - x;
+		var dy = p.y - y;
+		var dz = p.z - z;
+		return dx * dx + dy * dy + dz * dz;
+	}
+
+	public inline function distance( p : Point ) {
+		return distanceSq(p).sqrt();
+	}
+
+	
+	public function normalize() {
+		var k = x * x + y * y + z * z;
+		if( k < hxd.Math.EPSILON ) k = 0 else k = k.isqrt();
+		x *= k;
+		y *= k;
+		z *= k;
+	}
+	
+	public inline function transform( m : Matrix ) {
+		var px = x * m._11 + y * m._21 + z * m._31 + m._41;
+		var py = x * m._12 + y * m._22 + z * m._32 + m._42;
+		var pz = x * m._13 + y * m._23 + z * m._33 + m._43;
+		x = px;
+		y = py;
+		z = pz;
+	}
+	
+	public inline function toVector() {
+		return new Vector(x, y, z);
+	}
+
+	public inline function clone() {
+		return new Point(x,y,z);
+	}
+
+	public function toString() {
+		return '{${x.fmt()},${y.fmt()},${z.fmt()}}';
+	}
+	
+}

+ 18 - 9
h3d/col/Ray.hx

@@ -1,4 +1,5 @@
 package h3d.col;
 package h3d.col;
+import hxd.Math;
 
 
 @:allow(h3d.col)
 @:allow(h3d.col)
 class Ray {
 class Ray {
@@ -15,25 +16,33 @@ class Ray {
 	
 	
 	public function normalize() {
 	public function normalize() {
 		var l = lx * lx + ly * ly + lz * lz;
 		var l = lx * lx + ly * ly + lz * lz;
-		if( l < FMath.EPSILON ) l = 0 else l = FMath.isqrt(l);
+		if( l < Math.EPSILON ) l = 0 else l = Math.isqrt(l);
 		lx *= l;
 		lx *= l;
 		ly *= l;
 		ly *= l;
 		lz *= l;
 		lz *= l;
 	}
 	}
 	
 	
+	public inline function getPos() {
+		return new Point(px, py, pz);
+	}
+
+	public inline function getDir() {
+		return new Point(lx, ly, lz);
+	}
+	
 	public function toString() {
 	public function toString() {
-		return "{[" + FMath.fmt(px) + "," + FMath.fmt(py) + "," + FMath.fmt(pz) + "],[" + FMath.fmt(lx) + "," + FMath.fmt(ly) + "," + FMath.fmt(lz) + "]}";
+		return "{" + getPos() + "," + getDir() + "}";
 	}
 	}
 	
 	
-	public inline function intersect( p : Plane ) : Vector {
+	public inline function intersect( p : Plane ) : Null<Point> {
 		var d = lx * p.nx + ly * p.ny + lz * p.nz;
 		var d = lx * p.nx + ly * p.ny + lz * p.nz;
 		var nd = p.d - (px * p.nx + py * p.ny + pz * p.nz);
 		var nd = p.d - (px * p.nx + py * p.ny + pz * p.nz);
 		// line parallel with plane
 		// line parallel with plane
-		if( FMath.abs(d) < FMath.EPSILON )
-			return FMath.abs(nd) < FMath.EPSILON ? new Vector(px, py, pz) : null;
+		if( Math.abs(d) < Math.EPSILON )
+			return Math.abs(nd) < Math.EPSILON ? new Point(px, py, pz) : null;
 		else {
 		else {
 			var k = nd / d;
 			var k = nd / d;
-			return new Vector(px + lx * k, py + ly * k, pz + lz * k);
+			return new Point(px + lx * k, py + ly * k, pz + lz * k);
 		}
 		}
 	}
 	}
 
 
@@ -47,8 +56,8 @@ class Ray {
 		var t4 = (b.yMax - py) * dy;
 		var t4 = (b.yMax - py) * dy;
 		var t5 = (b.zMin - pz) * dz;
 		var t5 = (b.zMin - pz) * dz;
 		var t6 = (b.zMax - pz) * dz;
 		var t6 = (b.zMax - pz) * dz;
-		var tmin = FMath.max(FMath.max(FMath.min(t1, t2), FMath.min(t3, t4)), FMath.min(t5, t6));
-		var tmax = FMath.min(FMath.min(FMath.max(t1, t2), FMath.max(t3, t4)), FMath.max(t5, t6));
+		var tmin = Math.max(Math.max(Math.min(t1, t2), Math.min(t3, t4)), Math.min(t5, t6));
+		var tmax = Math.min(Math.min(Math.max(t1, t2), Math.max(t3, t4)), Math.max(t5, t6));
 		if( tmax < 0 ) {
 		if( tmax < 0 ) {
 			// t = tmax;
 			// t = tmax;
 			return false;
 			return false;
@@ -61,7 +70,7 @@ class Ray {
 		}
 		}
 	}
 	}
 	
 	
-	public static function fromPoints( p1 : Vector, p2 : Vector ) {
+	public static function fromPoints( p1 : Point, p2 : Point ) {
 		var r = new Ray();
 		var r = new Ray();
 		r.px = p1.x;
 		r.px = p1.x;
 		r.py = p1.y;
 		r.py = p1.y;

+ 9 - 8
h3d/col/Seg.hx

@@ -1,29 +1,30 @@
 package h3d.col;
 package h3d.col;
+import hxd.Math;
 
 
 class Seg {
 class Seg {
 	
 	
-	public var p1 : Vector;
-	public var p2 : Vector;
+	public var p1 : Point;
+	public var p2 : Point;
 	public var lenSq : Float;
 	public var lenSq : Float;
 	
 	
-	public inline function new( p1 : Vector, p2 : Vector ) {
+	public inline function new( p1 : Point, p2 : Point ) {
 		this.p1 = p1;
 		this.p1 = p1;
 		this.p2 = p2;
 		this.p2 = p2;
 		lenSq = p1.distanceSq(p2);
 		lenSq = p1.distanceSq(p2);
 	}
 	}
 	
 	
-	public inline function distanceSq( p : Vector ) {
-		var t = p.sub(p1).dot3(p2.sub(p1)) / lenSq;
+	public inline function distanceSq( p : Point ) {
+		var t = p.sub(p1).dot(p2.sub(p1)) / lenSq;
 		return if( t < 0 )
 		return if( t < 0 )
 			p.distanceSq(p1);
 			p.distanceSq(p1);
 		else if( t > 1 ) {
 		else if( t > 1 ) {
 			p.distanceSq(p2);
 			p.distanceSq(p2);
 		} else
 		} else
-			p.distanceSq(new Vector(p1.x + t * (p2.x - p1.x), p1.y + t * (p2.y - p1.y)));
+			p.distanceSq(new Point(p1.x + t * (p2.x - p1.x), p1.y + t * (p2.y - p1.y)));
 	}
 	}
 	
 	
-	public inline function distance( p : Vector ) {
-		return FMath.sqrt(distanceSq(p));
+	public inline function distance( p : Point ) {
+		return Math.sqrt(distanceSq(p));
 	}
 	}
 	
 	
 }
 }

+ 1 - 1
h3d/fbx/Geometry.hx

@@ -92,7 +92,7 @@ class Geometry {
 	public function getGeomTranslate() {
 	public function getGeomTranslate() {
 		for( p in lib.getParent(root, "Model").getAll("Properties70.P") )
 		for( p in lib.getParent(root, "Model").getAll("Properties70.P") )
 			if( p.props[0].toString() == "GeometricTranslation" )
 			if( p.props[0].toString() == "GeometricTranslation" )
-				return new h3d.prim.Point(p.props[4].toFloat() * (lib.leftHand ? -1 : 1), p.props[5].toFloat(), p.props[6].toFloat());
+				return new h3d.col.Point(p.props[4].toFloat() * (lib.leftHand ? -1 : 1), p.props[5].toFloat(), p.props[6].toFloat());
 		return null;
 		return null;
 	}
 	}
 
 

+ 3 - 3
h3d/fbx/Library.hx

@@ -1,6 +1,6 @@
 package h3d.fbx;
 package h3d.fbx;
 using h3d.fbx.Data;
 using h3d.fbx.Data;
-import h3d.prim.Point;
+import h3d.col.Point;
 
 
 enum AnimationMode {
 enum AnimationMode {
 	FrameAnim;
 	FrameAnim;
@@ -226,8 +226,8 @@ class Library {
 		}
 		}
 
 
 		var curves = new Map();
 		var curves = new Map();
-		var P0 = new h3d.prim.Point();
-		var P1 = new h3d.prim.Point(1, 1, 1);
+		var P0 = new Point();
+		var P1 = new Point(1, 1, 1);
 		var F = Math.PI / 180;
 		var F = Math.PI / 180;
 		var allTimes = new Map();
 		var allTimes = new Map();
 		for( cn in getChilds(animNode, "AnimationCurveNode") ) {
 		for( cn in getChilds(animNode, "AnimationCurveNode") ) {

+ 1 - 0
h3d/prim/Cube.hx

@@ -1,4 +1,5 @@
 package h3d.prim;
 package h3d.prim;
+import h3d.col.Point;
 
 
 class Cube extends Polygon {
 class Cube extends Polygon {
 
 

+ 1 - 0
h3d/prim/Cylinder.hx

@@ -1,4 +1,5 @@
 package h3d.prim;
 package h3d.prim;
+import h3d.col.Point;
 
 
 class Cylinder extends Quads {
 class Cylinder extends Quads {
 	
 	

+ 3 - 2
h3d/prim/FBXModel.hx

@@ -1,6 +1,7 @@
 package h3d.prim;
 package h3d.prim;
 using h3d.fbx.Data;
 using h3d.fbx.Data;
 import h3d.impl.Buffer.BufferOffset;
 import h3d.impl.Buffer.BufferOffset;
+import h3d.col.Point;
 
 
 class FBXModel extends MeshPrimitive {
 class FBXModel extends MeshPrimitive {
 
 
@@ -26,7 +27,7 @@ class FBXModel extends MeshPrimitive {
 		bounds = new h3d.col.Bounds();
 		bounds = new h3d.col.Bounds();
 		var verts = geom.getVertices();
 		var verts = geom.getVertices();
 		var gt = geom.getGeomTranslate();
 		var gt = geom.getGeomTranslate();
-		if( gt == null ) gt = new h3d.prim.Point();
+		if( gt == null ) gt = new Point();
 		if( verts.length > 0 ) {
 		if( verts.length > 0 ) {
 			bounds.xMin = bounds.xMax = verts[0] + gt.x;
 			bounds.xMin = bounds.xMax = verts[0] + gt.x;
 			bounds.yMin = bounds.yMax = verts[1] + gt.y;
 			bounds.yMin = bounds.yMax = verts[1] + gt.y;
@@ -85,7 +86,7 @@ class FBXModel extends MeshPrimitive {
 		var mats = multiMaterial ? geom.getMaterials() : null;
 		var mats = multiMaterial ? geom.getMaterials() : null;
 		
 		
 		var gt = geom.getGeomTranslate();
 		var gt = geom.getGeomTranslate();
-		if( gt == null ) gt = new h3d.prim.Point();
+		if( gt == null ) gt = new Point();
 		
 		
 		var idx = new hxd.IndexBuffer();
 		var idx = new hxd.IndexBuffer();
 		var midx = new Array<hxd.IndexBuffer>();
 		var midx = new Array<hxd.IndexBuffer>();

+ 1 - 0
h3d/prim/GeoSphere.hx

@@ -1,4 +1,5 @@
 package h3d.prim;
 package h3d.prim;
+import h3d.col.Point;
 
 
 class GeoSphere extends Polygon {
 class GeoSphere extends Polygon {
 
 

+ 0 - 55
h3d/prim/Point.hx

@@ -1,55 +0,0 @@
-package h3d.prim;
-
-class Point {
-
-	public var x : Float;
-	public var y : Float;
-	public var z : Float;
-	
-	public inline function new(x=0.,y=0.,z=0.) {
-		this.x = x;
-		this.y = y;
-		this.z = z;
-	}
-	
-	public inline function sub( p : Point ) {
-		return new Point(x - p.x, y - p.y, z - p.z);
-	}
-
-	public inline function add( p : Point ) {
-		return new Point(x + p.x, y + p.y, z + p.z);
-	}
-	
-	public inline function cross( p : Point ) {
-		return new Vector(y * p.z - z * p.y, z * p.x - x * p.z,  x * p.y - y * p.x);
-	}
-	
-	public inline function length() {
-		return FMath.sqrt(x * x + y * y + z * z);
-	}
-
-	public function normalize() {
-		var k = x * x + y * y + z * z;
-		if( k < FMath.EPSILON ) k = 0 else k = FMath.isqrt(k);
-		x *= k;
-		y *= k;
-		z *= k;
-	}
-	
-	public function transform( m : Matrix ) {
-		return new Point(x * m._11 + y * m._21 + z * m._31 + m._41, x * m._12 + y * m._22 + z * m._32 + m._42, x * m._13 + y * m._23 + z * m._33 + m._43);
-	}
-	
-	public inline function toVector() {
-		return new Vector(x, y, z);
-	}
-
-	public inline function clone() {
-		return new Point(x,y,z);
-	}
-
-	public function toString() {
-		return "{"+FMath.fmt(x)+","+FMath.fmt(y)+","+FMath.fmt(z)+"}";
-	}
-	
-}

+ 1 - 0
h3d/prim/Polygon.hx

@@ -1,4 +1,5 @@
 package h3d.prim;
 package h3d.prim;
+import h3d.col.Point;
 
 
 class Polygon extends Primitive {
 class Polygon extends Primitive {
 
 

+ 1 - 0
h3d/prim/Quads.hx

@@ -1,4 +1,5 @@
 package h3d.prim;
 package h3d.prim;
+import h3d.col.Point;
 
 
 class Quads extends Primitive {
 class Quads extends Primitive {
 
 

+ 1 - 0
h3d/prim/Sphere.hx

@@ -1,4 +1,5 @@
 package h3d.prim;
 package h3d.prim;
+import h3d.col.Point;
 
 
 class Sphere extends Polygon {
 class Sphere extends Polygon {
 	
 	

+ 9 - 9
h3d/scene/Object.hx

@@ -86,30 +86,30 @@ class Object {
 		if( defaultTransform != null ) {
 		if( defaultTransform != null ) {
 			var xMin = b.xMin, yMin = b.yMin, zMin = b.zMin, xMax = b.xMax, yMax = b.yMax, zMax = b.zMax;
 			var xMin = b.xMin, yMin = b.yMin, zMin = b.zMin, xMax = b.xMax, yMax = b.yMax, zMax = b.zMax;
 			b.empty();
 			b.empty();
-			var v = new Vector();
+			var v = new h3d.col.Point();
 			v.set(xMin, yMin, zMin);
 			v.set(xMin, yMin, zMin);
-			v.transform3x4(defaultTransform);
+			v.transform(defaultTransform);
 			b.addPoint(v);
 			b.addPoint(v);
 			v.set(xMin, yMin, zMax);
 			v.set(xMin, yMin, zMax);
-			v.transform3x4(defaultTransform);
+			v.transform(defaultTransform);
 			b.addPoint(v);
 			b.addPoint(v);
 			v.set(xMin, yMax, zMin);
 			v.set(xMin, yMax, zMin);
-			v.transform3x4(defaultTransform);
+			v.transform(defaultTransform);
 			b.addPoint(v);
 			b.addPoint(v);
 			v.set(xMin, yMax, zMax);
 			v.set(xMin, yMax, zMax);
-			v.transform3x4(defaultTransform);
+			v.transform(defaultTransform);
 			b.addPoint(v);
 			b.addPoint(v);
 			v.set(xMax, yMin, zMin);
 			v.set(xMax, yMin, zMin);
-			v.transform3x4(defaultTransform);
+			v.transform(defaultTransform);
 			b.addPoint(v);
 			b.addPoint(v);
 			v.set(xMax, yMin, zMax);
 			v.set(xMax, yMin, zMax);
-			v.transform3x4(defaultTransform);
+			v.transform(defaultTransform);
 			b.addPoint(v);
 			b.addPoint(v);
 			v.set(xMax, yMax, zMin);
 			v.set(xMax, yMax, zMin);
-			v.transform3x4(defaultTransform);
+			v.transform(defaultTransform);
 			b.addPoint(v);
 			b.addPoint(v);
 			v.set(xMax, yMax, zMax);
 			v.set(xMax, yMax, zMax);
-			v.transform3x4(defaultTransform);
+			v.transform(defaultTransform);
 			b.addPoint(v);
 			b.addPoint(v);
 		}
 		}
 		return b;
 		return b;

+ 122 - 0
hxd/Math.hx

@@ -0,0 +1,122 @@
+package hxd;
+
+class Math {
+	
+	public static inline var PI = 3.14159265358979323;
+	public static inline var EPSILON = 1e-10;
+
+	public static var POSITIVE_INFINITY(get, never) : Float;
+	public static var NEGATIVE_INFINITY(get, never) : Float;
+	
+	static inline function get_POSITIVE_INFINITY() {
+		return std.Math.POSITIVE_INFINITY;
+	}
+
+	static inline function get_NEGATIVE_INFINITY() {
+		return std.Math.NEGATIVE_INFINITY;
+	}
+	
+	// round to 4 significant digits, eliminates <1e-10
+	public static function fmt( v : Float ) {
+		var neg;
+		if( v < 0 ) {
+			neg = -1.0;
+			v = -v;
+		} else
+			neg = 1.0;
+		if( std.Math.isNaN(v) )
+			return v;
+		var digits = Std.int(4 - std.Math.log(v) / std.Math.log(10));
+		if( digits < 1 )
+			digits = 1;
+		else if( digits >= 10 )
+			return 0.;
+		var exp = pow(10,digits);
+		return floor(v * exp + .49999) * neg / exp;
+	}
+	
+	public static inline function floor( f : Float ) {
+		return std.Math.floor(f);
+	}
+
+	public static inline function ceil( f : Float ) {
+		return std.Math.ceil(f);
+	}
+
+	public static inline function round( f : Float ) {
+		return std.Math.round(f);
+	}
+	
+	public static inline function clamp( f : Float, min = 0., max = 1. ) {
+		return f < min ? min : f > max ? max : f;
+	}
+
+	public static inline function pow( v : Float, p : Float ) {
+		return std.Math.pow(v,p);
+	}
+	
+	public static inline function cos( f : Float ) {
+		return std.Math.cos(f);
+	}
+
+	public static inline function sin( f : Float ) {
+		return std.Math.sin(f);
+	}
+
+	public static inline function tan( f : Float ) {
+		return std.Math.tan(f);
+	}
+
+	public static inline function acos( f : Float ) {
+		return std.Math.acos(f);
+	}
+
+	public static inline function asin( f : Float ) {
+		return std.Math.asin(f);
+	}
+
+	public static inline function atan( f : Float ) {
+		return std.Math.atan(f);
+	}
+	
+	public static inline function sqrt( f : Float ) {
+		return std.Math.sqrt(f);
+	}
+
+	public static inline function isqrt( f : Float ) {
+		return 1. / sqrt(f);
+	}
+	
+	public static inline function atan2( dy : Float, dx : Float ) {
+		return std.Math.atan2(dy,dx);
+	}
+	
+	public static inline function abs( f : Float ) {
+		return f < 0 ? -f : f;
+	}
+
+	public static inline function max( a : Float, b : Float ) {
+		return a < b ? b : a;
+	}
+
+	public static inline function min( a : Float, b : Float ) {
+		return a > b ? b : a;
+	}
+	
+	public static inline function iabs( i : Int ) {
+		return i < 0 ? -i : i;
+	}
+
+	public static inline function imax( a : Int, b : Int ) {
+		return a < b ? b : a;
+	}
+
+	public static inline function imin( a : Int, b : Int ) {
+		return a > b ? b : a;
+	}
+
+	public static inline function iclamp( v : Int, min : Int, max : Int ) {
+		return v < min ? min : (v > max ? max : v);
+	}
+	
+}

+ 36 - 3
hxd/Perlin.hx

@@ -3,10 +3,15 @@ package hxd;
 class Perlin {
 class Perlin {
 
 
 	public var repeat : Int;
 	public var repeat : Int;
+	#if flash
 	var buf : flash.utils.ByteArray;
 	var buf : flash.utils.ByteArray;
+	#else
+	var gradients : Array<Float>;
+	#end
 	
 	
 	public function new() {
 	public function new() {
 		repeat = 0x7FFFFFFF;
 		repeat = 0x7FFFFFFF;
+		#if flash
 		// space for gradients
 		// space for gradients
 		buf = new flash.utils.ByteArray();
 		buf = new flash.utils.ByteArray();
 		buf.length += NGRADS * 4 * 8;
 		buf.length += NGRADS * 4 * 8;
@@ -19,19 +24,33 @@ class Perlin {
 			setDouble(p + 16, GRADIENTS[i * 3 + 2] * 2.12);
 			setDouble(p + 16, GRADIENTS[i * 3 + 2] * 2.12);
 			setDouble(p + 24, 0); // padding
 			setDouble(p + 24, 0); // padding
 		}
 		}
+		#else
+		gradients = [];
+		for( i in 0...NGRADS ) {
+			gradients.push(GRADIENTS[i * 3] * 2.12);
+			gradients.push(GRADIENTS[i * 3 + 1] * 2.12);
+			gradients.push(GRADIENTS[i * 3 + 2] * 2.12);
+			gradients.push(0); // padding
+		}
+		#end
 	}
 	}
 
 
 	public inline function select() {
 	public inline function select() {
+		#if flash
 		flash.Memory.select(buf);
 		flash.Memory.select(buf);
+		#end
 	}
 	}
 
 
+	#if flash
 	inline function setDouble( index : Int, v : Float )  {
 	inline function setDouble( index : Int, v : Float )  {
 		flash.Memory.setDouble(index, v);
 		flash.Memory.setDouble(index, v);
 	}
 	}
 	
 	
 	inline function double( index : Int ) : Float {
 	inline function double( index : Int ) : Float {
 		return flash.Memory.getDouble(index);
 		return flash.Memory.getDouble(index);
+		
 	}
 	}
+	#end
 	
 	
 	inline function scurve( a : Float ) {
 	inline function scurve( a : Float ) {
 		var a2 = a * a;
 		var a2 = a * a;
@@ -44,18 +63,32 @@ class Perlin {
 	
 	
 	inline function gradient3DAt( x : Float, y : Float, z : Float, ix : Int, iy : Int, iz : Int, seed : Int ) {
 	inline function gradient3DAt( x : Float, y : Float, z : Float, ix : Int, iy : Int, iz : Int, seed : Int ) {
 		var index = seed * 1013 + (ix % repeat) * 1619 + (iy % repeat) * 31337 + iz * 6971;
 		var index = seed * 1013 + (ix % repeat) * 1619 + (iy % repeat) * 31337 + iz * 6971;
-		index = ((index ^ (index >>> 8)) & 0xFF) << 5;
+		index = ((index ^ (index >>> 8)) & 0xFF);
+		#if flash
+		index <<= 5;
 		var gx = double(index);
 		var gx = double(index);
 		var gy = double(index + 8);
 		var gy = double(index + 8);
 		var gz = double(index + 16);
 		var gz = double(index + 16);
+		#else
+		index <<= 2;
+		var gx = gradients[index];
+		var gy = gradients[index + 1];
+		var gz = gradients[index + 2];
+		#end
 		return gx * (x - ix) + gy * (y - iy) + gz * (z - iz);
 		return gx * (x - ix) + gy * (y - iy) + gz * (z - iz);
 	}
 	}
 
 
 	inline function gradientAt( x : Float, y : Float, ix : Int, iy : Int, seed : Int ) {
 	inline function gradientAt( x : Float, y : Float, ix : Int, iy : Int, seed : Int ) {
 		var index = seed * 1013 + (ix%repeat) * 1619 + (iy%repeat) * 31337;
 		var index = seed * 1013 + (ix%repeat) * 1619 + (iy%repeat) * 31337;
-		index = ((index ^ (index >>> 8)) & 0xFF) << 5;
+		index = ((index ^ (index >>> 8)) & 0xFF);
+		#if flash
+		index <<= 5;
 		var gx = double(index);
 		var gx = double(index);
 		var gy = double(index + 8);
 		var gy = double(index + 8);
+		#else
+		var gx = gradients[index << 2];
+		var gy = gradients[(index << 2) + 1];
+		#end
 		return gx * (x - ix) + gy * (y - iy);
 		return gx * (x - ix) + gy * (y - iy);
 	}
 	}
 	
 	
@@ -114,7 +147,7 @@ class Perlin {
 		var tot = 0.;
 		var tot = 0.;
 		for( i in 0...octaves ) {
 		for( i in 0...octaves ) {
 			var g = gradient(seed + i, x * s, y * s) * p;
 			var g = gradient(seed + i, x * s, y * s) * p;
-			g = offset - h3d.FMath.abs(g);
+			g = offset - hxd.Math.abs(g);
 			g *= g;
 			g *= g;
 			g *= weight;
 			g *= weight;
 			v += g * s;
 			v += g * s;

+ 13 - 0
hxd/impl/Memory.hx

@@ -1,16 +1,25 @@
 package hxd.impl;
 package hxd.impl;
 
 
+@:access(hxd.impl.Memory)
 class MemoryReader {
 class MemoryReader {
 
 
 	public function new() {
 	public function new() {
 	}
 	}
 	
 	
 	public inline function b( addr : Int ) {
 	public inline function b( addr : Int ) {
+		#if flash
 		return flash.Memory.getByte(addr);
 		return flash.Memory.getByte(addr);
+		#else
+		return Memory.current.get(addr);
+		#end
 	}
 	}
 	
 	
 	public inline function wb( addr : Int, v : Int ) {
 	public inline function wb( addr : Int, v : Int ) {
+		#if flash
 		flash.Memory.setByte(addr, v);
 		flash.Memory.setByte(addr, v);
+		#else
+		Memory.current.set(addr, v);
+		#end
 	}
 	}
 	
 	
 	public inline function end() {
 	public inline function end() {
@@ -26,7 +35,9 @@ class Memory {
 	static var inst = new MemoryReader();
 	static var inst = new MemoryReader();
 	
 	
 	public static function select( b : haxe.io.Bytes ) {
 	public static function select( b : haxe.io.Bytes ) {
+		#if flash
 		flash.Memory.select(b.getData());
 		flash.Memory.select(b.getData());
+		#end
 		if( current != null ) stack.push(current);
 		if( current != null ) stack.push(current);
 		current = b;
 		current = b;
 		return inst;
 		return inst;
@@ -34,8 +45,10 @@ class Memory {
 	
 	
 	static function end() {
 	static function end() {
 		current = stack.pop();
 		current = stack.pop();
+		#if flash
 		if( current != null )
 		if( current != null )
 			flash.Memory.select(current.getData());
 			flash.Memory.select(current.getData());
+		#end
 	}
 	}
 
 
 }
 }

+ 1 - 1
hxd/res/FileTree.hx

@@ -39,7 +39,7 @@ class FileTree {
 		}
 		}
 		var pos = Context.currentPos();
 		var pos = Context.currentPos();
 		if( resolve )
 		if( resolve )
-			dir = try Context.resolvePath(dir) catch( e : Dynamic ) Context.error("Resource directory not found in classpath '" + dir + "'", pos);
+			dir = try Context.resolvePath(dir) catch( e : Dynamic ) Context.error("Resource directory not found in classpath '" + dir + "' (use -D resourcesPath=DIR)", pos);
 		var path = sys.FileSystem.fullPath(dir);
 		var path = sys.FileSystem.fullPath(dir);
 		if( !sys.FileSystem.exists(path) || !sys.FileSystem.isDirectory(path) )
 		if( !sys.FileSystem.exists(path) || !sys.FileSystem.isDirectory(path) )
 			Context.error("Resource directory does not exists '" + path + "'", pos);
 			Context.error("Resource directory does not exists '" + path + "'", pos);

+ 2 - 1
samples/2d/Demo.hx

@@ -22,7 +22,7 @@ class Demo {
 		tf.text = "Hello h2d !";
 		tf.text = "Hello h2d !";
 		#end
 		#end
 		
 		
-		var tile = hxd.Resource.embed("texture.png").toTile();
+		var tile = hxd.Res.hxlogo.toTile();
 		spr = new h2d.Sprite(scene);
 		spr = new h2d.Sprite(scene);
 		spr.x = engine.width >> 1;
 		spr.x = engine.width >> 1;
 		spr.y = engine.height >> 1;
 		spr.y = engine.height >> 1;
@@ -43,6 +43,7 @@ class Demo {
 	}
 	}
 	
 	
 	static function main() {
 	static function main() {
+		hxd.Res.loader = new hxd.res.Loader(hxd.res.EmbedFileSystem.create());
 		new Demo();
 		new Demo();
 	}
 	}
 	
 	

+ 2 - 2
samples/2d/demo.hxml

@@ -1,7 +1,7 @@
 -swf demo.swf
 -swf demo.swf
 -swf-header 800:600:60:FFFFFF
 -swf-header 800:600:60:FFFFFF
 --flash-strict
 --flash-strict
--swf-version 11
+-swf-version 11.6
 -main Demo
 -main Demo
 -lib h3d
 -lib h3d
--swf-version 11.6
+-D resourcesPath=../res

+ 2 - 2
samples/2d/demo.hxproj

@@ -9,7 +9,7 @@
     <movie width="800" />
     <movie width="800" />
     <movie height="600" />
     <movie height="600" />
     <movie version="11" />
     <movie version="11" />
-    <movie minorVersion="0" />
+    <movie minorVersion="6" />
     <movie platform="Flash Player" />
     <movie platform="Flash Player" />
     <movie background="#FFFFFF" />
     <movie background="#FFFFFF" />
   </output>
   </output>
@@ -23,7 +23,7 @@
     <option flashStrict="True" />
     <option flashStrict="True" />
     <option mainClass="Demo" />
     <option mainClass="Demo" />
     <option enabledebug="False" />
     <option enabledebug="False" />
-    <option additional="-lib h3d&#xA;-swf-version 11.6" />
+    <option additional="-lib h3d&#xA;-D resourcesPath=../res" />
   </build>
   </build>
   <!-- haxelib libraries -->
   <!-- haxelib libraries -->
   <haxelib>
   <haxelib>

+ 1 - 1
samples/comps/Comps.hx

@@ -15,7 +15,7 @@ class Comps {
 	function init() {
 	function init() {
 		hxd.System.setLoop(update);
 		hxd.System.setLoop(update);
 		scene = new h2d.Scene();
 		scene = new h2d.Scene();
-		var document = h2d.comp.Parser.fromHtml(hxd.Resource.getFileContent("components.html"),{ fmt : h3d.FMath.fmt });
+		var document = h2d.comp.Parser.fromHtml(hxd.res.Embed.getFileContent("components.html"),{ fmt : hxd.Math.fmt });
 		scene.addChild(document);
 		scene.addChild(document);
 		engine.onResized = function() document.setStyle(null);
 		engine.onResized = function() document.setStyle(null);
 	}
 	}

BIN
samples/comps/comps.swf