Subversion Repositories AndroidProjects

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.Bauzoid.math;

public class MathUtil
{
       
        static public final float EPSILON = 0.0000001f;

       
        public static float clamp(float value, float min, float max)
        {
                if (value < min)
                        return min;
                if (value > max)
                        return max;
                return value;
        }
       
        public static int clamp(int value, int min, int max)
        {
                if (value < min)
                        return min;
                if (value > max)
                        return max;
                return value;
        }
       
        public static float degToRad(float degrees)
        {
                return (float)(degrees * Math.PI / 180.0f);
        }
       
        public static float radToDeg(float rad)
        {
                return (float)(rad * 180.0f / Math.PI);
        }

        public static float clampToRange(float value, float min, float max)
        {
                if (value < min)
                        return min;
                if (value > max)
                        return max;
                return value;
        }

        public static float stayInDegrees0to360(float degrees)
        {
                float result = degrees;
                while (result > 360.0f)
                        result -= 360.0f;
                while (result < 0.0f)
                        result += 360.0f;
                return result;
        }
       
        public static float turnDegrees(float rot1, float rot2)
        {
                if (Math.abs(rot1 - rot2) > (180.0f))
                {
                        if (rot1 < rot2)
                        {
                                rot1 += 360.0f;
                        }
                        else
                        {
                                rot1 -= 360.0f;
                        }
                }
                return Math.abs(rot2-rot1);
        }
       
        public static float ease(float t)
        {
                return (t * t * (3.0f - 2.0f * t));
        }
       
/*      public static float easeOut(float t, float startValue, float changeValue)
        {
               
        }
       
        Math.easeOutQuad = function (t, b, c, d) {
                t /= d;
                return -c * t*(t-2) + b;
        };*/

}