Browse Source

Adding packNormal/unpackNormal/normalStrength to Vector.

clementlandrin 1 year ago
parent
commit
1c0ea4d6d8
1 changed files with 19 additions and 0 deletions
  1. 19 0
      h3d/Vector.hx

+ 19 - 0
h3d/Vector.hx

@@ -77,6 +77,25 @@ class VectorImpl #if apicheck implements h2d.impl.PointApi<Vector,Matrix> #end {
 		return new Vector(x * k, y * k, z * k);
 		return new Vector(x * k, y * k, z * k);
 	}
 	}
 
 
+	public inline function packNormal() {
+		x = x * 0.5 + 0.5;
+		y = y * 0.5 + 0.5;
+		z = z * 0.5 + 0.5;
+	}
+
+	public inline function unpackNormal() {
+		x = x * 2.0 - 1.0;
+		y = y * 2.0 - 1.0;
+		z = z * 2.0 - 1.0;
+	}
+
+	public inline function normalStrength(strength : Float) {
+		var k = 1.0 / strength;
+		x *= k;
+		y *= k;
+		normalize();
+	}
+
 	public inline function set(x=0.,y=0.,z=0.) {
 	public inline function set(x=0.,y=0.,z=0.) {
 		this.x = x;
 		this.x = x;
 		this.y = y;
 		this.y = y;