mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[csharp] Fixed precision problems when inherit rotation is disabled and parent rotated by disabling sin/cos/atan2 look up table based implementation. Define can manually be enabled in code in case anyone really receives any measuarable performance impact (which I did not). Closes #1606.
This commit is contained in:
parent
c568169821
commit
e62c42c041
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>Returns the sine in radians from a lookup table.</summary>
|
||||
/// <summary>Returns the sine of a given angle in radians from a lookup table.</summary>
|
||||
static public float Sin (float radians) {
|
||||
return sin[(int)(radians * RadToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
/// <summary>Returns the cosine in radians from a lookup table.</summary>
|
||||
/// <summary>Returns the cosine of a given angle in radians from a lookup table.</summary>
|
||||
static public float Cos (float radians) {
|
||||
return sin[(int)((radians + PI / 2) * RadToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
/// <summary>Returns the sine in radians from a lookup table.</summary>
|
||||
/// <summary>Returns the sine of a given angle in degrees from a lookup table.</summary>
|
||||
static public float SinDeg (float degrees) {
|
||||
return sin[(int)(degrees * DegToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
/// <summary>Returns the cosine in radians from a lookup table.</summary>
|
||||
/// <summary>Returns the cosine of a given angle in degrees from a lookup table.</summary>
|
||||
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
|
||||
/// <summary>Returns the sine of a given angle in radians.</summary>
|
||||
static public float Sin (float radians) {
|
||||
return (float)Math.Sin(radians);
|
||||
}
|
||||
|
||||
/// <summary>Returns the cosine of a given angle in radians.</summary>
|
||||
static public float Cos (float radians) {
|
||||
return (float)Math.Cos(radians);
|
||||
}
|
||||
|
||||
/// <summary>Returns the sine of a given angle in degrees.</summary>
|
||||
static public float SinDeg (float degrees) {
|
||||
return (float)Math.Sin(degrees * DegRad);
|
||||
}
|
||||
|
||||
/// <summary>Returns the cosine of a given angle in degrees.</summary>
|
||||
static public float CosDeg (float degrees) {
|
||||
return (float)Math.Cos(degrees * DegRad);
|
||||
}
|
||||
|
||||
/// <summary>Returns the atan2 using Math.Atan2.</summary>
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user