aboutsummaryrefslogtreecommitdiff
path: root/externals/g3dlite/G3D/vectorMath.h
blob: ac6d2b32e9dbce1101d70849cebb5eb3b964ebae (plain)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
  @file vectorMath.h
 
  Function aliases for popular vector methods.
 
  @maintainer Morgan McGuire, http://graphics.cs.williams.edu
 
  @created: 2001-06-02
  @edited:  2004-02-02
  Copyright 2000-2004, Morgan McGuire.
  All rights reserved.
 */

#ifndef G3D_VECTORMATH_H
#define G3D_VECTORMATH_H

#include "G3D/platform.h"
#include "G3D/g3dmath.h"
#include "G3D/Vector2.h"
#include "G3D/Vector3.h"
#include "G3D/Vector4.h"
#include "G3D/Matrix3.h"
#include "G3D/Matrix4.h"
#include "G3D/Color1.h"
#include "G3D/Color3.h"
#include "G3D/Color4.h"


namespace G3D {


inline Matrix4 mul(const Matrix4& a, const Matrix4& b) {
    return a * b;
}

inline Vector4 mul(const Matrix4& m, const Vector4& v) {
    return m * v;
}

inline Vector3 mul(const Matrix3& m, const Vector3& v) {
    return m * v;
}

inline Matrix3 mul(const Matrix3& a, const Matrix3& b) {
    return a * b;
}

inline float dot(const Vector2& a, const Vector2& b) {
    return a.dot(b);
}

inline float dot(const Vector3& a, const Vector3& b) {
    return a.dot(b);
}

inline float dot(const Vector4& a, const Vector4& b) {
    return a.dot(b);
}

inline Vector2 normalize(const Vector2& v) {
    return v / v.length();
}

inline Vector3 normalize(const Vector3& v) {
    return v / v.magnitude();
}

inline Vector4 normalize(const Vector4& v) {
    return v / v.length();
}

inline Vector2 abs(const Vector2& v) {
    return Vector2(::fabsf(v.x), ::fabsf(v.y));
}

inline Vector3 abs(const Vector3& v) {
    return Vector3(::fabsf(v.x), ::fabsf(v.y), ::fabsf(v.z));
}

inline Vector4 abs(const Vector4& v) {
    return Vector4(::fabsf(v.x), ::fabsf(v.y), ::fabsf(v.z), ::fabsf(v.w));
}

inline bool all(const Vector2& v) {
    return (v.x != 0) && (v.y != 0);
}

inline bool all(const Vector3& v) {
    return (v.x != 0) && (v.y != 0) && (v.z != 0);
}

inline bool all(const Vector4& v) {
    return (v.x != 0) && (v.y != 0) && (v.z != 0) && (v.w != 0);
}

inline bool any(const Vector2& v) {
    return (v.x != 0) || (v.y != 0);
}

inline bool any(const Vector3& v) {
    return (v.x != 0) || (v.y != 0) || (v.z != 0);
}

inline bool any(const Vector4& v) {
    return (v.x != 0) || (v.y != 0) || (v.z != 0) || (v.w != 0);
}

inline Vector2 clamp(const Vector2& v, const Vector2& a, const Vector2& b) {
    return v.clamp(a, b);
}

inline Vector3 clamp(const Vector3& v, const Vector3& a, const Vector3& b) {
    return v.clamp(a, b);
}

inline Vector4 clamp(const Vector4& v, const Vector4& a, const Vector4& b) {
    return v.clamp(a, b);
}

inline Vector2 lerp(const Vector2& v1, const Vector2& v2, float f) {
    return v1.lerp(v2, f);
}

inline Vector3 lerp(const Vector3& v1, const Vector3& v2, float f) {
    return v1.lerp(v2, f);
}

inline Vector4 lerp(const Vector4& v1, const Vector4& v2, float f) {
    return v1.lerp(v2, f);
}

inline Color1 lerp(const Color1& v1, const Color1& v2, float f) {
    return v1.lerp(v2, f);
}

inline Color3 lerp(const Color3& v1, const Color3& v2, float f) {
    return v1.lerp(v2, f);
}

inline Color4 lerp(const Color4& v1, const Color4& v2, float f) {
    return v1.lerp(v2, f);
}

inline Vector3 cross(const Vector3& v1, const Vector3& v2) {
    return v1.cross(v2);
}

inline double determinant(const Matrix3& m) {
    return m.determinant();
}

inline double determinant(const Matrix4& m) {
    return m.determinant();
}

inline Vector2 min(const Vector2& v1, const Vector2& v2) {
    return v1.min(v2);
}

inline Vector3 min(const Vector3& v1, const Vector3& v2) {
    return v1.min(v2);
}

inline Vector4 min(const Vector4& v1, const Vector4& v2) {
    return v1.min(v2);
}

inline Color3 min(const Color3& v1, const Color3& v2) {
    return v1.min(v2);
}

inline Color4 min(const Color4& v1, const Color4& v2) {
    return v1.min(v2);
}

inline Vector2 max(const Vector2& v1, const Vector2& v2) {
    return v1.max(v2);
}

inline Vector3 max(const Vector3& v1, const Vector3& v2) {
    return v1.max(v2);
}

inline Vector4 max(const Vector4& v1, const Vector4& v2) {
    return v1.max(v2);
}

inline Color3 max(const Color3& v1, const Color3& v2) {
    return v1.max(v2);
}

inline Color4 max(const Color4& v1, const Color4& v2) {
    return v1.max(v2);
}

inline Vector2 sign(const Vector2& v) {
    return Vector2((float)sign(v.x), (float)sign(v.y));
}

inline Vector3 sign(const Vector3& v) {
    return Vector3((float)sign(v.x), (float)sign(v.y), (float)sign(v.z));
}

inline Vector4 sign(const Vector4& v) {
    return Vector4((float)sign(v.x), (float)sign(v.y), (float)sign(v.z), (float)sign(v.w));
}

inline float length(float v) {
    return ::fabsf(v);
}

inline float length(const Vector2& v) {
    return v.length();
}

inline float length(const Vector3& v) {
    return v.magnitude();
}

inline float length(const Vector4& v) {
    return v.length();
}

/**
 Computes the log of each component.  Useful for
 inverting the monitor gamma function or simulating
 perceptual response.
 */
inline Color3 log(const Color3& c) {
    return Color3(::logf(c.r), ::logf(c.g), ::logf(c.b));
}

}

#endif