Explorar o código

added hxd.Math.ease

Nicolas Cannasse %!s(int64=4) %!d(string=hai) anos
pai
achega
6f41609ec8
Modificáronse 2 ficheiros con 16 adicións e 2 borrados
  1. 1 2
      h3d/anim/SmoothTarget.hx
  2. 15 0
      hxd/Math.hx

+ 1 - 2
h3d/anim/SmoothTarget.hx

@@ -100,8 +100,7 @@ class SmoothTarget extends Animation {
 		var objects = getSmoothObjects();
 		var objects = getSmoothObjects();
 		target.sync(true);
 		target.sync(true);
 
 
-		var bpow = Math.pow(blend, 1 + easing);
-		var blend = bpow / (bpow + Math.pow(1 - blend, easing + 1));
+		var blend = hxd.Math.easeFactor(blend, easing);
 
 
 		for( o in objects ) {
 		for( o in objects ) {
 			var m = @:privateAccess if( o.targetSkin != null ) o.targetSkin.currentRelPose[o.targetJoint] else if( o.targetObject != null ) o.targetObject.defaultTransform else null;
 			var m = @:privateAccess if( o.targetSkin != null ) o.targetSkin.currentRelPose[o.targetJoint] else if( o.targetObject != null ) o.targetObject.defaultTransform else null;

+ 15 - 0
hxd/Math.hx

@@ -135,6 +135,21 @@ class Math {
 		return a + k * (b - a);
 		return a + k * (b - a);
 	}
 	}
 
 
+	/**
+	 	Similar to linear interpolation (k is between [0,1]), but can be controled with easing parameter. When easing is 0 it's linear.
+	**/
+	public inline static function ease(a:Float, b:Float, k:Float, easing:Float) {
+		return lerp(a, b, easeFactor(k, easing));
+	}
+
+	/**
+		ease = lerp(a,b,easeFactor(k,easing))
+	**/
+	public inline static function easeFactor( k : Float, easing : Float ) {
+		var p = Math.pow(k, 1 + easing);
+		return p / (p + Math.pow(1 - k, easing + 1));
+	}
+
 	/**
 	/**
 		Same as lerp but is scaled based on current FPS, using current elapsed time in seconds.
 		Same as lerp but is scaled based on current FPS, using current elapsed time in seconds.
 	**/
 	**/