-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.hpp
More file actions
201 lines (153 loc) · 5.59 KB
/
Vector.hpp
File metadata and controls
201 lines (153 loc) · 5.59 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Vector.hpp
// Gabriel Ortega
//
// Defines 2D, 3D, and 4D vectors and behavior
#pragma once
#ifndef VECTOR_H
#define VECTOR_H
#ifdef _WINDLL
#define CGM_DLL __declspec(dllexport)
#else
#define CGM_DLL __declspec(dllimport)
#endif
namespace cliqCity
{
namespace graphicsMath
{
struct CGM_DLL Vector2
{
union
{
struct
{
float x, y;
};
float pCols[2];
};
inline Vector2(float x, float y) : x(x), y(y) {};
inline Vector2(float v) : x(v), y(v) {};
inline Vector2(const Vector2& vector2) : Vector2(vector2.x, vector2.y) {};
inline Vector2() : Vector2(0.0f) {};
Vector2& operator+=(const Vector2& rhs);
Vector2& operator-=(const Vector2& rhs);
Vector2& operator*=(const Vector2& rhs);
Vector2& operator+=(const float& rhs);
Vector2& operator-=(const float& rhs);
Vector2& operator*=(const float& rhs);
Vector2& operator/=(const float& rhs);
// Unary
Vector2& operator++();
Vector2& operator--();
Vector2& operator=(const Vector2& rhs);
Vector2 operator-();
float& operator[](const unsigned int& index);
};
struct CGM_DLL Vector3
{
union
{
struct
{
float x, y, z;
};
float pCols[3];
};
inline Vector3(float x, float y, float z) : x(x), y(y), z(z) {};
inline Vector3(float v) : x(v), y(v), z(v) {};
inline Vector3(const Vector3& vector3) : Vector3(vector3.x, vector3.y, vector3.z) {};
inline Vector3() : Vector3(0.0f) {};
inline Vector3(const Vector2& vector2, float z) : Vector3(vector2.x, vector2.y, z) {};
inline Vector3(const Vector2& vector2) : Vector3(vector2, 0.0f) {};
Vector3& operator+=(const Vector3& rhs);
Vector3& operator-=(const Vector3& rhs);
Vector3& operator*=(const Vector3& rhs);
Vector3& operator+=(const float& rhs);
Vector3& operator-=(const float& rhs);
Vector3& operator*=(const float& rhs);
Vector3& operator/=(const float& rhs);
// Unary
Vector3& operator++();
Vector3& operator--();
Vector3& operator=(const Vector3& rhs);
Vector3 operator-();
float& operator[](const unsigned int& index);
// Typecast
operator Vector2();
};
struct CGM_DLL Vector4
{
union
{
struct
{
float x, y, z, w;
};
float pCols[4];
};
inline Vector4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {};
inline Vector4(float v) : Vector4(v, v, v, v) {};
inline Vector4(const Vector4& vector4) : Vector4(vector4.x, vector4.y, vector4.z, vector4.w) {};
inline Vector4() : Vector4(0.0f) {};
inline Vector4(const Vector3& vector3, float w) : Vector4(vector3.x, vector3.y, vector3.z, w) {};
inline Vector4(const Vector3& vector3) : Vector4(vector3, 0.0f) {};
inline Vector4(const Vector2& vector2, float z, float w) : Vector4(vector2.x, vector2.y, z, w) {};
inline Vector4(const Vector2& vector2) : Vector4(vector2.x, vector2.y, 0.0f, 0.0f) {};
//Vector4(const float128_t& v) : v(v) {};
Vector4& operator+=(const Vector4& rhs);
Vector4& operator-=(const Vector4& rhs);
Vector4& operator*=(const Vector4& rhs);
Vector4& operator+=(const float& rhs);
Vector4& operator-=(const float& rhs);
Vector4& operator*=(const float& rhs);
Vector4& operator/=(const float& rhs);
// Unary
Vector4& operator++();
Vector4& operator--();
Vector4& operator=(const Vector4& rhs);
Vector4 operator-();
float& operator[](const unsigned int& index);
// Typecast
inline operator Vector3()
{
return{ this->x, this->y, this->z };
}
inline operator Vector2()
{
return{ this->x, this->y };
}
};
CGM_DLL Vector2 operator+(const Vector2& lhs, const Vector2& rhs);
CGM_DLL Vector2 operator-(const Vector2& lhs, const Vector2& rhs);
CGM_DLL Vector2 operator*(const Vector2& lhs, const Vector2& rhs);
CGM_DLL Vector2 operator+(const Vector2& lhs, const float& rhs);
CGM_DLL Vector2 operator-(const Vector2& lhs, const float& rhs);
CGM_DLL Vector2 operator*(const Vector2& lhs, const float& rhs);
CGM_DLL Vector2 operator/(const Vector2& lhs, const float& rhs);
CGM_DLL Vector2 operator+(const float& lhs, const Vector2& rhs);
CGM_DLL Vector2 operator-(const float& lhs, const Vector2& rhs);
CGM_DLL Vector2 operator*(const float& lhs, const Vector2& rhs);
// Binary (Vector3)
CGM_DLL Vector3 operator+(const Vector3& lhs, const Vector3& rhs);
CGM_DLL Vector3 operator-(const Vector3& lhs, const Vector3& rhs);
CGM_DLL Vector3 operator*(const Vector3& lhs, const Vector3& rhs);
CGM_DLL Vector3 operator+(const Vector3& lhs, const float& rhs);
CGM_DLL Vector3 operator-(const Vector3& lhs, const float& rhs);
CGM_DLL Vector3 operator*(const Vector3& lhs, const float& rhs);
CGM_DLL Vector3 operator/(const Vector3& lhs, const float& rhs);
CGM_DLL Vector3 operator+(const float& lhs, const Vector3& rhs);
CGM_DLL Vector3 operator-(const float& lhs, const Vector3& rhs);
CGM_DLL Vector3 operator*(const float& lhs, const Vector3& rhs);
// Binary (Vector4)
CGM_DLL Vector4 operator+(const Vector4& lhs, const Vector4& rhs);
CGM_DLL Vector4 operator-(const Vector4& lhs, const Vector4& rhs);
CGM_DLL Vector4 operator*(const Vector4& lhs, const Vector4& rhs);
CGM_DLL Vector4 operator+(const Vector4& lhs, const float& rhs);
CGM_DLL Vector4 operator-(const Vector4& lhs, const float& rhs);
CGM_DLL Vector4 operator*(const Vector4& lhs, const float& rhs);
CGM_DLL Vector4 operator/(const Vector4& lhs, const float& rhs);
CGM_DLL Vector4 operator+(const float& lhs, const Vector4& rhs);
CGM_DLL Vector4 operator-(const float& lhs, const Vector4& rhs);
CGM_DLL Vector4 operator*(const float& lhs, const Vector4& rhs);
}
}
#endif