TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vectorMath.h
Go to the documentation of this file.
1 
14 #ifndef G3D_VECTORMATH_H
15 #define G3D_VECTORMATH_H
16 
17 #include "G3D/platform.h"
18 #include "G3D/g3dmath.h"
19 #include "G3D/Vector2.h"
20 #include "G3D/Vector3.h"
21 #include "G3D/Vector4.h"
22 #include "G3D/Matrix3.h"
23 #include "G3D/Matrix4.h"
24 #include "G3D/Color1.h"
25 #include "G3D/Color3.h"
26 #include "G3D/Color4.h"
27 
28 
29 namespace G3D {
30 
31 
32 inline Matrix4 mul(const Matrix4& a, const Matrix4& b) {
33  return a * b;
34 }
35 
36 inline Vector4 mul(const Matrix4& m, const Vector4& v) {
37  return m * v;
38 }
39 
40 inline Vector3 mul(const Matrix3& m, const Vector3& v) {
41  return m * v;
42 }
43 
44 inline Matrix3 mul(const Matrix3& a, const Matrix3& b) {
45  return a * b;
46 }
47 
48 inline float dot(const Vector2& a, const Vector2& b) {
49  return a.dot(b);
50 }
51 
52 inline float dot(const Vector3& a, const Vector3& b) {
53  return a.dot(b);
54 }
55 
56 inline float dot(const Vector4& a, const Vector4& b) {
57  return a.dot(b);
58 }
59 
60 inline Vector2 normalize(const Vector2& v) {
61  return v / v.length();
62 }
63 
64 inline Vector3 normalize(const Vector3& v) {
65  return v / v.magnitude();
66 }
67 
68 inline Vector4 normalize(const Vector4& v) {
69  return v / v.length();
70 }
71 
72 inline Vector2 abs(const Vector2& v) {
73  return Vector2(::fabsf(v.x), ::fabsf(v.y));
74 }
75 
76 inline Vector3 abs(const Vector3& v) {
77  return Vector3(::fabsf(v.x), ::fabsf(v.y), ::fabsf(v.z));
78 }
79 
80 inline Vector4 abs(const Vector4& v) {
81  return Vector4(::fabsf(v.x), ::fabsf(v.y), ::fabsf(v.z), ::fabsf(v.w));
82 }
83 
84 inline bool all(const Vector2& v) {
85  return (v.x != 0) && (v.y != 0);
86 }
87 
88 inline bool all(const Vector3& v) {
89  return (v.x != 0) && (v.y != 0) && (v.z != 0);
90 }
91 
92 inline bool all(const Vector4& v) {
93  return (v.x != 0) && (v.y != 0) && (v.z != 0) && (v.w != 0);
94 }
95 
96 inline bool any(const Vector2& v) {
97  return (v.x != 0) || (v.y != 0);
98 }
99 
100 inline bool any(const Vector3& v) {
101  return (v.x != 0) || (v.y != 0) || (v.z != 0);
102 }
103 
104 inline bool any(const Vector4& v) {
105  return (v.x != 0) || (v.y != 0) || (v.z != 0) || (v.w != 0);
106 }
107 
108 inline Vector2 clamp(const Vector2& v, const Vector2& a, const Vector2& b) {
109  return v.clamp(a, b);
110 }
111 
112 inline Vector3 clamp(const Vector3& v, const Vector3& a, const Vector3& b) {
113  return v.clamp(a, b);
114 }
115 
116 inline Vector4 clamp(const Vector4& v, const Vector4& a, const Vector4& b) {
117  return v.clamp(a, b);
118 }
119 
120 inline Vector2 lerp(const Vector2& v1, const Vector2& v2, float f) {
121  return v1.lerp(v2, f);
122 }
123 
124 inline Vector3 lerp(const Vector3& v1, const Vector3& v2, float f) {
125  return v1.lerp(v2, f);
126 }
127 
128 inline Vector4 lerp(const Vector4& v1, const Vector4& v2, float f) {
129  return v1.lerp(v2, f);
130 }
131 
132 inline Color1 lerp(const Color1& v1, const Color1& v2, float f) {
133  return v1.lerp(v2, f);
134 }
135 
136 inline Color3 lerp(const Color3& v1, const Color3& v2, float f) {
137  return v1.lerp(v2, f);
138 }
139 
140 inline Color4 lerp(const Color4& v1, const Color4& v2, float f) {
141  return v1.lerp(v2, f);
142 }
143 
144 inline Vector3 cross(const Vector3& v1, const Vector3& v2) {
145  return v1.cross(v2);
146 }
147 
148 inline double determinant(const Matrix3& m) {
149  return m.determinant();
150 }
151 
152 inline double determinant(const Matrix4& m) {
153  return m.determinant();
154 }
155 
156 inline Vector2 min(const Vector2& v1, const Vector2& v2) {
157  return v1.min(v2);
158 }
159 
160 inline Vector3 min(const Vector3& v1, const Vector3& v2) {
161  return v1.min(v2);
162 }
163 
164 inline Vector4 min(const Vector4& v1, const Vector4& v2) {
165  return v1.min(v2);
166 }
167 
168 inline Color3 min(const Color3& v1, const Color3& v2) {
169  return v1.min(v2);
170 }
171 
172 inline Color4 min(const Color4& v1, const Color4& v2) {
173  return v1.min(v2);
174 }
175 
176 inline Vector2 max(const Vector2& v1, const Vector2& v2) {
177  return v1.max(v2);
178 }
179 
180 inline Vector3 max(const Vector3& v1, const Vector3& v2) {
181  return v1.max(v2);
182 }
183 
184 inline Vector4 max(const Vector4& v1, const Vector4& v2) {
185  return v1.max(v2);
186 }
187 
188 inline Color3 max(const Color3& v1, const Color3& v2) {
189  return v1.max(v2);
190 }
191 
192 inline Color4 max(const Color4& v1, const Color4& v2) {
193  return v1.max(v2);
194 }
195 
196 inline Vector2 sign(const Vector2& v) {
197  return Vector2((float)sign(v.x), (float)sign(v.y));
198 }
199 
200 inline Vector3 sign(const Vector3& v) {
201  return Vector3((float)sign(v.x), (float)sign(v.y), (float)sign(v.z));
202 }
203 
204 inline Vector4 sign(const Vector4& v) {
205  return Vector4((float)sign(v.x), (float)sign(v.y), (float)sign(v.z), (float)sign(v.w));
206 }
207 
208 inline float length(float v) {
209  return ::fabsf(v);
210 }
211 
212 inline float length(const Vector2& v) {
213  return v.length();
214 }
215 
216 inline float length(const Vector3& v) {
217  return v.magnitude();
218 }
219 
220 inline float length(const Vector4& v) {
221  return v.length();
222 }
223 
229 inline Color3 log(const Color3& c) {
230  return Color3(::logf(c.r), ::logf(c.g), ::logf(c.b));
231 }
232 
233 }
234 
235 #endif
float length() const
Definition: Vector4.h:692
Definition: Vector2.h:40
Color4 lerp(const Color4 &other, float a) const
Definition: Color4.h:160
float x
Definition: Vector3.h:62
Quat log(const Quat &q)
Definition: Quat.h:733
float w
Definition: Vector4.h:74
double abs(double fValue)
Definition: g3dmath.h:617
Vector3 __fastcall max(const Vector3 &v) const
Definition: Vector3.h:794
Vector2 clamp(const Vector2 &low, const Vector2 &high) const
Definition: Vector2.h:137
Vector2 min(const Vector2 &v) const
Definition: Vector2.h:452
float length() const
Definition: Vector2.h:419
Vector3 clamp(const Vector3 &low, const Vector3 &high) const
Definition: Vector3.h:329
Definition: AABox.h:25
bool any(float x)
Definition: g3dmath.h:424
float mul(float a, float b)
Definition: g3dmath.h:453
Vector2 lerp(const Vector2 &v, float alpha) const
Definition: Vector2.h:133
double clamp(double val, double low, double hi)
Definition: g3dmath.h:571
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
Vector3 __fastcall min(const Vector3 &v) const
Definition: Vector3.h:789
float y
Definition: Vector3.h:62
bool all(float x)
Definition: g3dmath.h:431
float x
Definition: Vector4.h:74
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Definition: Vector3.h:58
float y
Definition: Vector2.h:50
Color3 lerp(const Color3 &other, float a) const
Definition: Color3.h:220
float normalize(float v)
Definition: g3dmath.h:438
double determinant(const Matrix3 &m)
Definition: vectorMath.h:148
Vector3 lerp(const Vector3 &v, float alpha) const
Definition: Vector3.h:357
Definition: Matrix4.h:36
T min(const T &x, const T &y)
Definition: g3dmath.h:305
float g
Definition: Color3.h:139
Color4 min(const Color4 &other) const
Definition: Color4.h:151
Vector4 max(const Vector4 &v) const
Definition: Vector4.h:669
Vector4 clamp(const Vector4 &low, const Vector4 &high) const
Definition: Vector4.h:161
float magnitude() const
Definition: Vector3.h:746
Definition: Vector4.h:39
float x
Definition: Vector2.h:49
float r
Definition: Color3.h:139
float dot(const Vector4 &rkVector) const
Definition: Vector4.h:659
float length(float v)
Definition: vectorMath.h:208
float z
Definition: Vector4.h:74
Definition: Matrix3.h:37
Vector3 __fastcall cross(const Vector3 &rkVector) const
Definition: Vector3.h:776
Vector4 min(const Vector4 &v) const
Definition: Vector4.h:664
Definition: Color1.h:28
float z
Definition: Vector3.h:62
Color1 lerp(const Color1 &other, float a) const
Definition: Color1.h:148
Definition: Color3.h:33
Vector3 cross(const Vector3 &v1, const Vector3 &v2)
Definition: vectorMath.h:144
float dot(float a, float b)
Definition: g3dmath.h:445
Color3 max(const Color3 &other) const
Definition: Color3.h:202
Color4 max(const Color4 &other) const
Definition: Color4.h:147
float y
Definition: Vector4.h:74
double lerp(double a, double b, double f)
Definition: g3dmath.h:189
float determinant() const
Definition: Matrix4.cpp:424
Vector2 max(const Vector2 &v) const
Definition: Vector2.h:458
double sign(double fValue)
Definition: g3dmath.h:669
Color3 min(const Color3 &other) const
Definition: Color3.h:206
Definition: Color4.h:33
float determinant() const
Definition: Matrix3.cpp:453
float dot(const Vector2 &s) const
Definition: Vector2.h:446
Vector4 lerp(const Vector4 &v, float alpha) const
Definition: Vector4.h:643
float b
Definition: Color3.h:139