-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector4.h
85 lines (78 loc) · 5.69 KB
/
vector4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
namespace rapid
{
class vector4 : public vector
{
public:
vector4() noexcept {}
vector4(FXMVECTOR v) noexcept: vector(v) {}
vector4(const vector& v) noexcept: vector(v) {}
vector4(const float2& v) noexcept: vector(XMLoadFloat2(&v)) {}
vector4(const float2a& v) noexcept: vector(XMLoadFloat2A(&v)) {}
vector4(const float3& v) noexcept: vector(XMLoadFloat3(&v)) {}
vector4(const float3a& v) noexcept: vector(XMLoadFloat3A(&v)) {}
vector4(const float4& v) noexcept: vector(XMLoadFloat4(&v)) {}
vector4(const float4a& v) noexcept: vector(XMLoadFloat4A(&v)) {}
explicit vector4(const vector2& v, const float z, const float w) noexcept: vector(v.x(), v.y(), z, w) {}
explicit vector4(const vector3& v, const float w) noexcept: vector(v) { V = XMVectorSetW(V, w); }
explicit vector4(const float3& v, float w) noexcept: vector(XMLoadFloat3(&v)) { V = XMVectorSetW(V, w); }
explicit vector4(const float3a& v, float w) noexcept: vector(XMLoadFloat3A(&v)) { V = XMVectorSetW(V, w); }
explicit vector4(const float x) noexcept: vector(x) {}
explicit vector4(const float x, const float y, const float z, const float w) noexcept: vector(x, y, z, w) {}
vector4 operator+(const vector4& v) const noexcept { return XMVectorAdd(V, v.V); }
vector4 operator-(const vector4& v) const noexcept { return XMVectorSubtract(V, v.V); }
vector4 operator*(const vector4& v) const noexcept { return XMVectorMultiply(V, v.V); }
vector4 operator*(const float s) const noexcept { return XMVectorScale(V, s); }
vector4 operator/(const vector4& v) const noexcept { return XMVectorDivide(V, v.V); }
vector4 operator/(const float s) const noexcept { return XMVectorScale(V, 1.f/s); }
vector operator|(const vector4& v) const noexcept { return XMVector4Dot(V, v.V); }
vector operator!() const noexcept { return XMVector4Length(V); }
const vector4& operator+() const noexcept { return *this; }
vector4 operator-() const noexcept { return XMVectorNegate(V); }
const vector4& operator+=(const vector4& v) noexcept { V = XMVectorAdd(V, v.V); return *this; }
const vector4& operator-=(const vector4& v) noexcept { V = XMVectorSubtract(V, v.V); return *this; }
const vector4& operator*=(const vector4& v) noexcept { V = XMVectorMultiply(V, v.V); return *this; }
const vector4& operator*=(const float s) noexcept { V = XMVectorScale(V, s); return *this; }
const vector4& operator/=(const vector4& v) noexcept { V = XMVectorDivide(V, v.V); return *this; }
const vector4& operator/=(const float s) noexcept { V = XMVectorScale(V, 1.f/s); return *this; }
bool operator==(const vector4& v) const noexcept { return XMVector4Equal(V, v.V); }
bool nearEqual(const vector4& v, const vector4& eps) const noexcept { return XMVector4NearEqual(V, v.V, eps); }
bool operator!=(const vector4& v) const noexcept { return XMVector4NotEqual(V, v.V); }
bool operator>(const vector4& v) const noexcept { return XMVector4Greater(V, v.V); }
bool operator>=(const vector4& v) const noexcept { return XMVector4GreaterOrEqual(V, v.V); }
bool operator<(const vector4& v) const noexcept { return XMVector4Less(V, v.V); }
bool operator<=(const vector4& v) const noexcept { return XMVector4LessOrEqual(V, v.V); }
float y() const noexcept { return XMVectorGetY(V); }
float z() const noexcept { return XMVectorGetZ(V); }
float w() const noexcept { return XMVectorGetW(V); }
#include "swizzling/vector2.inl"
#include "swizzling/vector3.inl"
#include "swizzling/vector4.inl"
bool nan() const noexcept { return XMVector4IsNaN(V); }
bool infinite() const noexcept { return XMVector4IsInfinite(V); }
bool unit() const noexcept {
XMVECTOR v = XMVectorSubtract(g_XMOne, XMVector4Dot(V, V));
return XMVector4LessOrEqual(XMVectorAbs(v), g_XMEpsilon);
}
vector sum() const noexcept { return XMVectorSum(V); }
vector sumAbs() const noexcept { return XMVectorSum(XMVectorAbs(V)); }
vector dot(const vector4& v) const noexcept { return XMVector4Dot(V, v.V); }
vector4 cross(const vector4& v2, const vector4& v3) const noexcept { return XMVector4Cross(V, v2.V, v3.V); }
vector lengthSq() const noexcept { return XMVector4LengthSq(V); }
vector rcpLengthEst() const noexcept { return XMVector4ReciprocalLengthEst(V); }
vector rcpLength() const noexcept { return XMVector4ReciprocalLength(V); }
vector lengthEst() const noexcept { return XMVector4LengthEst(V); }
vector length() const noexcept { return XMVector4Length(V); }
void normalizeEst() noexcept { V = XMVector4NormalizeEst(V); }
vector4 normalizedEst() const noexcept { return XMVector4NormalizeEst(V); }
void normalize() noexcept { V = XMVector4Normalize(V); }
vector4 normalized() const noexcept { return XMVector4Normalize(V); }
void clampLength(const float min, const float max) noexcept { V = XMVector4ClampLength(V, min, max); }
void clampLength(const vector4& min, const vector4& max) noexcept { V = XMVector4ClampLengthV(V, min.V, max.V); }
void store(float2 *v) const noexcept { XMStoreFloat2(v, V); };
void store(float2a *v) const noexcept { XMStoreFloat2A(v, V); };
void store(float3 *v) const noexcept { XMStoreFloat3(v, V); };
void store(float3a *v) const noexcept { XMStoreFloat3A(v, V); };
void store(float4 *v) const noexcept { XMStoreFloat4(v, V); };
void store(float4a *v) const noexcept { XMStoreFloat4A(v, V); };
};
} // namespace rapid