mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-09-12 12:17:24 +08:00
99 lines
2.4 KiB
C#
99 lines
2.4 KiB
C#
using SharpDX;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CodeWalker.GameFiles;
|
|
|
|
namespace CodeWalker
|
|
{
|
|
public static class Vectors
|
|
{
|
|
public static Vector3 XYZ(this Vector4 v)
|
|
{
|
|
return new Vector3(v.X, v.Y, v.Z);
|
|
}
|
|
|
|
public static Vector3 Round(this Vector3 v)
|
|
{
|
|
return new Vector3((float)Math.Round(v.X), (float)Math.Round(v.Y), (float)Math.Round(v.Z));
|
|
}
|
|
|
|
public static Vector3 GetPerpVec(this Vector3 n)
|
|
{
|
|
//make a vector perpendicular to the given one
|
|
float nx = Math.Abs(n.X);
|
|
float ny = Math.Abs(n.Y);
|
|
float nz = Math.Abs(n.Z);
|
|
if ((nx < ny) && (nx < nz))
|
|
{
|
|
return Vector3.Cross(n, Vector3.Right);
|
|
}
|
|
else if (ny < nz)
|
|
{
|
|
return Vector3.Cross(n, Vector3.Up);
|
|
}
|
|
else
|
|
{
|
|
return Vector3.Cross(n, Vector3.ForwardLH);
|
|
}
|
|
}
|
|
|
|
public static Vector3 Abs(this Vector3 v)
|
|
{
|
|
return new Vector3(Math.Abs(v.X), Math.Abs(v.Y), Math.Abs(v.Z));
|
|
}
|
|
|
|
|
|
public static Vector4 Floor(this Vector4 v)
|
|
{
|
|
return new Vector4((float)Math.Floor(v.X), (float)Math.Floor(v.Y), (float)Math.Floor(v.Z), (float)Math.Floor(v.W));
|
|
}
|
|
|
|
public static Vector4 Abs(this Vector4 v)
|
|
{
|
|
return new Vector4(Math.Abs(v.X), Math.Abs(v.Y), Math.Abs(v.Z), Math.Abs(v.W));
|
|
}
|
|
|
|
public static Quaternion ToQuaternion(this Vector4 v)
|
|
{
|
|
return new Quaternion(v);
|
|
}
|
|
}
|
|
|
|
|
|
public struct Vector2I
|
|
{
|
|
public int X;
|
|
public int Y;
|
|
|
|
public Vector2I(int x, int y)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
}
|
|
public Vector2I(Vector2 v)
|
|
{
|
|
X = (int)Math.Floor(v.X);
|
|
Y = (int)Math.Floor(v.Y);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return X.ToString() + ", " + Y.ToString();
|
|
}
|
|
|
|
|
|
public static Vector2I operator +(Vector2I a, Vector2I b)
|
|
{
|
|
return new Vector2I(a.X + b.X, a.Y + b.Y);
|
|
}
|
|
|
|
public static Vector2I operator -(Vector2I a, Vector2I b)
|
|
{
|
|
return new Vector2I(a.X - b.X, a.Y - b.Y);
|
|
}
|
|
|
|
}
|
|
} |