added to math helper

This commit is contained in:
DarkGuardsman 2013-09-27 18:56:56 -04:00
parent 53ca79a784
commit bbd334284c

View file

@ -67,4 +67,45 @@ public class MathHelper extends net.minecraft.util.MathHelper
return new Vector3(x, y, z);
}
/** Clamps the angles to a min max by adding or subtracting the min max. This way it maintanes
* the change in angle in the chance it goes out of bounds */
public static float clampAngle(float var, float min, float max)
{
while (var < min)
{
var += min;
}
while (var > max)
{
var -= max;
}
return var;
}
/** Clamps an angle to 360 degree circle */
public static float clampAngleTo360(float var)
{
return MathHelper.clampAngle(var, 0, 360);
}
/** Find the shortest delta change to the angle goal from the current angle */
public static float shortestAngleTo360(float angle, float angleGoal)
{
angle = clampAngleTo360(angle);
angleGoal = clampAngleTo360(angleGoal);
if (angle == angleGoal)
{
return 0;
}
else if (angle > angleGoal)
{
return angleGoal - angle;
}
else
{
return angle - angleGoal;
}
}
}