diff --git a/spine-csharp/src/MathUtils.cs b/spine-csharp/src/MathUtils.cs
index 230eb0bd1..eb9756a63 100644
--- a/spine-csharp/src/MathUtils.cs
+++ b/spine-csharp/src/MathUtils.cs
@@ -27,6 +27,8 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
+//#define USE_FAST_SIN_COS_ATAN2_APPROXIMATIONS
+
using System;
namespace Spine {
@@ -47,6 +49,7 @@ namespace Spine {
static Random random = new Random();
+ #if USE_FAST_SIN_COS_ATAN2_APPROXIMATIONS
static MathUtils () {
for (int i = 0; i < SIN_COUNT; i++)
sin[i] = (float)Math.Sin((i + 0.5f) / SIN_COUNT * RadFull);
@@ -54,22 +57,22 @@ namespace Spine {
sin[(int)(i * DegToIndex) & SIN_MASK] = (float)Math.Sin(i * DegRad);
}
- /// Returns the sine in radians from a lookup table.
+ /// Returns the sine of a given angle in radians from a lookup table.
static public float Sin (float radians) {
return sin[(int)(radians * RadToIndex) & SIN_MASK];
}
- /// Returns the cosine in radians from a lookup table.
+ /// Returns the cosine of a given angle in radians from a lookup table.
static public float Cos (float radians) {
return sin[(int)((radians + PI / 2) * RadToIndex) & SIN_MASK];
}
- /// Returns the sine in radians from a lookup table.
+ /// Returns the sine of a given angle in degrees from a lookup table.
static public float SinDeg (float degrees) {
return sin[(int)(degrees * DegToIndex) & SIN_MASK];
}
- /// Returns the cosine in radians from a lookup table.
+ /// Returns the cosine of a given angle in degrees from a lookup table.
static public float CosDeg (float degrees) {
return sin[(int)((degrees + 90) * DegToIndex) & SIN_MASK];
}
@@ -91,7 +94,32 @@ namespace Spine {
atan = PI / 2 - z / (z * z + 0.28f);
return y < 0f ? atan - PI : atan;
}
+ #else
+ /// Returns the sine of a given angle in radians.
+ static public float Sin (float radians) {
+ return (float)Math.Sin(radians);
+ }
+ /// Returns the cosine of a given angle in radians.
+ static public float Cos (float radians) {
+ return (float)Math.Cos(radians);
+ }
+
+ /// Returns the sine of a given angle in degrees.
+ static public float SinDeg (float degrees) {
+ return (float)Math.Sin(degrees * DegRad);
+ }
+
+ /// Returns the cosine of a given angle in degrees.
+ static public float CosDeg (float degrees) {
+ return (float)Math.Cos(degrees * DegRad);
+ }
+
+ /// Returns the atan2 using Math.Atan2.
+ static public float Atan2 (float y, float x) {
+ return (float)Math.Atan2(y, x);
+ }
+ #endif
static public float Clamp (float value, float min, float max) {
if (value < min) return min;
if (value > max) return max;