191 lines
2.7 KiB
C++
191 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <d3d11.h>
|
|
|
|
#include "vec2.h"
|
|
|
|
namespace egm
|
|
{
|
|
|
|
template <typename T>
|
|
struct tvec4
|
|
{
|
|
T x;
|
|
T y;
|
|
T z;
|
|
T w;
|
|
|
|
tvec4() : x(0), y(0), z(0), w(0) {}
|
|
tvec4(const tvec4<T>& v) : x(v.x), y(v.y), z(v.z), w(v.w) {}
|
|
template <typename U>
|
|
tvec4(const tvec4<U>& v) : x((T)v.x), y((T)v.y), z((T)v.z), w((T)v.w) {}
|
|
tvec4(const tvec2<T>& a, const tvec2<T>& b) : x(a.x), y(a.y), z(b.x), w(b.y) {}
|
|
tvec4(const T& scalar) : x(scalar), y(scalar), z(scalar), w(scalar) {}
|
|
tvec4(const T& scalar1, const T& scalar2, const T& scalar3, const T& scalar4) : x(scalar1), y(scalar2), z(scalar3), w(scalar4) {}
|
|
|
|
T& operator[](const unsigned int& index)
|
|
{
|
|
switch (index)
|
|
{
|
|
case 0:
|
|
return x;
|
|
case 1:
|
|
return y;
|
|
case 2:
|
|
return z;
|
|
case 3:
|
|
return w;
|
|
default:
|
|
throw "Index Out Of Bounds";
|
|
}
|
|
}
|
|
|
|
bool operator==(const tvec4<T>& o)
|
|
{
|
|
return (o.x == x && o.y == y && o.z == z && o.w == w);
|
|
}
|
|
|
|
tvec4<T>& operator=(const tvec4<T>& o)
|
|
{
|
|
x = o.x;
|
|
y = o.y;
|
|
z = o.z;
|
|
w = o.w;
|
|
return *this;
|
|
}
|
|
|
|
tvec4<T> operator+(const tvec4<T>& o) const
|
|
{
|
|
return {
|
|
x + o.x,
|
|
y + o.y,
|
|
z + o.z,
|
|
w + o.w
|
|
}
|
|
}
|
|
|
|
tvec4<T>& operator+=(const tvec4<T>& o)
|
|
{
|
|
x += o.x;
|
|
y += o.y;
|
|
z += o.z;
|
|
w += o.w;
|
|
return *this;
|
|
}
|
|
|
|
tvec4<T> operator-(const tvec4<T>& o) const
|
|
{
|
|
return {
|
|
x - o.x,
|
|
y - o.y,
|
|
z - o.z,
|
|
w - o.w
|
|
}
|
|
}
|
|
|
|
tvec4<T>& operator-=(const tvec4<T>& o)
|
|
{
|
|
x -= o.x;
|
|
y -= o.y;
|
|
z -= o.z;
|
|
w -= o.w;
|
|
return *this;
|
|
}
|
|
|
|
tvec4<T> operator*(const tvec4<T>& o) const
|
|
{
|
|
return {
|
|
x * o.x,
|
|
y * o.y,
|
|
z * o.z,
|
|
w * o.w
|
|
}
|
|
}
|
|
|
|
tvec4<T>& operator*=(const tvec4<T>& o)
|
|
{
|
|
x *= o.x;
|
|
y *= o.y;
|
|
z *= o.z;
|
|
w *= o.w;
|
|
return *this;
|
|
}
|
|
|
|
tvec4<T> operator*(const T& scalar) const
|
|
{
|
|
return {
|
|
x * scalar,
|
|
y * scalar,
|
|
z * scalar,
|
|
w * scalar
|
|
}
|
|
}
|
|
|
|
tvec4<T>& operator*=(const T& scalar)
|
|
{
|
|
x *= scalar;
|
|
y *= scalar;
|
|
z *= scalar;
|
|
w *= scalar;
|
|
return *this;
|
|
}
|
|
|
|
tvec4<T> operator/(const tvec4<T>& o) const
|
|
{
|
|
return {
|
|
x / o.x,
|
|
y / o.y,
|
|
z / o.z,
|
|
w / o.w
|
|
}
|
|
}
|
|
|
|
tvec4<T>& operator/=(const tvec4<T>& o)
|
|
{
|
|
x /= o.x;
|
|
y /= o.y;
|
|
z /= o.z;
|
|
w /= o.w;
|
|
return *this;
|
|
}
|
|
|
|
tvec4<T> operator/(const T& scalar) const
|
|
{
|
|
return {
|
|
x / scalar,
|
|
y / scalar,
|
|
z / scalar,
|
|
w / scalar
|
|
};
|
|
}
|
|
|
|
tvec4<T>& operator/=(const T& scalar)
|
|
{
|
|
x /= scalar;
|
|
y /= scalar;
|
|
z /= scalar;
|
|
w /= scalar;
|
|
return *this;
|
|
}
|
|
|
|
operator RECT()
|
|
{
|
|
return {
|
|
x,
|
|
y,
|
|
z,
|
|
w
|
|
}
|
|
}
|
|
|
|
float* data()
|
|
{
|
|
return &x;
|
|
}
|
|
};
|
|
|
|
typedef tvec4<float> vec4;
|
|
typedef tvec4<double> dvec4;
|
|
typedef tvec4<int> ivec4;
|
|
}
|