UltimateZoneBuilder/Source/Core/Rendering/Vector4.cs

215 lines
5.2 KiB
C#
Raw Normal View History

2019-08-08 16:24:33 +00:00
using System;
using System.Collections.Generic;
2023-06-29 18:37:47 +00:00
using System.Drawing.Printing;
2019-08-08 16:24:33 +00:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-06-29 18:37:47 +00:00
using System.Windows;
2019-08-08 16:24:33 +00:00
namespace CodeImp.DoomBuilder.Rendering
{
public struct Vector4f
2019-08-08 16:24:33 +00:00
{
public Vector4f(float v)
2019-08-08 16:24:33 +00:00
{
X = v;
Y = v;
Z = v;
W = v;
}
public Vector4f(Vector2f xy, float z, float w)
2019-08-08 16:24:33 +00:00
{
X = xy.X;
Y = xy.Y;
Z = z;
W = w;
}
public Vector4f(Vector3f xyz, float w)
2019-08-08 16:24:33 +00:00
{
X = xyz.X;
Y = xyz.Y;
Z = xyz.Z;
W = w;
}
public Vector4f(float x, float y, float z, float w)
2019-08-08 16:24:33 +00:00
{
X = x;
Y = y;
Z = z;
W = w;
}
public float X;
public float Y;
public float Z;
public float W;
2023-06-29 18:37:47 +00:00
public static float Dot(Vector4f a, Vector4f b)
{
return a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W;
}
public float Length()
{
return (float)Math.Sqrt(Dot(this, this));
}
public static Vector4f Normalize(Vector4f v)
{
v.Normalize();
return v;
}
public void Normalize()
{
float len = Length();
if (len > 0.0f)
{
X /= len;
Y /= len;
Z /= len;
W /= len;
}
}
2019-08-08 16:24:33 +00:00
public override bool Equals(object o)
{
if (o is Vector4f)
2019-08-08 16:24:33 +00:00
{
Vector4f v = (Vector4f)o;
2019-08-08 16:24:33 +00:00
return this == v;
}
else
{
return false;
}
}
2023-06-29 18:37:47 +00:00
public static Vector4f operator *(Vector4f vec, float scalar)
{
return new Vector4f(vec.X * scalar, vec.Y * scalar, vec.Z * scalar, vec.W * scalar);
}
public static Vector4f operator *(float scalar, Vector4f vec)
{
return new Vector4f(vec.X * scalar, vec.Y * scalar, vec.Z * scalar, vec.W * scalar);
}
public static Vector4f operator +(Vector4f left, Vector4f right)
2019-08-08 16:24:33 +00:00
{
return new Vector4f(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
2019-08-08 16:24:33 +00:00
}
public static Vector4f operator -(Vector4f left, Vector4f right)
2019-08-08 16:24:33 +00:00
{
return new Vector4f(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
2019-08-08 16:24:33 +00:00
}
public static Vector4f operator -(Vector4f v)
2019-08-08 16:24:33 +00:00
{
return new Vector4f(-v.X, -v.Y, -v.Z, -v.W);
2019-08-08 16:24:33 +00:00
}
public override int GetHashCode()
{
return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode() + W.GetHashCode();
}
public static bool operator ==(Vector4f left, Vector4f right)
2019-08-08 16:24:33 +00:00
{
return left.X == right.X && left.Y == right.Y && left.Z == right.Z && left.W == right.W;
}
public static bool operator !=(Vector4f left, Vector4f right)
{
return left.X != right.X || left.Y != right.Y || left.Z != right.Z || left.W != right.W;
}
}
public struct Vector4i
{
public Vector4i(int v)
{
X = v;
Y = v;
Z = v;
W = v;
}
public Vector4i(Vector2i xy, int z, int w)
{
X = xy.X;
Y = xy.Y;
Z = z;
W = w;
}
public Vector4i(Vector3i xyz, int w)
{
X = xyz.X;
Y = xyz.Y;
Z = xyz.Z;
W = w;
}
public Vector4i(int x, int y, int z, int w)
{
X = x;
Y = y;
Z = z;
W = w;
}
public int X;
public int Y;
public int Z;
public int W;
public override bool Equals(object o)
{
if (o is Vector4i)
{
Vector4i v = (Vector4i)o;
return this == v;
}
else
{
return false;
}
}
public static Vector4i operator +(Vector4i left, Vector4i right)
{
return new Vector4i(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
}
public static Vector4i operator -(Vector4i left, Vector4i right)
{
return new Vector4i(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
}
public static Vector4i operator -(Vector4i v)
{
return new Vector4i(-v.X, -v.Y, -v.Z, -v.W);
}
public override int GetHashCode()
{
return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode() + W.GetHashCode();
}
public static bool operator ==(Vector4i left, Vector4i right)
{
return left.X == right.X && left.Y == right.Y && left.Z == right.Z && left.W == right.W;
}
public static bool operator !=(Vector4i left, Vector4i right)
2019-08-08 16:24:33 +00:00
{
return left.X != right.X || left.Y != right.Y || left.Z != right.Z || left.W != right.W;
}
}
}