Blame |
Last modification |
View Log
| RSS feed
package com.gebauz.pingK.util;
public class MathUtil
{
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 stayInRadians0to2Pi(float radians) {
float result = radians;
while (result > (float)(2*Math.PI))
result -= (float)(2*Math.PI);
while (result < 0.0f)
result += (float)(2*Math.PI);
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 turnRadians(float rot1, float rot2) {
if (Math.abs(rot1 - rot2) > (Math.PI)) {
if (rot1 < rot2) {
rot1 += (float)2*Math.PI;
} else {
rot1 -= (float)2*Math.PI;
}
}
return Math.abs(rot2-rot1);
}
*/
/* function SUXMath.turnDegrees(rot1,rot2:SXFloat;var direction:SXState):SXFloat;
begin
if abs(rot1-rot2)>180 then
begin // Reset the rotation if necessary
if rot1<rot2 then rot1:=rot1+360 else rot1:=rot1-360;
end;
result:=abs(rot2-rot1);
if rot2>rot1 then direction:=SX_MOVEMENT_RIGHT else direction:=SX_MOVEMENT_LEFT;
end;*/
}