mirror of
https://github.com/XorTroll/EveryFileExplorer.git
synced 2024-12-03 08:00:47 +00:00
Added MathUtil
This commit is contained in:
parent
f6023861a2
commit
0b4ef1820d
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using LibEveryFileExplorer.Math;
|
||||
|
||||
namespace _3DS.DSP
|
||||
{
|
||||
@ -39,12 +40,12 @@ namespace _3DS.DSP
|
||||
if (high >= 8) high -= 16;
|
||||
if (low >= 8) low -= 16;
|
||||
double val = (((high * Scale) << 11) + 1024.0 + (Coef1 * Last1 + Coef2 * Last2)) / 2048.0; //>> 11;
|
||||
short samp = Clamp((int)val, short.MinValue, short.MaxValue);
|
||||
short samp = (short)MathUtil.Clamp((int)val, short.MinValue, short.MaxValue);
|
||||
DataOut.Add(samp);
|
||||
Last2 = Last1;
|
||||
Last1 = val;
|
||||
val = (((low * Scale) << 11) + 1024.0 + (Coef1 * Last1 + Coef2 * Last2)) / 2048.0;//>> 11;
|
||||
samp = Clamp((int)val, short.MinValue, short.MaxValue);
|
||||
samp = (short)MathUtil.Clamp((int)val, short.MinValue, short.MaxValue);
|
||||
DataOut.Add(samp);
|
||||
Last2 = Last1;
|
||||
Last1 = val;
|
||||
@ -52,12 +53,5 @@ namespace _3DS.DSP
|
||||
}
|
||||
return DataOut.ToArray();
|
||||
}
|
||||
|
||||
private static short Clamp(int value, int min, int max)
|
||||
{
|
||||
if (value < min) value = min;
|
||||
if (value > max) value = max;
|
||||
return (short)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace LibEveryFileExplorer._3D
|
||||
get
|
||||
{
|
||||
Vector3 a = (PointB - PointA).Cross(PointC - PointA);
|
||||
return a / (float)Math.Sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z);
|
||||
return a / (float)System.Math.Sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ namespace LibEveryFileExplorer.Collections
|
||||
|
||||
public float Length
|
||||
{
|
||||
get { return (float)Math.Sqrt(X * X + Y * Y); }
|
||||
get { return (float)System.Math.Sqrt(X * X + Y * Y); }
|
||||
}
|
||||
|
||||
public void Normalize()
|
||||
|
@ -52,7 +52,7 @@ namespace LibEveryFileExplorer.Collections
|
||||
|
||||
public float Length
|
||||
{
|
||||
get { return (float)Math.Sqrt(X * X + Y * Y + Z * Z); }
|
||||
get { return (float)System.Math.Sqrt(X * X + Y * Y + Z * Z); }
|
||||
}
|
||||
|
||||
public void Normalize()
|
||||
|
@ -62,7 +62,7 @@ namespace LibEveryFileExplorer.Collections
|
||||
|
||||
public float Length
|
||||
{
|
||||
get { return (float)Math.Sqrt(X * X + Y * Y + Z * Z + W * W); }
|
||||
get { return (float)System.Math.Sqrt(X * X + Y * Y + Z * Z + W * W); }
|
||||
}
|
||||
|
||||
public void Normalize()
|
||||
|
@ -76,6 +76,7 @@
|
||||
<Compile Include="IO\EndianBinaryReader.cs" />
|
||||
<Compile Include="IO\EndianBinaryWriter.cs" />
|
||||
<Compile Include="IO\IOUtil.cs" />
|
||||
<Compile Include="Math\MathUtil.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Resource.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
27
LibEveryFileExplorer/Math/MathUtil.cs
Normal file
27
LibEveryFileExplorer/Math/MathUtil.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace LibEveryFileExplorer.Math
|
||||
{
|
||||
public class MathUtil
|
||||
{
|
||||
public static int Clamp(int value, int min, int max)
|
||||
{
|
||||
if (value < min) value = min;
|
||||
if (value > max) value = max;
|
||||
return (short)value;
|
||||
}
|
||||
|
||||
public static float RadToDeg(float Radians)
|
||||
{
|
||||
return Radians * (180f / (float)System.Math.PI);
|
||||
}
|
||||
|
||||
public static double RadToDeg(double Radians)
|
||||
{
|
||||
return Radians * (180.0 / System.Math.PI);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ using LibEveryFileExplorer.Collections;
|
||||
using Tao.OpenGl;
|
||||
using MarioKart.UI;
|
||||
using LibEveryFileExplorer.GFX;
|
||||
using LibEveryFileExplorer.Math;
|
||||
|
||||
namespace MarioKart.MKDS
|
||||
{
|
||||
@ -433,7 +434,7 @@ namespace MarioKart.MKDS
|
||||
if (Version <= 34)
|
||||
{
|
||||
float yangle = (float)Math.Atan2(Rotation.X, Rotation.Z);
|
||||
Rotation = new Vector3(0, /*MathHelper.RadiansToDegrees(yangle)*/ yangle * (180f / (float)Math.PI), 0);
|
||||
Rotation = new Vector3(0, MathUtil.RadToDeg(yangle), 0);
|
||||
}
|
||||
EnemyPositionID = er.ReadInt16();
|
||||
ItemPositionID = er.ReadInt16();
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using LibEveryFileExplorer.IO;
|
||||
using LibEveryFileExplorer.Math;
|
||||
|
||||
namespace NDS.SND
|
||||
{
|
||||
@ -57,19 +58,12 @@ namespace NDS.SND
|
||||
StepTable[Index] * ((val >> 2) & 1);
|
||||
|
||||
int samp = Last + diff * ((((val >> 3) & 1) == 1) ? -1 : 1);
|
||||
Last = Clamp(samp, short.MinValue, short.MaxValue);
|
||||
Index = Clamp(Index + IndexTable[val & 7], 0, 88);
|
||||
Last = (short)MathUtil.Clamp(samp, short.MinValue, short.MaxValue);
|
||||
Index = (short)MathUtil.Clamp(Index + IndexTable[val & 7], 0, 88);
|
||||
DataOut.Add((short)Last);
|
||||
}
|
||||
}
|
||||
return DataOut.ToArray();
|
||||
}
|
||||
|
||||
private static short Clamp(int value, int min, int max)
|
||||
{
|
||||
if (value < min) value = min;
|
||||
if (value > max) value = max;
|
||||
return (short)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user