-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector3.h
77 lines (70 loc) · 5.02 KB
/
vector3.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
namespace rapid
{
class vector3 : public vector
{
public:
vector3() {}
vector3(FXMVECTOR v) noexcept: vector(v) {}
vector3(const vector& v) noexcept: vector(v) {}
vector3(const float2& v) noexcept: vector(XMLoadFloat2(&v)) {}
vector3(const float2a& v) noexcept: vector(XMLoadFloat2A(&v)) {}
vector3(const float3& v) noexcept: vector(XMLoadFloat3(&v)) {}
vector3(const float3a& v) noexcept: vector(XMLoadFloat3A(&v)) {}
explicit vector3(const vector2& v, const float z) noexcept: vector(v.x(), v.y(), z) {}
explicit vector3(const float x) noexcept: vector(x) {}
explicit vector3(const float x, const float y, const float z) noexcept: vector(x, y, z) {}
vector3 operator+(const vector3& v) const noexcept { return XMVectorAdd(V, v.V); }
vector3 operator-(const vector3& v) const noexcept { return XMVectorSubtract(V, v.V); }
vector3 operator*(const vector3& v) const noexcept { return XMVectorMultiply(V, v.V); }
vector3 operator*(const float s) const noexcept { return XMVectorScale(V, s); }
vector3 operator/(const vector3& v) const noexcept { return XMVectorDivide(V, v.V); }
vector3 operator/(const float s) const noexcept { return XMVectorScale(V, 1.f/s); }
vector operator|(const vector3& v) const noexcept { return XMVector3Dot(V, v.V); }
vector3 operator^(const vector3& v) const noexcept { return XMVector3Cross(V, v.V); }
vector operator!() const noexcept { return XMVector3Length(V); }
const vector3& operator+() const noexcept { return *this; }
vector3 operator-() const noexcept { return XMVectorNegate(V); }
const vector3& operator+=(const vector3& v) noexcept { V = XMVectorAdd(V, v.V); return *this; }
const vector3& operator-=(const vector3& v) noexcept { V = XMVectorSubtract(V, v.V); return *this; }
const vector3& operator*=(const vector3& v) noexcept { V = XMVectorMultiply(V, v.V); return *this; }
const vector3& operator*=(const float s) noexcept { V = XMVectorScale(V, s); return *this; }
const vector3& operator/=(const vector3& v) noexcept { V = XMVectorDivide(V, v.V); return *this; }
const vector3& operator/=(const float s) noexcept { V = XMVectorScale(V, 1.f/s); return *this; }
bool operator==(const vector3& v) const noexcept { return XMVector3Equal(V, v.V); }
bool nearEqual(const vector3& v, const vector3& eps) const noexcept { return XMVector3NearEqual(V, v.V, eps); }
bool operator!=(const vector3& v) const noexcept { return XMVector3NotEqual(V, v.V); }
bool operator>(const vector3& v) const noexcept { return XMVector3Greater(V, v.V); }
bool operator>=(const vector3& v) const noexcept { return XMVector3GreaterOrEqual(V, v.V); }
bool operator<(const vector3& v) const noexcept { return XMVector3Less(V, v.V); }
bool operator<=(const vector3& v) const noexcept { return XMVector3LessOrEqual(V, v.V); }
float y() const noexcept { return XMVectorGetY(V); }
float z() const noexcept { return XMVectorGetZ(V); }
#include "swizzling/vector2.inl"
#include "swizzling/vector3.inl"
bool nan() const noexcept { return XMVector3IsNaN(V); }
bool infinite() const noexcept { return XMVector3IsInfinite(V); }
bool unit() const noexcept {
XMVECTOR v = XMVectorSubtract(g_XMOne3, XMVector3Dot(V, V));
return XMVector3LessOrEqual(XMVectorAbs(v), g_XMEpsilon);
}
vector sum() const noexcept { return XMVector3Dot(V, g_XMOne3); }
vector sumAbs() const noexcept { return XMVector3Dot(XMVectorAbs(V), g_XMOne3); }
vector dot(const vector3& v) const noexcept { return XMVector3Dot(V, v.V); }
vector3 cross(const vector3& v) const noexcept { return XMVector3Cross(V, v.V); }
vector lengthSq() const noexcept { return XMVector3LengthSq(V); }
vector rcpLengthEst() const noexcept { return XMVector3ReciprocalLengthEst(V); }
vector rcpLength() const noexcept { return XMVector3ReciprocalLength(V); }
vector lengthEst() const noexcept { return XMVector3LengthEst(V); }
vector length() const noexcept { return XMVector3Length(V); }
void normalizeEst() noexcept { V = XMVector3NormalizeEst(V); }
vector3 normalizedEst() const noexcept { return XMVector3NormalizeEst(V); }
void normalize() noexcept { V = XMVector3Normalize(V); }
vector3 normalized() const noexcept { return XMVector3Normalize(V); }
void clampLength(const float min, const float max) noexcept { V = XMVector3ClampLength(V, min, max); }
void clampLength(const vector3& min, const vector3& max) noexcept { V = XMVector3ClampLengthV(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); };
};
} // namespace rapid