9 #ifndef _util_misc_algebra_h
10 #define _util_misc_algebra_h
19 typedef double (*V_FCT_PTR)(double);
27 enum {VX, VY, VZ, VW};
28 enum {PA, PB, PC, PD};
29 enum {RED, GREEN, BLUE};
48 vec2(
const double x,
const double y);
59 vec2& operator *= (
const double d );
60 vec2& operator /= (
const double d );
61 double& operator [] (
int i);
62 const double& operator[](
int i)
const;
69 vec2& apply(V_FCT_PTR fct);
73 friend vec2 operator - (
const vec2& v);
76 friend vec2 operator * (
const vec2& a,
const double d);
77 friend vec2 operator * (
const double d,
const vec2& a);
80 friend double operator * (
const vec2& a,
const vec2& b);
81 friend vec2 operator / (
const vec2& a,
const double d);
83 friend int operator == (
const vec2& a,
const vec2& b);
84 friend int operator != (
const vec2& a,
const vec2& b);
85 friend std::ostream& operator << (std::ostream& s,
vec2& v);
86 friend std::istream& operator >> (std::istream& s,
vec2& v);
114 vec3(
const double x,
const double y,
const double z);
115 vec3(
const double d);
125 vec3& operator += (
const vec3& v );
126 vec3& operator -= (
const vec3& v );
127 vec3& operator *= (
const double d );
128 vec3& operator /= (
const double d );
129 double& operator [] (
int i);
130 const double& operator[](
int i)
const;
137 vec3& apply(V_FCT_PTR fct);
141 friend vec3 operator - (
const vec3& v);
144 friend vec3 operator * (
const vec3& a,
const double d);
145 friend vec3 operator * (
const double d,
const vec3& a);
148 friend double operator * (
const vec3& a,
const vec3& b);
149 friend vec3 operator / (
const vec3& a,
const double d);
151 friend int operator == (
const vec3& a,
const vec3& b);
152 friend int operator != (
const vec3& a,
const vec3& b);
153 friend std::ostream& operator << (std::ostream& s,
vec3& v);
154 friend std::istream& operator >> (std::istream& s,
vec3& v);
186 vec4(
const double x,
const double y,
const double z,
const double w);
187 vec4(
const double d);
190 vec4(
const vec3& v,
const double d);
195 vec4& operator += (
const vec4& v );
196 vec4& operator -= (
const vec4& v );
197 vec4& operator *= (
const double d );
198 vec4& operator /= (
const double d );
199 double& operator [] (
int i);
200 const double& operator [] (
int i)
const;
207 vec4& apply(V_FCT_PTR fct);
211 friend vec4 operator - (
const vec4& v);
214 friend vec4 operator * (
const vec4& a,
const double d);
215 friend vec4 operator * (
const double d,
const vec4& a);
218 friend double operator * (
const vec4& a,
const vec4& b);
219 friend vec4 operator / (
const vec4& a,
const double d);
220 friend int operator == (
const vec4& a,
const vec4& b);
221 friend int operator != (
const vec4& a,
const vec4& b);
222 friend std::ostream& operator << (std::ostream& s,
vec4& v);
223 friend std::istream& operator >> (std::istream& s,
vec4& v);
255 mat3(
const double d);
261 mat3& operator += (
const mat3& m );
262 mat3& operator -= (
const mat3& m );
263 mat3& operator *= (
const double d );
264 mat3& operator /= (
const double d );
265 vec3& operator [] (
int i);
266 const vec3& operator [] (
int i)
const;
270 mat3 transpose()
const;
272 mat3& apply(V_FCT_PTR fct);
276 friend mat3 operator - (
const mat3& a);
280 friend mat3 operator * (
const mat3& a,
const double d);
281 friend mat3 operator * (
const double d,
const mat3& a);
282 friend mat3 operator / (
const mat3& a,
const double d);
283 friend int operator == (
const mat3& a,
const mat3& b);
284 friend int operator != (
const mat3& a,
const mat3& b);
285 friend std::ostream& operator << (std::ostream& s,
mat3& m);
286 friend std::istream& operator >> (std::istream& s,
mat3& m);
313 mat4(
const double d);
319 mat4& operator += (
const mat4& m );
320 mat4& operator -= (
const mat4& m );
321 mat4& operator *= (
const double d );
322 mat4& operator /= (
const double d );
323 vec4& operator [] (
int i);
324 const vec4& operator [] (
int i)
const;
328 mat4 transpose()
const;
330 mat4& apply(V_FCT_PTR fct);
334 friend mat4 operator - (
const mat4& a);
338 friend mat4 operator * (
const mat4& a,
const double d);
339 friend mat4 operator * (
const double d,
const mat4& a);
340 friend mat4 operator / (
const mat4& a,
const double d);
341 friend int operator == (
const mat4& a,
const mat4& b);
342 friend int operator != (
const mat4& a,
const mat4& b);
343 friend std::ostream& operator << (std::ostream& s,
mat4& m);
344 friend std::istream& operator >> (std::istream& s,
mat4& m);
361 mat3 rotation2D(
const vec2& Center,
const double angleDeg);
362 mat3 scaling2D(
const vec2& scaleVector);
365 mat4 rotation3D(
const vec3& Axis,
const double angleDeg);
366 mat4 scaling3D(
const vec3& scaleVector);
367 mat4 perspective3D(
const double d);