Browse Source

add THREE.Math.smoothStep and THREE.Math.smootherStep based on Wikipedia article.

Ben Houston 12 years ago
parent
commit
d0a6c5ab5b
1 changed files with 36 additions and 0 deletions
  1. 36 0
      src/math/Math.js

+ 36 - 0
src/math/Math.js

@@ -28,6 +28,42 @@ THREE.Math = {
 
 	},
 
+	// http://en.wikipedia.org/wiki/Smoothstep
+
+	smoothStep: function ( x, min, max ) {
+
+		if( x <= min ) {
+			return 0;
+		}
+		if( x >= max ) {
+			return 1;
+		}
+
+		// normalize
+		x = ( x - min )/( max - min );
+
+		return x*x*(3 - 2*x);
+
+	},
+
+	// http://en.wikipedia.org/wiki/Smoothstep
+
+	smootherStep: function ( x, min, max ) {
+
+		if( x <= min ) {
+			return 0;
+		}
+		if( x >= max ) {
+			return 1;
+		}
+
+		// normalize
+		x = ( x - min )/( max - min );
+
+		return x*x*x*(x*(x*6 - 15) + 10);
+
+	},
+	
 	// Random float from <0, 1> with 16 bits of randomness
 	// (standard Math.random() creates repetitive patterns when applied over larger space)