reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofVectorMath.h
Go to the documentation of this file.
1#pragma once
2
3#include "ofVec2f.h"
4#include "ofVec3f.h"
5#include "ofVec4f.h"
6#include "ofMatrix3x3.h"
7#include "ofMatrix4x4.h"
8#include "ofQuaternion.h"
9
10#include "ofMathConstants.h"
11#include "ofConstants.h"
12//#include "glm/glm.hpp"
13
14//#include "glm/detail/setup.hpp"
15//#include "glm/detail/_swizzle.hpp"
16//#include "glm/detail/_swizzle_func.hpp"
17
18#include "glm/vec2.hpp"
19#include "glm/vec3.hpp"
20#include "glm/vec4.hpp"
21#include "glm/mat3x3.hpp"
22#include "glm/mat4x4.hpp"
23#include "glm/geometric.hpp"
24#include "glm/common.hpp"
25#include "glm/trigonometric.hpp"
26#include "glm/exponential.hpp"
27#include "glm/vector_relational.hpp"
28
29#include "glm/gtc/constants.hpp"
30#include "glm/gtc/matrix_transform.hpp"
31#include "glm/gtc/matrix_inverse.hpp"
32#include "glm/gtc/quaternion.hpp"
33#include "glm/gtc/epsilon.hpp"
34#include "glm/gtx/norm.hpp"
35#include "glm/gtx/perpendicular.hpp"
36#include "glm/gtx/quaternion.hpp"
37#include "glm/gtx/rotate_vector.hpp"
38#include "glm/gtx/spline.hpp"
39#include "glm/gtx/transform.hpp"
40#include "glm/gtx/vector_angle.hpp"
41#include "glm/gtx/scalar_multiplication.hpp"
42#include <glm/gtc/type_ptr.hpp>
43
44#include <iomanip>
45
46//--------------------------------------------------------------
47inline const ofVec2f & toOf(const glm::vec2 & v){
48 return *reinterpret_cast<const ofVec2f*>(&v);
49}
50
51//--------------------------------------------------------------
52inline const ofVec3f & toOf(const glm::vec3 & v){
53 return *reinterpret_cast<const ofVec3f*>(&v);
54}
55
56//--------------------------------------------------------------
57inline const ofVec4f & toOf(const glm::vec4 & v){
58 return *reinterpret_cast<const ofVec4f*>(&v);
59}
60
61//--------------------------------------------------------------
62inline const ofMatrix4x4 & toOf(const glm::mat4 & v){
63 return *reinterpret_cast<const ofMatrix4x4*>(&v);
64}
65
66//--------------------------------------------------------------
67inline const ofMatrix3x3 & toOf(const glm::mat3 & v){
68 return *reinterpret_cast<const ofMatrix3x3*>(&v);
69}
70
71//--------------------------------------------------------------
72inline const glm::vec2 & toGlm(const ofVec2f & v){
73 return *reinterpret_cast<const glm::vec2*>(&v);
74}
75
76//--------------------------------------------------------------
77inline const glm::vec3 & toGlm(const ofVec3f & v){
78 return *reinterpret_cast<const glm::vec3*>(&v);
79}
80
81//--------------------------------------------------------------
82inline const glm::vec4 & toGlm(const ofVec4f & v){
83 return *reinterpret_cast<const glm::vec4*>(&v);
84}
85
86//--------------------------------------------------------------
87inline const glm::mat4 & toGlm(const ofMatrix4x4 & v){
88 return *reinterpret_cast<const glm::mat4*>(&v);
89}
90
91//--------------------------------------------------------------
92inline const glm::mat3 & toGlm(const ofMatrix3x3 & v){
93 return *reinterpret_cast<const glm::mat3*>(&v);
94}
95
96//--------------------------------------------------------------
97inline const glm::vec2 & toGlm(const glm::vec2 & v){
98 return v;
99}
100
101//--------------------------------------------------------------
102inline const glm::vec3 & toGlm(const glm::vec3 & v){
103 return v;
104}
105
106//--------------------------------------------------------------
107inline const glm::vec4 & toGlm(const glm::vec4 & v){
108 return v;
109}
110
111//--------------------------------------------------------------
112inline const glm::quat toGlm(const ofQuaternion & q){
113 return glm::quat(q.w(), glm::vec3(q.x(), q.y(), q.z()));
114}
115
116//--------------------------------------------------------------
117inline const glm::quat & toGlm(const glm::quat & q){
118 return q;
119}
120
121namespace glm {
122 //--------------------------------------------------------------
123 template <typename T, precision P>
124 inline std::ostream& operator<<(std::ostream& os, const vec<3, T, P>& vec) {
125 os << vec.x << ", " << vec.y << ", " << vec.z;
126 return os;
127 }
128
129 //--------------------------------------------------------------
130 template <typename T, precision P>
131 inline std::istream& operator>>(std::istream& is, vec<3, T, P>& vec) {
132 is >> vec.x;
133 is.ignore(2);
134 is >> vec.y;
135 is.ignore(2);
136 is >> vec.z;
137 return is;
138 }
139
140 //--------------------------------------------------------------
141 template <typename T, precision P>
142 inline std::ostream& operator<<(std::ostream& os, const vec<2, T, P>& vec) {
143 os << vec.x << ", " << vec.y;
144 return os;
145 }
146
147 //--------------------------------------------------------------
148 template <typename T, precision P>
149 inline std::istream& operator>>(std::istream& is, vec<2, T, P>& vec) {
150 is >> vec.x;
151 is.ignore(2);
152 is >> vec.y;
153 return is;
154 }
155
156 //--------------------------------------------------------------
157 template <typename T, precision P>
158 inline std::ostream& operator<<(std::ostream& os, const vec<4, T, P>& vec) {
159 os << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w;
160 return os;
161 }
162
163 //--------------------------------------------------------------
164 template <typename T, precision P>
165 inline std::istream& operator>>(std::istream& is, vec<4, T, P>& vec) {
166 is >> vec.x;
167 is.ignore(2);
168 is >> vec.y;
169 is.ignore(2);
170 is >> vec.z;
171 is.ignore(2);
172 is >> vec.w;
173 return is;
174 }
175
176 //--------------------------------------------------------------
177 template <typename T, precision P>
178 inline std::ostream& operator<<(std::ostream& os, const mat<3, 3, T, P>& mat) {
179 int w = 8;
180 os << std::setw(w)
181 << mat[0][0] << ", " << std::setw(w)
182 << mat[0][1] << ", " << std::setw(w)
183 << mat[0][2] << std::endl;
184
185 os << std::setw(w)
186 << mat[1][0] << ", " << std::setw(w)
187 << mat[1][1] << ", " << std::setw(w)
188 << mat[1][2] << std::endl;
189
190 os << std::setw(w)
191 << mat[2][0] << ", " << std::setw(w)
192 << mat[2][1] << ", " << std::setw(w)
193 << mat[2][2];
194 return os;
195 }
196
197 //--------------------------------------------------------------
198 template <typename T, precision P>
199 inline std::istream& operator>>(std::istream& is, mat<3, 3, T, P>& mat) {
200 is >> mat[0][0]; is.ignore(2);
201 is >> mat[0][1]; is.ignore(2);
202 is >> mat[0][2]; is.ignore(1);
203
204 is >> mat[1][0]; is.ignore(2);
205 is >> mat[1][1]; is.ignore(2);
206 is >> mat[1][2]; is.ignore(1);
207
208 is >> mat[2][0]; is.ignore(2);
209 is >> mat[2][1]; is.ignore(2);
210 is >> mat[2][2];
211 return is;
212 }
213
214 //--------------------------------------------------------------
215 template <typename T, precision P>
216 inline std::ostream& operator<<(std::ostream& os, const mat<4, 4, T, P>& mat) {
217 int w = 8;
218 os << std::setw(w)
219 << mat[0][0] << ", " << std::setw(w)
220 << mat[0][1] << ", " << std::setw(w)
221 << mat[0][2] << ", " << std::setw(w)
222 << mat[0][3] << std::endl;
223
224 os << std::setw(w)
225 << mat[1][0] << ", " << std::setw(w)
226 << mat[1][1] << ", " << std::setw(w)
227 << mat[1][2] << ", " << std::setw(w)
228 << mat[1][3] << std::endl;
229
230 os << std::setw(w)
231 << mat[2][0] << ", " << std::setw(w)
232 << mat[2][1] << ", " << std::setw(w)
233 << mat[2][2] << ", " << std::setw(w)
234 << mat[2][3] << std::endl;
235
236 os << std::setw(w)
237 << mat[3][0] << ", " << std::setw(w)
238 << mat[3][1] << ", " << std::setw(w)
239 << mat[3][2] << ", " << std::setw(w)
240 << mat[3][3];
241 return os;
242 }
243
244 //--------------------------------------------------------------
245 template <typename T, precision P>
246 inline std::istream& operator>>(std::istream& is, mat<4, 4, T, P>& mat) {
247 is >> mat[0][0]; is.ignore(2);
248 is >> mat[0][1]; is.ignore(2);
249 is >> mat[0][2]; is.ignore(2);
250 is >> mat[0][3]; is.ignore(1);
251
252 is >> mat[1][0]; is.ignore(2);
253 is >> mat[1][1]; is.ignore(2);
254 is >> mat[1][2]; is.ignore(2);
255 is >> mat[1][3]; is.ignore(1);
256
257 is >> mat[2][0]; is.ignore(2);
258 is >> mat[2][1]; is.ignore(2);
259 is >> mat[2][2]; is.ignore(2);
260 is >> mat[2][3]; is.ignore(1);
261
262 is >> mat[3][0]; is.ignore(2);
263 is >> mat[3][1]; is.ignore(2);
264 is >> mat[3][2]; is.ignore(2);
265 is >> mat[3][3];
266 return is;
267 }
268
269 //----------------------------------------
270 template <typename T, precision P>
271 inline std::ostream& operator<<(std::ostream& os, const qua<T, P>& q) {
272 os << q.w << ", " << q.x << ", " << q.y << ", " << q.z;
273 return os;
274 }
275
276
277 //----------------------------------------
278 template <typename T, precision P>
279 inline std::istream& operator>> (std::istream& is, qua<T, P>& q) {
280 is >> q.w;
281 is.ignore(2);
282 is >> q.x;
283 is.ignore(2);
284 is >> q.y;
285 is.ignore(2);
286 is >> q.z;
287 return is;
288 }
289}
290
291//--------------------------------------------------------------
292inline glm::vec3 operator+(const glm::vec3 & v1, const ofVec3f & v2){
293 return v1 + glm::vec3(v2);
294}
295
296//--------------------------------------------------------------
297inline glm::vec3 operator-(const glm::vec3 & v1, const ofVec3f & v2){
298 return v1 - glm::vec3(v2);
299}
300
301//--------------------------------------------------------------
302inline glm::vec3 operator*(const glm::vec3 & v1, const ofVec3f & v2){
303 return v1 * glm::vec3(v2);
304}
305
306//--------------------------------------------------------------
307inline glm::vec3 operator/(const glm::vec3 & v1, const ofVec3f & v2){
308 return v1 / glm::vec3(v2);
309}
310
311//--------------------------------------------------------------
312inline glm::vec3 & operator+=(glm::vec3 & v1, const ofVec3f & v2){
313 v1 += glm::vec3(v2);
314 return v1;
315}
316
317//--------------------------------------------------------------
318inline glm::vec3 & operator-=(glm::vec3 & v1, const ofVec3f & v2){
319 v1 -= glm::vec3(v2);
320 return v1;
321}
322
323//--------------------------------------------------------------
324inline glm::vec3 & operator*=(glm::vec3 & v1, const ofVec3f & v2){
325 v1 *= glm::vec3(v2);
326 return v1;
327}
328
329//--------------------------------------------------------------
330inline glm::vec3 & operator/=(glm::vec3 & v1, const ofVec3f & v2){
331 v1 /= glm::vec3(v2);
332 return v1;
333}
334
335//--------------------------------------------------------------
336inline glm::vec2 operator+(const glm::vec2 & v1, const ofVec2f & v2){
337 return v1 + glm::vec2(v2);
338}
339
340//--------------------------------------------------------------
341inline glm::vec2 operator-(const glm::vec2 & v1, const ofVec2f & v2){
342 return v1 - glm::vec2(v2);
343}
344
345//--------------------------------------------------------------
346inline glm::vec2 operator*(const glm::vec2 & v1, const ofVec2f & v2){
347 return v1 * glm::vec2(v2);
348}
349
350//--------------------------------------------------------------
351inline glm::vec2 operator/(const glm::vec2 & v1, const ofVec2f & v2){
352 return v1 / glm::vec2(v2);
353}
354
355//--------------------------------------------------------------
356inline glm::vec2 & operator+=(glm::vec2 & v1, const ofVec2f & v2){
357 v1 += glm::vec2(v2);
358 return v1;
359}
360
361//--------------------------------------------------------------
362inline glm::vec2 & operator-=(glm::vec2 & v1, const ofVec2f & v2){
363 v1 -= glm::vec2(v2);
364 return v1;
365}
366
367//--------------------------------------------------------------
368inline glm::vec2 & operator*=(glm::vec2 & v1, const ofVec2f & v2){
369 v1 *= glm::vec2(v2);
370 return v1;
371}
372
373//--------------------------------------------------------------
374inline glm::vec2 & operator/=(glm::vec2 & v1, const ofVec2f & v2){
375 v1 /= glm::vec2(v2);
376 return v1;
377}
378
379
A 3x3 Matrix.
Definition ofMatrix3x3.h:20
The ofMatrix4x4 is the big class of the math part of openFrameworks.
Definition ofMatrix4x4.h:58
Definition ofQuaternion.h:27
float & w()
Definition ofQuaternion.h:313
float & y()
Definition ofQuaternion.h:301
float & z()
Definition ofQuaternion.h:307
float & x()
Definition ofQuaternion.h:295
ofVec2f is a class for storing a two dimensional vector.
Definition ofVec2f.h:72
ofVec3f is a class for storing a three dimensional vector.
Definition ofVec3f.h:79
Definition ofVec4f.h:11
Definition ofVectorMath.h:121
std::ostream & operator<<(std::ostream &os, const vec< 3, T, P > &vec)
Definition ofVectorMath.h:124
std::istream & operator>>(std::istream &is, vec< 3, T, P > &vec)
Definition ofVectorMath.h:131
glm::vec3 operator+(const glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:292
glm::vec3 operator/(const glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:307
const ofVec2f & toOf(const glm::vec2 &v)
Definition ofVectorMath.h:47
glm::vec3 & operator/=(glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:330
glm::vec3 & operator*=(glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:324
glm::vec3 & operator+=(glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:312
const glm::vec2 & toGlm(const ofVec2f &v)
Definition ofVectorMath.h:72
glm::vec3 operator*(const glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:302
glm::vec3 & operator-=(glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:318
glm::vec3 operator-(const glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:297