Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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;
	}
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: set time on audio source unity 
Csharp :: c# button click gets assigned the last value 
Csharp :: how to make a C# game launcher 
Csharp :: c sharp xml prettier 
Csharp :: hide component in component menu 
Csharp :: disable button netbeans 
Csharp :: list of vectors c# 
Csharp :: unity hexmapping 
Csharp :: c# Prefix Sum of Matrix (Or 2D Array) 
Csharp :: nuget Microsoft.EntityFrameworkCore.InMemory": "1.0.0" 
Csharp :: blazor editform empty 
Csharp :: MissingMethodException: PlayerManager.OnPlayerLeft Due to: Attempted to access a missing member. 
Csharp :: turnary operator c# 
Csharp :: ASP.NET C# Catch all exceptions in a class 
Csharp :: Make Enemy follow and rotate towards target in Unity 
Csharp :: how to extract data from a document using c# 
Csharp :: asp.net list size 
Csharp :: c# max in 2d array row 
Csharp :: Custom Encrypted String Type 
Csharp :: params string[] 
Csharp :: use string[] args c# 
Csharp :: unity soundclip mix 
Csharp :: convert iqueryable to list c# 
Csharp :: f sharp make parameter mutable 
Csharp :: c# Jarray tryparse 
Csharp :: set windows theme in c# 
Csharp :: c# parsing datetime from string irrespctive of culture 
Csharp :: how to change the volume of all sound effects in monogame 
Csharp :: vb.net substring after character 
Csharp :: syncfusion worksheet get last row with value 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =