Horje
unity fast sin Code Example
unity fast sin
// Low percision sine approximation
public class SineLP
{
	private static float sin = 0;

	public static float Sin( float x )
	{
		if (x < -3.14159265f)
			x += 6.28318531f;
		else
			if (x >  3.14159265f)
				x -= 6.28318531f;

		if ( x < 0 )
			return x * ( 1.27323954f + 0.405284735f * x );
		else
			return x * ( 1.27323954f - 0.405284735f * x );
	}
}

// High percision sine approximation
public class SineHP
{
	private static float sin = 0;

	public static float Sin( float x )
	{
		if (x < -3.14159265f)
			x += 6.28318531f;
		else
			if (x >  3.14159265f)
				x -= 6.28318531f;	

		if ( x < 0 )
		{
			sin = x * ( 1.27323954f + 0.405284735f * x );

			if ( sin < 0 )
				sin = sin * ( -0.255f * ( sin + 1 ) + 1 );
			else
				sin = sin * ( 0.255f * ( sin - 1 ) + 1 );
		}
		else
		{
			sin = x * ( 1.27323954f - 0.405284735f * x );

			if ( sin < 0 )
				sin = sin * ( -0.255f * ( sin + 1 ) + 1 );
			else
				sin = sin * ( 0.255f * ( sin - 1 ) + 1 );
		}

		return sin;
	}
}




Csharp

Related
Compiling C# Example Code Example Compiling C# Example Code Example
C# Convert range Code Example C# Convert range Code Example
range to 01 Code Example range to 01 Code Example
how to move player with transform. position Code Example how to move player with transform. position Code Example
c# String Uppercase and Lowercase method Code Example c# String Uppercase and Lowercase method Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8