threex
Version:
Game Extensions for three.js http://www.threejsgames.com/extensions/
23 lines (19 loc) • 696 B
JavaScript
/** @namespace */
var THREEx = THREEx || {};
THREEx.AbsoluteNormalizer = function(){
var maxThreshold = -Infinity;
var minThreshold = +Infinity;
this.update = function(value){
// TODO make be good to smooth those values over time, thus it would forget
// it would be the adaptative
// and this one being absolute
if( value < minThreshold ) minThreshold = value
if( value > maxThreshold ) maxThreshold = value
// to avoid division by zero
if( maxThreshold === minThreshold ) return value;
// compute normalized value
var normalized = (value - minThreshold) / (maxThreshold-minThreshold);
// return the just built normalized value between [0, 1]
return normalized;
}
}