Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/DivideSever/Utility/Headers/MathClasses.h

Diff revisions: vs.
  @@ -37,6 +37,15 @@
37 37 #include <stdlib.h>
38 38 #include <math.h>
39 39
40 + #pragma warning(disable:4201) // nameless struct/union
41 +
42 + #ifndef F32
43 + #define F32 float
44 + #endif
45 + #ifndef I32
46 + #define I32 signed int
47 + #endif
48 +
40 49 #define EPSILON 0.000001f
41 50 #ifndef M_PI
42 51 #define M_PI 3.141592653589793238462643383279f // PI
  @@ -58,10 +67,6 @@
58 67 class vec4;
59 68 class mat3;
60 69 class mat4;
61 - class quat;
62 - class ivec2;
63 - class ivec3;
64 - class ivec4;
65 70
66 71 /*****************************************************************************/
67 72 /* */
  @@ -72,18 +77,18 @@
72 77 class vec2 {
73 78 public:
74 79 vec2(void) : x(0), y(0) { }
75 - vec2(float _x,float _y) : x(_x), y(_y) { }
76 - vec2(const float *_v) : x(_v[0]), y(_v[1]) { }
80 + vec2(F32 _x,F32 _y) : x(_x), y(_y) { }
81 + vec2(const F32 *_v) : x(_v[0]), y(_v[1]) { }
77 82 vec2(const vec2 &_v) : x(_v.x), y(_v.y) { }
78 83 vec2(const vec3 &_v);
79 84 vec2(const vec4 &_v);
80 85
81 - int operator==(const vec2 &_v) { return (fabs(this->x - _v.x) < EPSILON && fabs(this->y - _v.y) < EPSILON); }
82 - int operator!=(const vec2 &_v) { return !(*this == _v); }
86 + I32 operator==(const vec2 &_v) { return (fabs(this->x - _v.x) < EPSILON && fabs(this->y - _v.y) < EPSILON); }
87 + I32 operator!=(const vec2 &_v) { return !(*this == _v); }
83 88
84 - vec2 &operator=(float _f) { this->x=_f; this->y=_f; return (*this); }
85 - const vec2 operator*(float _f) const { return vec2(this->x * _f,this->y * _f); }
86 - const vec2 operator/(float _f) const {
89 + vec2 &operator=(F32 _f) { this->x=_f; this->y=_f; return (*this); }
90 + const vec2 operator*(F32 _f) const { return vec2(this->x * _f,this->y * _f); }
91 + const vec2 operator/(F32 _f) const {
87 92 if(fabs(_f) < EPSILON) return *this;
88 93 _f = 1.0f / _f;
89 94 return (*this) * _f;
  @@ -92,77 +97,77 @@
92 97 const vec2 operator-() const { return vec2(-this->x,-this->y); }
93 98 const vec2 operator-(const vec2 &_v) const { return vec2(this->x - _v.x,this->y - _v.y); }
94 99
95 - vec2 &operator*=(float _f) { return *this = *this * _f; }
96 - vec2 &operator/=(float _f) { return *this = *this / _f; }
100 + vec2 &operator*=(F32 _f) { return *this = *this * _f; }
101 + vec2 &operator/=(F32 _f) { return *this = *this / _f; }
97 102 vec2 &operator+=(const vec2 &_v) { return *this = *this + _v; }
98 103 vec2 &operator-=(const vec2 &_v) { return *this = *this - _v; }
99 104
100 - float operator*(const vec2 &_v) const { return this->x * _v.x + this->y * _v.y; }
105 + F32 operator*(const vec2 &_v) const { return this->x * _v.x + this->y * _v.y; }
101 106
102 - operator float*() { return this->v; }
103 - operator const float*() const { return this->v; }
104 - // float &operator[](int _i) { return this->v[_i]; }
105 - // const float &operator[](int _i) const { return this->v[_i]; }
107 + operator F32*() { return this->v; }
108 + operator const F32*() const { return this->v; }
109 + // F32 &operator[](I32 _i) { return this->v[_i]; }
110 + // const F32 &operator[](I32 _i) const { return this->v[_i]; }
106 111
107 - void set(float _x,float _y) { this->x = _x; this->y = _y; }
112 + void set(F32 _x,F32 _y) { this->x = _x; this->y = _y; }
108 113 void reset(void) { this->x = this->y = 0; }
109 - float length(void) const { return sqrtf(this->x * this->x + this->y * this->y); }
110 - float normalize(void) {
111 - float inv,l = this->length();
114 + F32 length(void) const { return sqrtf(this->x * this->x + this->y * this->y); }
115 + F32 normalize(void) {
116 + F32 inv,l = this->length();
112 117 if(l < EPSILON) return 0.0f;
113 118 inv = 1.0f / l;
114 119 this->x *= inv;
115 120 this->y *= inv;
116 121 return l;
117 122 }
118 - float dot(const vec2 &v) { return ((this->x*v.x) + (this->y*v.y)); } // Produit scalaire
119 - bool compare(const vec2 &_v,float epsi=EPSILON) { return (fabs(this->x - _v.x) < epsi && fabs(this->y - _v.y) < epsi); }
123 + F32 dot(const vec2 &v) { return ((this->x*v.x) + (this->y*v.y)); } // Produit scalaire
124 + bool compare(const vec2 &_v,F32 epsi=EPSILON) { return (fabs(this->x - _v.x) < epsi && fabs(this->y - _v.y) < epsi); }
120 125 // retourne les coordonn�e du point le plus proche de *this sur la droite passant par vA et vB
121 126 vec2 closestPointOnLine(const vec2 &vA, const vec2 &vB) { return (((vB-vA) * this->projectionOnLine(vA, vB)) + vA); }
122 127 // retourne les coordonn�e du point le plus proche de *this sur le segment vA,vB
123 128 vec2 closestPointOnSegment(const vec2 &vA, const vec2 &vB) {
124 - float factor = this->projectionOnLine(vA, vB);
129 + F32 factor = this->projectionOnLine(vA, vB);
125 130 if (factor <= 0.0f) return vA;
126 131 if (factor >= 1.0f) return vB;
127 132 return (((vB-vA) * factor) + vA);
128 133 }
129 134 // retourne le facteur de la projection de *this sur la droite passant par vA et vB
130 - float projectionOnLine(const vec2 &vA, const vec2 &vB) {
135 + F32 projectionOnLine(const vec2 &vA, const vec2 &vB) {
131 136 vec2 v(vB - vA);
132 137 return v.dot(*this - vA) / v.dot(v);
133 138 }
134 139 // Fonction d'interpolation lin�aire entre 2 vecteurs
135 - vec2 lerp(vec2 &u, vec2 &v, float factor) { return ((u * (1 - factor)) + (v * factor)); }
140 + vec2 lerp(vec2 &u, vec2 &v, F32 factor) { return ((u * (1 - factor)) + (v * factor)); }
136 141 vec2 lerp(vec2 &u, vec2 &v, vec2& factor) { return (vec2((u.x * (1 - factor.x)) + (v.x * factor.x), (u.y * (1 - factor.y)) + (v.y * factor.y))); }
137 - float angle(void) { return (float)atan2(this->y,this->x); }
138 - float angle(const vec2 &v) { return (float)atan2(v.y-this->y,v.x-this->x); }
142 + F32 angle(void) { return (F32)atan2(this->y,this->x); }
143 + F32 angle(const vec2 &v) { return (F32)atan2(v.y-this->y,v.x-this->x); }
139 144
140 145 union {
141 - struct {float x,y;};
142 - struct {float s,t;};
143 - float v[2];
146 + struct {F32 x,y;};
147 + struct {F32 s,t;};
148 + F32 v[2];
144 149 };
145 150 };
146 151
147 - inline vec2 operator*(float fl, const vec2& v) { return vec2(v.x*fl, v.y*fl);}
152 + inline vec2 operator*(F32 fl, const vec2& v) { return vec2(v.x*fl, v.y*fl);}
148 153
149 - inline float Dot(const vec2& a, const vec2& b) { return(a.x*b.x+a.y*b.y); }
154 + inline F32 Dot(const vec2& a, const vec2& b) { return(a.x*b.x+a.y*b.y); }
150 155
151 156 class vec3 {
152 157 public:
153 158 vec3(void) : x(0), y(0), z(0) { }
154 - vec3(float _x,float _y,float _z) : x(_x), y(_y), z(_z) { }
155 - vec3(const float *_v) : x(_v[0]), y(_v[1]), z(_v[2]) { }
156 - vec3(const vec2 &_v,float _z) : x(_v.x), y(_v.y), z(_z) { }
159 + vec3(F32 _x,F32 _y,F32 _z) : x(_x), y(_y), z(_z) { }
160 + vec3(const F32 *_v) : x(_v[0]), y(_v[1]), z(_v[2]) { }
161 + vec3(const vec2 &_v,F32 _z) : x(_v.x), y(_v.y), z(_z) { }
157 162 vec3(const vec3 &_v) : x(_v.x), y(_v.y), z(_v.z) { }
158 163 vec3(const vec4 &_v);
159 164
160 - int operator==(const vec3 &_v) { return (fabs(this->x - _v.x) < EPSILON && fabs(this->y - _v.y) < EPSILON && fabs(this->z - _v.z) < EPSILON); }
161 - int operator!=(const vec3 &_v) { return !(*this == _v); }
165 + I32 operator==(const vec3 &_v) { return (fabs(this->x - _v.x) < EPSILON && fabs(this->y - _v.y) < EPSILON && fabs(this->z - _v.z) < EPSILON); }
166 + I32 operator!=(const vec3 &_v) { return !(*this == _v); }
162 167
163 - vec3 &operator=(float _f) { this->x=_f; this->y=_f; this->z=_f; return (*this); }
164 - const vec3 operator*(float _f) const { return vec3(this->x * _f,this->y * _f,this->z * _f); }
165 - const vec3 operator/(float _f) const {
168 + vec3 &operator=(F32 _f) { this->x=_f; this->y=_f; this->z=_f; return (*this); }
169 + const vec3 operator*(F32 _f) const { return vec3(this->x * _f,this->y * _f,this->z * _f); }
170 + const vec3 operator/(F32 _f) const {
166 171 if(fabs(_f) < EPSILON) return *this;
167 172 _f = 1.0f / _f;
168 173 return (*this) * _f;
  @@ -172,22 +177,22 @@
172 177 const vec3 operator-() const { return vec3(-this->x,-this->y,-this->z); }
173 178 const vec3 operator-(const vec3 &_v) const { return vec3(this->x - _v.x,this->y - _v.y,this->z - _v.z); }
174 179
175 - vec3 &operator*=(float _f) { return *this = *this * _f; }
176 - vec3 &operator/=(float _f) { return *this = *this / _f; }
180 + vec3 &operator*=(F32 _f) { return *this = *this * _f; }
181 + vec3 &operator/=(F32 _f) { return *this = *this / _f; }
177 182 vec3 &operator+=(const vec3 &_v) { return *this = *this + _v; }
178 183 vec3 &operator-=(const vec3 &_v) { return *this = *this - _v; }
179 184
180 - float operator*(const vec3 &_v) const { return this->x * _v.x + this->y * _v.y + this->z * _v.z; }
181 - float operator*(const vec4 &_v) const;
182 - //float operator[](const int i) {switch(i){case 0: return this->x; case 1: return this->y; case 2: return this->z;};}
183 - operator float*() { return this->v; }
184 - operator const float*() const { return this->v; }
185 + F32 operator*(const vec3 &_v) const { return this->x * _v.x + this->y * _v.y + this->z * _v.z; }
186 + F32 operator*(const vec4 &_v) const;
187 + //F32 operator[](const I32 i) {switch(i){case 0: return this->x; case 1: return this->y; case 2: return this->z;};}
188 + operator F32*() { return this->v; }
189 + operator const F32*() const { return this->v; }
185 190
186 - void set(float _x,float _y,float _z) { this->x = _x; this->y = _y; this->z = _z; }
191 + void set(F32 _x,F32 _y,F32 _z) { this->x = _x; this->y = _y; this->z = _z; }
187 192 void reset(void) { this->x = this->y = this->z = 0; }
188 - float length(void) const { return sqrtf(this->x * this->x + this->y * this->y + this->z * this->z); }
189 - float normalize(void) {
190 - float inv,l = this->length();
193 + F32 length(void) const { return sqrtf(this->x * this->x + this->y * this->y + this->z * this->z); }
194 + F32 normalize(void) {
195 + F32 inv,l = this->length();
191 196 if(l < EPSILON) return 0.0f;
192 197 inv = 1.0f / l;
193 198 this->x *= inv;
  @@ -203,19 +208,19 @@
203 208 }
204 209
205 210 void cross(const vec3 &v2) {
206 - float x = this->y * v2.z - this->z * v2.y;
207 - float y = this->z * v2.x - this->x * v2.z;
211 + F32 x = this->y * v2.z - this->z * v2.y;
212 + F32 y = this->z * v2.x - this->x * v2.z;
208 213 this->z = this->x * v2.y - this->y * v2.x;
209 214 this->y = y;
210 215 this->x = x;
211 216 }
212 217
213 - float dot(const vec3 &v) { return ((this->x*v.x) + (this->y*v.y) + (this->z*v.z)); }
214 - bool compare(const vec3 &_v,float epsi=EPSILON) { return (fabs(this->x - _v.x) < epsi && fabs(this->y - _v.y) < epsi && fabs(this->z - _v.z) < epsi); }
218 + F32 dot(const vec3 &v) { return ((this->x*v.x) + (this->y*v.y) + (this->z*v.z)); }
219 + bool compare(const vec3 &_v,F32 epsi=EPSILON) { return (fabs(this->x - _v.x) < epsi && fabs(this->y - _v.y) < epsi && fabs(this->z - _v.z) < epsi); }
215 220
216 221 //Returns the angle in radians between '*this' and 'v'
217 - float angle(vec3 &v) {
218 - float angle = (float)fabs(acos(this->dot(v)/(this->length()*v.length())));
222 + F32 angle(vec3 &v) {
223 + F32 angle = (F32)fabs(acos(this->dot(v)/(this->length()*v.length())));
219 224 if(angle < EPSILON) return 0;
220 225 return angle;
221 226 }
  @@ -223,37 +228,37 @@
223 228
224 229 vec3 closestPointOnLine(const vec3 &vA, const vec3 &vB) { return (((vB-vA) * this->projectionOnLine(vA, vB)) + vA); }
225 230 vec3 closestPointOnSegment(const vec3 &vA, const vec3 &vB) {
226 - float factor = this->projectionOnLine(vA, vB);
231 + F32 factor = this->projectionOnLine(vA, vB);
227 232 if (factor <= 0.0f) return vA;
228 233 if (factor >= 1.0f) return vB;
229 234 return (((vB-vA) * factor) + vA);
230 235 }
231 - float projectionOnLine(const vec3 &vA, const vec3 &vB) {
236 + F32 projectionOnLine(const vec3 &vA, const vec3 &vB) {
232 237 vec3 v(vB - vA);
233 238 return v.dot(*this - vA) / v.dot(v);
234 239 }
235 - vec3 lerp(vec3 &u, vec3 &v, float factor) { return ((u * (1 - factor)) + (v * factor)); }
240 + vec3 lerp(vec3 &u, vec3 &v, F32 factor) { return ((u * (1 - factor)) + (v * factor)); }
236 241 vec3 lerp(vec3 &u, vec3 &v, vec3& factor) { return (vec3( (u.x * (1 - factor.x)) + (v.x * factor.x),
237 242 (u.y * (1 - factor.y)) + (v.y * factor.y),
238 243 (u.z * (1 - factor.z)) + (v.z * factor.z))); }
239 244 union {
240 - struct {float x,y,z;};
241 - struct {float s,t,p;};
242 - struct {float r,g,b;};
243 - float v[3];
245 + struct {F32 x,y,z;};
246 + struct {F32 s,t,p;};
247 + struct {F32 r,g,b;};
248 + F32 v[3];
244 249 };
245 250
246 - inline void get(float * v) const
251 + inline void get(F32 * v) const
247 252 {
248 - v[0] = (float)this->x;
249 - v[1] = (float)this->y;
250 - v[2] = (float)this->z;
253 + v[0] = (F32)this->x;
254 + v[1] = (F32)this->y;
255 + v[2] = (F32)this->z;
251 256 }
252 257 };
253 258
254 - inline vec3 operator*(float fl, const vec3& v) { return vec3(v.x*fl, v.y*fl, v.z*fl);}
259 + inline vec3 operator*(F32 fl, const vec3& v) { return vec3(v.x*fl, v.y*fl, v.z*fl);}
255 260
256 - inline float Dot(const vec3& a, const vec3& b) { return(a.x*b.x+a.y*b.y+a.z*b.z); }
261 + inline F32 Dot(const vec3& a, const vec3& b) { return(a.x*b.x+a.y*b.y+a.z*b.z); }
257 262 inline vec3 Cross(const vec3 &v1, const vec3 &v2) {
258 263 return vec3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x);
259 264 }
  @@ -278,18 +283,18 @@
278 283 class vec4 {
279 284 public:
280 285 vec4(void) : x(0), y(0), z(0), w(1) { }
281 - vec4(float _x,float _y,float _z,float _w) : x(_x), y(_y), z(_z), w(_w) { }
282 - vec4(const float *_v) : x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]) { }
286 + vec4(F32 _x,F32 _y,F32 _z,F32 _w) : x(_x), y(_y), z(_z), w(_w) { }
287 + vec4(const F32 *_v) : x(_v[0]), y(_v[1]), z(_v[2]), w(_v[3]) { }
283 288 vec4(const vec3 &_v) : x(_v.x), y(_v.y), z(_v.z), w(1) { }
284 - vec4(const vec3 &_v,float _w) : x(_v.x), y(_v.y), z(_v.z), w(_w) { }
289 + vec4(const vec3 &_v,F32 _w) : x(_v.x), y(_v.y), z(_v.z), w(_w) { }
285 290 vec4(const vec4 &_v) : x(_v.x), y(_v.y), z(_v.z), w(_v.w) { }
286 291
287 - int operator==(const vec4 &_v) { return (fabs(this->x - _v.x) < EPSILON && fabs(this->y - _v.y) < EPSILON && fabs(this->z - _v.z) < EPSILON && fabs(this->w - _v.w) < EPSILON); }
288 - int operator!=(const vec4 &_v) { return !(*this == _v); }
292 + I32 operator==(const vec4 &_v) { return (fabs(this->x - _v.x) < EPSILON && fabs(this->y - _v.y) < EPSILON && fabs(this->z - _v.z) < EPSILON && fabs(this->w - _v.w) < EPSILON); }
293 + I32 operator!=(const vec4 &_v) { return !(*this == _v); }
289 294
290 - vec4 &operator=(float _f) { this->x=_f; this->y=_f; this->z=_f; this->w=_f; return (*this); }
291 - const vec4 operator*(float _f) const { return vec4(this->x * _f,this->y * _f,this->z * _f,this->w * _f); }
292 - const vec4 operator/(float _f) const {
295 + vec4 &operator=(F32 _f) { this->x=_f; this->y=_f; this->z=_f; this->w=_f; return (*this); }
296 + const vec4 operator*(F32 _f) const { return vec4(this->x * _f,this->y * _f,this->z * _f,this->w * _f); }
297 + const vec4 operator/(F32 _f) const {
293 298 if(fabs(_f) < EPSILON) return *this;
294 299 _f = 1.0f / _f;
295 300 return (*this) * _f;
  @@ -298,35 +303,35 @@
298 303 const vec4 operator-() const { return vec4(-x,-y,-z,-w); }
299 304 const vec4 operator-(const vec4 &_v) const { return vec4(this->x - _v.x,this->y - _v.y,this->z - _v.z,this->w - _v.w); }
300 305
301 - vec4 &operator*=(float _f) { return *this = *this * _f; }
302 - vec4 &operator/=(float _f) { return *this = *this / _f; }
306 + vec4 &operator*=(F32 _f) { return *this = *this * _f; }
307 + vec4 &operator/=(F32 _f) { return *this = *this / _f; }
303 308 vec4 &operator+=(const vec4 &_v) { return *this = *this + _v; }
304 309 vec4 &operator-=(const vec4 &_v) { return *this = *this - _v; }
305 310
306 - float operator*(const vec3 &_v) const { return this->x * _v.x + this->y * _v.y + this->z * _v.z + this->w; }
307 - float operator*(const vec4 &_v) const { return this->x * _v.x + this->y * _v.y + this->z * _v.z + this->w * _v.w; }
311 + F32 operator*(const vec3 &_v) const { return this->x * _v.x + this->y * _v.y + this->z * _v.z + this->w; }
312 + F32 operator*(const vec4 &_v) const { return this->x * _v.x + this->y * _v.y + this->z * _v.z + this->w * _v.w; }
308 313
309 - operator float*() { return this->v; }
310 - operator const float*() const { return this->v; }
311 - // float &operator[](int _i) { return this->v[_i]; }
312 - // const float &operator[](int _i) const { return this->v[_i]; }
314 + operator F32*() { return this->v; }
315 + operator const F32*() const { return this->v; }
316 + // F32 &operator[](I32 _i) { return this->v[_i]; }
317 + // const F32 &operator[](I32 _i) const { return this->v[_i]; }
313 318
314 - void set(float _x,float _y,float _z,float _w) { this->x=_x; this->y=_y; this->z=_z; this->w=_w; }
319 + void set(F32 _x,F32 _y,F32 _z,F32 _w) { this->x=_x; this->y=_y; this->z=_z; this->w=_w; }
315 320 void reset(void) { this->x = this->y = this->z = this->w = 0; }
316 - bool compare(const vec4 &_v,float epsi=EPSILON) { return (fabs(this->x - _v.x) < epsi && fabs(this->y - _v.y) < epsi && fabs(this->z - _v.z) < epsi && fabs(this->w - _v.w) < epsi); }
321 + bool compare(const vec4 &_v,F32 epsi=EPSILON) { return (fabs(this->x - _v.x) < epsi && fabs(this->y - _v.y) < epsi && fabs(this->z - _v.z) < epsi && fabs(this->w - _v.w) < epsi); }
317 322
318 - vec4 lerp(const vec4 &u, const vec4 &v, float factor) { return ((u * (1 - factor)) + (v * factor)); }
323 + vec4 lerp(const vec4 &u, const vec4 &v, F32 factor) { return ((u * (1 - factor)) + (v * factor)); }
319 324
320 325 union {
321 - struct {float x,y,z,w;};
322 - struct {float s,t,p,q;};
323 - struct {float r,g,b,a;};
324 - struct {float fov,ratio,znear,zfar;};
325 - float v[4];
326 + struct {F32 x,y,z,w;};
327 + struct {F32 s,t,p,q;};
328 + struct {F32 r,g,b,a;};
329 + struct {F32 fov,ratio,znear,zfar;};
330 + F32 v[4];
326 331 };
327 332 };
328 333
329 - inline vec4 operator*(float fl, const vec4& v) { return vec4(v.x*fl, v.y*fl, v.z*fl, v.w*fl);}
334 + inline vec4 operator*(F32 fl, const vec4& v) { return vec4(v.x*fl, v.y*fl, v.z*fl, v.w*fl);}
330 335
331 336 inline vec3::vec3(const vec4 &_v) {
332 337 this->x = _v.x;
  @@ -334,7 +339,7 @@
334 339 this->z = _v.z;
335 340 }
336 341
337 - inline float vec3::operator*(const vec4 &_v) const {
342 + inline F32 vec3::operator*(const vec4 &_v) const {
338 343 return this->x * _v.x + this->y * _v.y + this->z * _v.z + _v.w;
339 344 }
340 345
  @@ -356,14 +361,14 @@
356 361 mat[1] = 0.0; mat[4] = 1.0; mat[7] = 0.0;
357 362 mat[2] = 0.0; mat[5] = 0.0; mat[8] = 1.0;
358 363 }
359 - mat3(float m0, float m1, float m2,
360 - float m3, float m4, float m5,
361 - float m6, float m7, float m8) {
364 + mat3(F32 m0, F32 m1, F32 m2,
365 + F32 m3, F32 m4, F32 m5,
366 + F32 m6, F32 m7, F32 m8) {
362 367 mat[0] = m0; mat[3] = m3; mat[6] = m6;
363 368 mat[1] = m1; mat[4] = m4; mat[7] = m7;
364 369 mat[2] = m2; mat[5] = m5; mat[8] = m8;
365 370 }
366 - mat3(const float *m) {
371 + mat3(const F32 *m) {
367 372 mat[0] = m[0]; mat[3] = m[3]; mat[6] = m[6];
368 373 mat[1] = m[1]; mat[4] = m[4]; mat[7] = m[7];
369 374 mat[2] = m[2]; mat[5] = m[5]; mat[8] = m[8];
  @@ -386,7 +391,7 @@
386 391 mat[2] * v[0] + mat[5] * v[1] + mat[8] * v[2],
387 392 v[3]);
388 393 }
389 - mat3 operator*(float f) const {
394 + mat3 operator*(F32 f) const {
390 395 return mat3(mat[0] * f, mat[1] * f, mat[2] * f,
391 396 mat[3] * f, mat[4] * f, mat[5] * f,
392 397 mat[6] * f, mat[7] * f, mat[8] * f);
  @@ -413,23 +418,23 @@
413 418 mat[6] - m[6], mat[7] - m[7], mat[8] - m[8]);
414 419 }
415 420
416 - mat3 &operator*=(float f) { return *this = *this * f; }
421 + mat3 &operator*=(F32 f) { return *this = *this * f; }
417 422 mat3 &operator*=(const mat3 &m) { return *this = *this * m; }
418 423 mat3 &operator+=(const mat3 &m) { return *this = *this + m; }
419 424 mat3 &operator-=(const mat3 &m) { return *this = *this - m; }
420 425
421 - operator float*() { return mat; }
422 - operator const float*() const { return mat; }
426 + operator F32*() { return mat; }
427 + operator const F32*() const { return mat; }
423 428
424 - float &operator[](int i) { return mat[i]; }
425 - const float operator[](int i) const { return mat[i]; }
429 + F32 &operator[](I32 i) { return mat[i]; }
430 + const F32 operator[](I32 i) const { return mat[i]; }
426 431
427 432 mat3 transpose(void) const {
428 433 return mat3(mat[0], mat[3], mat[6],
429 434 mat[1], mat[4], mat[2],
430 435 mat[7], mat[5], mat[8]);
431 436 }
432 - float det(void) const {
437 + F32 det(void) const {
433 438 return ((mat[0] * mat[4] * mat[8]) +
434 439 (mat[3] * mat[7] * mat[2]) +
435 440 (mat[6] * mat[1] * mat[5]) -
  @@ -438,7 +443,7 @@
438 443 (mat[0] * mat[7] * mat[5]));
439 444 }
440 445 mat3 inverse(void) const {
441 - float idet = 1.0f / det();
446 + F32 idet = 1.0f / det();
442 447 return mat3((mat[4] * mat[8] - mat[7] * mat[5]) * idet,
443 448 -(mat[1] * mat[8] - mat[7] * mat[2]) * idet,
444 449 (mat[1] * mat[5] - mat[4] * mat[2]) * idet,
  @@ -460,55 +465,55 @@
460 465 mat[1] = 0.0; mat[4] = 1.0; mat[7] = 0.0;
461 466 mat[2] = 0.0; mat[5] = 0.0; mat[8] = 1.0;
462 467 }
463 - void rotate(const vec3 &v,float angle) {
468 + void rotate(const vec3 &v,F32 angle) {
464 469 rotate(v.x,v.y,v.z,angle);
465 470 }
466 - void rotate(float x,float y,float z,float angle) {
471 + void rotate(F32 x,F32 y,F32 z,F32 angle) {
467 472 DegToRad(angle);
468 - float c = (float)cos(angle);
469 - float s = (float)sin(angle);
470 - float l = sqrtf(x * x + y * y + z * z);
473 + F32 c = (F32)cos(angle);
474 + F32 s = (F32)sin(angle);
475 + F32 l = sqrtf(x * x + y * y + z * z);
471 476 if(l < EPSILON) l = 1.0f;
472 477 else l = 1.0f / l;
473 478 x *= l;
474 479 y *= l;
475 480 z *= l;
476 - float xy = x * y;
477 - float yz = y * z;
478 - float zx = z * x;
479 - float xs = x * s;
480 - float ys = y * s;
481 - float zs = z * s;
482 - float c1 = 1.0f - c;
481 + F32 xy = x * y;
482 + F32 yz = y * z;
483 + F32 zx = z * x;
484 + F32 xs = x * s;
485 + F32 ys = y * s;
486 + F32 zs = z * s;
487 + F32 c1 = 1.0f - c;
483 488 mat[0] = c1 * x * x + c; mat[3] = c1 * xy - zs; mat[6] = c1 * zx + ys;
484 489 mat[1] = c1 * xy + zs; mat[4] = c1 * y * y + c; mat[7] = c1 * yz - xs;
485 490 mat[2] = c1 * zx - ys; mat[5] = c1 * yz + xs; mat[8] = c1 * z * z + c;
486 491 }
487 - void rotate_x(float angle) {
492 + void rotate_x(F32 angle) {
488 493 DegToRad(angle);
489 - float c = (float)cos(angle);
490 - float s = (float)sin(angle);
494 + F32 c = (F32)cos(angle);
495 + F32 s = (F32)sin(angle);
491 496 mat[0] = 1.0; mat[3] = 0.0; mat[6] = 0.0;
492 497 mat[1] = 0.0; mat[4] = c; mat[7] = -s;
493 498 mat[2] = 0.0; mat[5] = s; mat[8] = c;
494 499 }
495 - void rotate_y(float angle) {
500 + void rotate_y(F32 angle) {
496 501 DegToRad(angle);
497 - float c = (float)cos(angle);
498 - float s = (float)sin(angle);
502 + F32 c = (F32)cos(angle);
503 + F32 s = (F32)sin(angle);
499 504 mat[0] = c; mat[3] = 0.0; mat[6] = s;
500 505 mat[1] = 0.0; mat[4] = 1.0; mat[7] = 0.0;
501 506 mat[2] = -s; mat[5] = 0.0; mat[8] = c;
502 507 }
503 - void rotate_z(float angle) {
508 + void rotate_z(F32 angle) {
504 509 DegToRad(angle);
505 - float c = (float)cos(angle);
506 - float s = (float)sin(angle);
510 + F32 c = (F32)cos(angle);
511 + F32 s = (F32)sin(angle);
507 512 mat[0] = c; mat[3] = -s; mat[6] = 0.0;
508 513 mat[1] = s; mat[4] = c; mat[7] = 0.0;
509 514 mat[2] = 0.0; mat[5] = 0.0; mat[8] = 1.0;
510 515 }
511 - void scale(float x,float y,float z) {
516 + void scale(F32 x,F32 y,F32 z) {
512 517 mat[0] = x; mat[3] = 0; mat[6] = 0;
513 518 mat[1] = 0; mat[4] = y; mat[7] = 0;
514 519 mat[2] = 0; mat[5] = 0; mat[8] = z;
  @@ -530,7 +535,7 @@
530 535 mat[2] = x.z; mat[5] = y.z; mat[8] = z.z;
531 536 }
532 537
533 - float mat[9];
538 + F32 mat[9];
534 539 };
535 540
536 541 /*****************************************************************************/
  @@ -547,10 +552,10 @@
547 552 this->mat[2] = 0.0; this->mat[6] = 0.0; this->mat[10] = 1.0; this->mat[14] = 0.0;
548 553 this->mat[3] = 0.0; this->mat[7] = 0.0; this->mat[11] = 0.0; this->mat[15] = 1.0;
549 554 }
550 - mat4(float m0, float m1, float m2, float m3,
551 - float m4, float m5, float m6, float m7,
552 - float m8, float m9, float m10,float m11,
553 - float m12,float m13,float m14,float m15) {
555 + mat4(F32 m0, F32 m1, F32 m2, F32 m3,
556 + F32 m4, F32 m5, F32 m6, F32 m7,
557 + F32 m8, F32 m9, F32 m10,F32 m11,
558 + F32 m12,F32 m13,F32 m14,F32 m15) {
554 559 this->mat[0] = m0; this->mat[4] = m4; this->mat[8] = m8; this->mat[12] = m12;
555 560 this->mat[1] = m1; this->mat[5] = m5; this->mat[9] = m9; this->mat[13] = m13;
556 561 this->mat[2] = m2; this->mat[6] = m6; this->mat[10] = m10; this->mat[14] = m14;
  @@ -559,13 +564,13 @@
559 564 mat4(const vec3 &v) {
560 565 translate(v);
561 566 }
562 - mat4(float x,float y,float z) {
567 + mat4(F32 x,F32 y,F32 z) {
563 568 translate(x,y,z);
564 569 }
565 - mat4(const vec3 &axis,float angle) {
570 + mat4(const vec3 &axis,F32 angle) {
566 571 rotate(axis,angle);
567 572 }
568 - mat4(float x,float y,float z,float angle) {
573 + mat4(F32 x,F32 y,F32 z,F32 angle) {
569 574 rotate(x,y,z,angle);
570 575 }
571 576 mat4(const mat3 &m) {
  @@ -574,7 +579,7 @@
574 579 this->mat[2] = m[2]; this->mat[6] = m[5]; this->mat[10] = m[8]; this->mat[14] = 0.0;
575 580 this->mat[3] = 0.0; this->mat[7] = 0.0; this->mat[11] = 0.0; this->mat[15] = 1.0;
576 581 }
577 - mat4(const float *m) {
582 + mat4(const F32 *m) {
578 583 this->mat[0] = m[0]; this->mat[4] = m[4]; this->mat[8] = m[8]; this->mat[12] = m[12];
579 584 this->mat[1] = m[1]; this->mat[5] = m[5]; this->mat[9] = m[9]; this->mat[13] = m[13];
580 585 this->mat[2] = m[2]; this->mat[6] = m[6]; this->mat[10] = m[10]; this->mat[14] = m[14];
  @@ -598,7 +603,7 @@
598 603 this->mat[2] * v[0] + this->mat[6] * v[1] + this->mat[10] * v[2] + this->mat[14] * v[3],
599 604 this->mat[3] * v[0] + this->mat[7] * v[1] + this->mat[11] * v[2] + this->mat[15] * v[3]);
600 605 }
601 - mat4 operator*(float f) const {
606 + mat4 operator*(F32 f) const {
602 607 return mat4(this->mat[0] * f, this->mat[1] * f, this->mat[2] * f, this->mat[3] * f,
603 608 this->mat[4] * f, this->mat[5] * f, this->mat[6] * f, this->mat[7] * f,
604 609 this->mat[8] * f, this->mat[9] * f, this->mat[10] * f, this->mat[11] * f,
  @@ -635,16 +640,16 @@
635 640 this->mat[12] - m[12], this->mat[13] - m[13], this->mat[14] - m[14], this->mat[15] - m[15]);
636 641 }
637 642
638 - mat4 &operator*=(float f) { return *this = *this * f; }
643 + mat4 &operator*=(F32 f) { return *this = *this * f; }
639 644 mat4 &operator*=(const mat4 &m) { return *this = *this * m; }
640 645 mat4 &operator+=(const mat4 &m) { return *this = *this + m; }
641 646 mat4 &operator-=(const mat4 &m) { return *this = *this - m; }
642 647
643 - operator float*() { return this->mat; }
644 - operator const float*() const { return this->mat; }
648 + operator F32*() { return this->mat; }
649 + operator const F32*() const { return this->mat; }
645 650
646 - float &operator[](int i) { return this->mat[i]; }
647 - const float operator[](int i) const { return this->mat[i]; }
651 + F32 &operator[](I32 i) { return this->mat[i]; }
652 + const F32 operator[](I32 i) const { return this->mat[i]; }
648 653
649 654 mat4 rotation(void) const {
650 655 return mat4(this->mat[0], this->mat[1], this->mat[2], 0,
  @@ -665,7 +670,7 @@
665 670 this->mat[12], this->mat[13], this->mat[14], this->mat[15]);
666 671 }
667 672
668 - float det(void) const {
673 + F32 det(void) const {
669 674 return ((this->mat[0] * this->mat[5] * this->mat[10]) +
670 675 (this->mat[4] * this->mat[9] * this->mat[2]) +
671 676 (this->mat[8] * this->mat[1] * this->mat[6]) -
  @@ -676,7 +681,7 @@
676 681
677 682 void inverse(mat4& ret) {
678 683 // mat4 *ret = new mat4();
679 - float idet = 1.0f / det();
684 + F32 idet = 1.0f / det();
680 685 ret[0] = (this->mat[5] * this->mat[10] - this->mat[9] * this->mat[6]) * idet;
681 686 ret[1] = -(this->mat[1] * this->mat[10] - this->mat[9] * this->mat[2]) * idet;
682 687 ret[2] = (this->mat[1] * this->mat[6] - this->mat[5] * this->mat[2]) * idet;
  @@ -697,9 +702,9 @@
697 702 }
698 703 /*
699 704 // MATINVERSE BY FRANKOI
700 - void mat_inverse (float *in, float *out)
705 + void mat_inverse (F32 *in, F32 *out)
701 706 {
702 - float det, oneOverDet;
707 + F32 det, oneOverDet;
703 708
704 709 det = in[0] * ((in[5] * in[10]) - (in[6] * in[9]))
705 710 + in[1] * ((in[6] * in[8]) - (in[4] * in[10]))
  @@ -740,51 +745,51 @@
740 745 this->mat[2] = 0.0; this->mat[6] = 0.0; this->mat[10] = 1.0; this->mat[14] = 0.0;
741 746 this->mat[3] = 0.0; this->mat[7] = 0.0; this->mat[11] = 0.0; this->mat[15] = 1.0;
742 747 }
743 - void rotate(const vec3 &axis,float angle) {
748 + void rotate(const vec3 &axis,F32 angle) {
744 749 DegToRad(angle);
745 - float c = (float)cos(angle);
746 - float s = (float)sin(angle);
750 + F32 c = (F32)cos(angle);
751 + F32 s = (F32)sin(angle);
747 752 vec3 v = axis;
748 753 v.normalize();
749 - float xx = v.x * v.x;
750 - float yy = v.y * v.y;
751 - float zz = v.z * v.z;
752 - float xy = v.x * v.y;
753 - float yz = v.y * v.z;
754 - float zx = v.z * v.x;
755 - float xs = v.x * s;
756 - float ys = v.y * s;
757 - float zs = v.z * s;
754 + F32 xx = v.x * v.x;
755 + F32 yy = v.y * v.y;
756 + F32 zz = v.z * v.z;
757 + F32 xy = v.x * v.y;
758 + F32 yz = v.y * v.z;
759 + F32 zx = v.z * v.x;
760 + F32 xs = v.x * s;
761 + F32 ys = v.y * s;
762 + F32 zs = v.z * s;
758 763 this->mat[0] = (1.0f - c) * xx + c; this->mat[4] = (1.0f - c) * xy - zs; this->mat[8] = (1.0f - c) * zx + ys; this->mat[12] = 0.0;
759 764 this->mat[1] = (1.0f - c) * xy + zs; this->mat[5] = (1.0f - c) * yy + c; this->mat[9] = (1.0f - c) * yz - xs; this->mat[13] = 0.0;
760 765 this->mat[2] = (1.0f - c) * zx - ys; this->mat[6] = (1.0f - c) * yz + xs; this->mat[10] = (1.0f - c) * zz + c; this->mat[14] = 0.0;
761 766 this->mat[3] = 0.0; this->mat[7] = 0.0; this->mat[11] = 0.0; this->mat[15] = 1.0;
762 767 }
763 - void rotate(float x,float y,float z,float angle) {
768 + void rotate(F32 x,F32 y,F32 z,F32 angle) {
764 769 rotate(vec3(x,y,z),angle);
765 770 }
766 - void rotate_x(float angle) {
771 + void rotate_x(F32 angle) {
767 772 DegToRad(angle);
768 - float c = (float)cos(angle);
769 - float s = (float)sin(angle);
773 + F32 c = (F32)cos(angle);
774 + F32 s = (F32)sin(angle);
770 775 this->mat[0] = 1.0; this->mat[4] = 0.0; this->mat[8] = 0.0; this->mat[12] = 0.0;
771 776 this->mat[1] = 0.0; this->mat[5] = c; this->mat[9] = -s; this->mat[13] = 0.0;
772 777 this->mat[2] = 0.0; this->mat[6] = s; this->mat[10] = c; this->mat[14] = 0.0;
773 778 this->mat[3] = 0.0; this->mat[7] = 0.0; this->mat[11] = 0.0; this->mat[15] = 1.0;
774 779 }
775 - void rotate_y(float angle) {
780 + void rotate_y(F32 angle) {
776 781 DegToRad(angle);
777 - float c = (float)cos(angle);
778 - float s = (float)sin(angle);
782 + F32 c = (F32)cos(angle);
783 + F32 s = (F32)sin(angle);
779 784 this->mat[0] = c; this->mat[4] = 0.0; this->mat[8] = s; this->mat[12] = 0.0;
780 785 this->mat[1] = 0.0; this->mat[5] = 1.0; this->mat[9] = 0.0; this->mat[13] = 0.0;
781 786 this->mat[2] = -s; this->mat[6] = 0.0; this->mat[10] = c; this->mat[14] = 0.0;
782 787 this->mat[3] = 0.0; this->mat[7] = 0.0; this->mat[11] = 0.0; this->mat[15] = 1.0;
783 788 }
784 - void rotate_z(float angle) {
789 + void rotate_z(F32 angle) {
785 790 DegToRad(angle);
786 - float c = (float)cos(angle);
787 - float s = (float)sin(angle);
791 + F32 c = (F32)cos(angle);
792 + F32 s = (F32)sin(angle);
788 793 this->mat[0] = c; this->mat[4] = -s; this->mat[8] = 0.0; this->mat[12] = 0.0;
789 794 this->mat[1] = s; this->mat[5] = c; this->mat[9] = 0.0; this->mat[13] = 0.0;
790 795 this->mat[2] = 0.0; this->mat[6] = 0.0; this->mat[10] = 1.0; this->mat[14] = 0.0;
  @@ -796,7 +801,7 @@
796 801 this->mat[2] = 0.0; this->mat[6] = 0.0; this->mat[10] = v.z; this->mat[14] = 0.0;
797 802 this->mat[3] = 0.0; this->mat[7] = 0.0; this->mat[11] = 0.0; this->mat[15] = 1.0;
798 803 }
799 - void scale(float x,float y,float z) {
804 + void scale(F32 x,F32 y,F32 z) {
800 805 scale(vec3(x,y,z));
801 806 }
802 807 void translate(const vec3 &v) {
  @@ -805,28 +810,28 @@
805 810 this->mat[2] = 0.0; this->mat[6] = 0.0; this->mat[10] = 1.0; this->mat[14] = v.z;
806 811 this->mat[3] = 0.0; this->mat[7] = 0.0; this->mat[11] = 0.0; this->mat[15] = 1.0;
807 812 }
808 - void translate(float x,float y,float z) {
813 + void translate(F32 x,F32 y,F32 z) {
809 814 translate(vec3(x,y,z));
810 815 }
811 816 void reflect(const vec4 &plane) {
812 - float x = plane.x;
813 - float y = plane.y;
814 - float z = plane.z;
815 - float x2 = x * 2.0f;
816 - float y2 = y * 2.0f;
817 - float z2 = z * 2.0f;
817 + F32 x = plane.x;
818 + F32 y = plane.y;
819 + F32 z = plane.z;
820 + F32 x2 = x * 2.0f;
821 + F32 y2 = y * 2.0f;
822 + F32 z2 = z * 2.0f;
818 823 this->mat[0] = 1.0f - x * x2; this->mat[4] = -y * x2; this->mat[8] = -z * x2; this->mat[12] = -plane.w * x2;
819 824 this->mat[1] = -x * y2; this->mat[5] = 1.0f - y * y2; this->mat[9] = -z * y2; this->mat[13] = -plane.w * y2;
820 825 this->mat[2] = -x * z2; this->mat[6] = -y * z2; this->mat[10] = 1.0f - z * z2; this->mat[14] = -plane.w * z2;
821 826 this->mat[3] = 0.0; this->mat[7] = 0.0; this->mat[11] = 0.0; this->mat[15] = 1.0;
822 827 }
823 - void reflect(float x,float y,float z,float w) {
828 + void reflect(F32 x,F32 y,F32 z,F32 w) {
824 829 reflect(vec4(x,y,z,w));
825 830 }
826 831
827 - void perspective(float fov,float aspect,float znear,float zfar) {
828 - float y = (float)tan(fov * M_PI / 360.0f);
829 - float x = y * aspect;
832 + void perspective(F32 fov,F32 aspect,F32 znear,F32 zfar) {
833 + F32 y = (F32)tan(fov * M_PI / 360.0f);
834 + F32 x = y * aspect;
830 835 this->mat[0] = 1.0f / x; this->mat[4] = 0.0; this->mat[8] = 0.0; this->mat[12] = 0.0;
831 836 this->mat[1] = 0.0; this->mat[5] = 1.0f / y; this->mat[9] = 0.0; this->mat[13] = 0.0;
832 837 this->mat[2] = 0.0; this->mat[6] = 0.0; this->mat[10] = -(zfar + znear) / (zfar - znear); this->mat[14] = -(2.0f * zfar * znear) / (zfar - znear);
  @@ -848,11 +853,11 @@
848 853 m1.translate(-eye);
849 854 *this = m0 * m1;
850 855 }
851 - void look_at(const float *eye,const float *dir,const float *up) {
856 + void look_at(const F32 *eye,const F32 *dir,const F32 *up) {
852 857 look_at(vec3(eye),vec3(dir),vec3(up));
853 858 }
854 859
855 - float mat[16];
860 + F32 mat[16];
856 861 };
857 862
858 863 inline mat3::mat3(const mat4 &m) {
  @@ -861,287 +866,4 @@
861 866 this->mat[2] = m[2]; this->mat[5] = m[6]; this->mat[8] = m[10];
862 867 }
863 868
864 - /*****************************************************************************/
865 - /* */
866 - /* quat */
867 - /* */
868 - /*****************************************************************************/
869 -
870 - class quat {
871 - public:
872 - quat(void) : x(0), y(0), z(0), w(1) { }
873 - quat(const vec3 &dir,float angle) {
874 - set(dir,angle);
875 - }
876 - quat(float _x,float _y,float _z,float angle) {
877 - set(_x,_y,_z,angle);
878 - }
879 - quat(const mat3 &m) {
880 - float trace = m[0] + m[4] + m[8];
881 - if(trace > 0.0) {
882 - float s = sqrtf(trace + 1.0f);
883 - this->q[3] = 0.5f * s;
884 - s = 0.5f / s;
885 - this->q[0] = (m[5] - m[7]) * s;
886 - this->q[1] = (m[6] - m[2]) * s;
887 - this->q[2] = (m[1] - m[3]) * s;
888 - } else {
889 - static int next[3] = { 1, 2, 0 };
890 - int i = 0;
891 - if(m[4] > m[0]) i = 1;
892 - if(m[8] > m[3 * i + i]) i = 2;
893 - int j = next[i];
894 - int k = next[j];
895 - float s = sqrtf(m[3 * i + i] - m[3 * j + j] - m[3 * k + k] + 1.0f);
896 - this->q[i] = 0.5f * s;
897 - if(s != 0) s = 0.5f / s;
898 - this->q[3] = (m[3 * j + k] - m[3 * k + j]) * s;
899 - this->q[j] = (m[3 * i + j] + m[3 * j + i]) * s;
900 - this->q[k] = (m[3 * i + k] + m[3 * k + i]) * s;
901 - }
902 - }
903 - quat& operator*(const quat &q) {
904 - quat *ret = new quat();
905 - ret->x = w * q.x + x * q.x + y * q.z - z * q.y;
906 - ret->y = w * q.y + y * q.w + z * q.x - x * q.z;
907 - ret->z = w * q.z + z * q.w + x * q.y - y * q.x;
908 - ret->w = w * q.w - x * q.x - y * q.y - z * q.z;
909 - return *ret;
910 - }
911 - void set(const vec3 &dir,float angle) {
912 - float l = dir.length();
913 - if(l != 0.0) {
914 - l = 1.0f / l;
915 - DegToRad(angle);
916 - l *= (float)sin(angle * 0.5f);
917 - this->x = dir[0] * l;
918 - this->y = dir[1] * l;
919 - this->z = dir[2] * l;
920 - this->w = (float)cos(angle * 0.5f);
921 - } else {
922 - this->x = this->y = this->z = 0.0;
923 - this->w = 1.0;
924 - }
925 - }
926 - void set(float _x,float _y,float _z,float angle) {
927 - set(vec3(_x,_y,_z),angle);
928 - }
929 - void reset(void) { this->x = this->y = this->z = 0; this->w = 1; }
930 - void slerp(const quat &q0,const quat &q1,float t) {
931 - float k0,k1,cosomega = q0.x * q1.x + q0.y * q1.y + q0.z * q1.z + q0.w * q1.w;
932 - quat q;
933 - if(cosomega < 0.0) {
934 - cosomega = -cosomega;
935 - q.x = -q1.x;
936 - q.y = -q1.y;
937 - q.z = -q1.z;
938 - q.w = -q1.w;
939 - } else {
940 - q.x = q1.x;
941 - q.y = q1.y;
942 - q.z = q1.z;
943 - q.w = q1.w;
944 - }
945 - if(1.0 - cosomega > 1e-6) {
946 - float omega = (float)acos(cosomega);
947 - float sinomega = (float)sin(omega);
948 - k0 = (float)sin((1.0f - t) * omega) / sinomega;
949 - k1 = (float)sin(t * omega) / sinomega;
950 - } else {
951 - k0 = 1.0f - t;
952 - k1 = t;
953 - }
954 - this->x = q0.x * k0 + q.x * k1;
955 - this->y = q0.y * k0 + q.y * k1;
956 - this->z = q0.z * k0 + q.z * k1;
957 - this->w = q0.w * k0 + q.w * k1;
958 - }
959 -
960 - mat3 to_matrix(void) const {
961 - float x2 = this->x + this->x;
962 - float y2 = this->y + this->y;
963 - float z2 = this->z + this->z;
964 - float xx = this->x * x2;
965 - float yy = this->y * y2;
966 - float zz = this->z * z2;
967 - float xy = this->x * y2;
968 - float yz = this->y * z2;
969 - float xz = this->z * x2;
970 - float wx = this->w * x2;
971 - float wy = this->w * y2;
972 - float wz = this->w * z2;
973 - return mat3(1.0f - (yy + zz), xy + wz, xz - wy,
974 - xy - wz, 1.0f - (xx + zz), yz + wx,
975 - xz + wy, yz - wx, 1.0f - (xx + yy));
976 - }
977 -
978 - operator float*() { return this->q; }
979 - operator const float*() const { return this->q; }
980 - // float &operator[](int _i) { return this->q[_i]; }
981 - // const float &operator[](int _i) const { return this->q[_i]; }
982 -
983 - union {
984 - struct {float x,y,z,w;};
985 - float q[4];
986 - };
987 - };
988 -
989 - /*****************************************************************************/
990 - /* */
991 - /* ivec2 */
992 - /* */
993 - /*****************************************************************************/
994 -
995 - class ivec2 {
996 - public:
997 - ivec2(void) : a(0), b(0) { }
998 - ivec2(long _a,long _b) : a(_a), b(_b) { }
999 - ivec2(const long *iv) : a(iv[0]), b(iv[1]) { }
1000 - ivec2(const ivec2 &iv) : a(iv.a), b(iv.b) { }
1001 -
1002 - int operator==(const ivec2 &iv) { return ((this->a == iv.a) && (this->b == iv.b)); }
1003 - int operator!=(const ivec2 &iv) { return !(*this == iv); }
1004 -
1005 - ivec2 &operator=(long _i) { this->x=_i; this->y=_i; return (*this); }
1006 - const ivec2 operator*(long _i) const { return ivec2(this->a * _i,this->b * _i); }
1007 - const ivec2 operator/(long _i) const { return ivec2(this->a / _i,this->b / _i); }
1008 - const ivec2 operator+(const ivec2 &iv) const { return ivec2(this->a + iv.a,this->b + iv.b); }
1009 - const ivec2 operator-() const { return ivec2(-this->a,-this->b); }
1010 - const ivec2 operator-(const ivec2 &iv) const { return ivec2(this->a - iv.a,this->b - iv.b); }
1011 -
1012 - ivec2 &operator*=(long _i) { return *this = *this * _i; }
1013 - ivec2 &operator/=(long _i) { return *this = *this / _i; }
1014 - ivec2 &operator+=(const ivec2 &iv) { return *this = *this + iv; }
1015 - ivec2 &operator-=(const ivec2 &iv) { return *this = *this - iv; }
1016 -
1017 - long operator*(const ivec2 &iv) const { return this->a * iv.a + this->b * iv.b; }
1018 -
1019 - operator long*() { return this->i; }
1020 - operator const long*() const { return this->i; }
1021 - // long &operator[](int _i) { return this->i[_i]; }
1022 - // const long &operator[](int _i) const { return this->i[_i]; }
1023 -
1024 - void set(long _a,long _b) { this->a = _a; this->b = _b; }
1025 - void reset(void) { this->a = this->b = 0; }
1026 - void swap(ivec2 &iv) { long tmp=a; a=iv.a; iv.a=tmp; tmp=b; b=iv.b; iv.b=tmp; }
1027 - void swap(ivec2 *iv) { this->swap(*iv); }
1028 -
1029 - union {
1030 - struct {long a,b;};
1031 - struct {long x,y;};
1032 - long i[2];
1033 - };
1034 - };
1035 -
1036 - /*****************************************************************************/
1037 - /* */
1038 - /* ivec3 */
1039 - /* */
1040 - /*****************************************************************************/
1041 -
1042 - class ivec3 {
1043 - public:
1044 - ivec3(void) : a(0), b(0), c(0) { }
1045 - ivec3(long _a,long _b,long _c) : a(_a), b(_b), c(_c) { }
1046 - ivec3(const long *iv) : a(iv[0]), b(iv[1]), c(iv[2]) { }
1047 - ivec3(const ivec3 &iv) : a(iv.a), b(iv.b), c(iv.c) { }
1048 - ivec3(const ivec4 &iv);
1049 -
1050 - int operator==(const ivec3 &iv) { return ((this->a == iv.a) && (this->b == iv.b) && (this->c == iv.c)); }
1051 - int operator!=(const ivec3 &iv) { return !(*this == iv); }
1052 -
1053 - ivec3 &operator=(long _i) { this->x=_i; this->y=_i; this->z=_i; return (*this); }
1054 - const ivec3 operator*(long _i) const { return ivec3(this->a * _i,this->b * _i,this->c * _i); }
1055 - const ivec3 operator/(long _i) const { return ivec3(this->a / _i,this->b / _i,this->c / _i); }
1056 - const ivec3 operator+(const ivec3 &iv) const { return ivec3(this->a + iv.a,this->b + iv.b,this->c + iv.c); }
1057 - const ivec3 operator-() const { return ivec3(-this->a,-this->b,-this->c); }
1058 - const ivec3 operator-(const ivec3 &iv) const { return ivec3(this->a - iv.a,this->b - iv.b,this->c - iv.c); }
1059 -
1060 - ivec3 &operator*=(long _i) { return *this = *this * _i; }
1061 - ivec3 &operator/=(long _i) { return *this = *this / _i; }
1062 - ivec3 &operator+=(const ivec3 &iv) { return *this = *this + iv; }
1063 - ivec3 &operator-=(const ivec3 &iv) { return *this = *this - iv; }
1064 -
1065 - long operator*(const ivec3 &iv) const { return this->a * iv.a + this->b * iv.b + this->c * iv.c; }
1066 - long operator*(const ivec4 &iv) const;
1067 -
1068 - operator long*() { return this->i; }
1069 - operator const long*() const { return this->i; }
1070 - // long &operator[](int _i) { return this->i[_i]; }
1071 - // const long &operator[](int _i) const { return this->i[_i]; }
1072 -
1073 - void set(long _a,long _b,long _c) { this->a = _a; this->b = _b; this->c = _c; }
1074 - void reset(void) { this->a = this->b = this->c = 0; }
1075 - void swap(ivec3 &iv) { long tmp=a; a=iv.a; iv.a=tmp; tmp=b; b=iv.b; iv.b=tmp; tmp=c; c=iv.c; iv.c=tmp; }
1076 - void swap(ivec3 *iv) { this->swap(*iv); }
1077 -
1078 - union {
1079 - struct {long a,b,c;};
1080 - struct {long x,y,z;};
1081 - struct {long red,green,blue;};
1082 - long i[3];
1083 - };
1084 - };
1085 -
1086 - /*****************************************************************************/
1087 - /* */
1088 - /* ivec4 */
1089 - /* */
1090 - /*****************************************************************************/
1091 -
1092 - class ivec4 {
1093 - public:
1094 - ivec4(void) : a(0), b(0), c(0), d(1) { }
1095 - ivec4(long _a,long _b,long _c,long _d) : a(_a), b(_b), c(_c), d(_d) { }
1096 - ivec4(const long *iv) : a(iv[0]), b(iv[1]), c(iv[2]), d(iv[3]) { }
1097 - ivec4(const ivec3 &iv) : a(iv.a), b(iv.b), c(iv.c), d(1) { }
1098 - ivec4(const ivec3 &iv,long _d) : a(iv.a), b(iv.b), c(iv.c), d(_d) { }
1099 - ivec4(const ivec4 &iv) : a(iv.a), b(iv.b), c(iv.c), d(iv.d) { }
1100 -
1101 - int operator==(const ivec4 &iv) { return ((this->a == iv.a) && (this->b == iv.b) && (this->c == iv.c) && (this->d == iv.d)); }
1102 - int operator!=(const ivec4 &iv) { return !(*this == iv); }
1103 -
1104 - ivec4 &operator=(long _i) { this->x=_i; this->y=_i; this->z=_i; this->w=_i; return (*this); }
1105 - const ivec4 operator*(long _i) const { return ivec4(this->a * _i,this->b * _i,this->c * _i,this->d * _i); }
1106 - const ivec4 operator/(long _i) const { return ivec4(this->a / _i,this->b / _i,this->c / _i,this->d / _i); }
1107 - const ivec4 operator+(const ivec4 &iv) const { return ivec4(this->a + iv.a,this->b + iv.b,this->c + iv.c,this->d + iv.d); }
1108 - const ivec4 operator-() const { return ivec4(-this->a,-this->b,-this->c,-this->d); }
1109 - const ivec4 operator-(const ivec4 &iv) const { return ivec4(this->a - iv.a,this->b - iv.b,this->c - iv.c,this->d - iv.d); }
1110 -
1111 - ivec4 &operator*=(long _i) { return *this = *this * _i; }
1112 - ivec4 &operator/=(long _i) { return *this = *this / _i; }
1113 - ivec4 &operator+=(const ivec4 &iv) { return *this = *this + iv; }
1114 - ivec4 &operator-=(const ivec4 &iv) { return *this = *this - iv; }
1115 -
1116 - long operator*(const ivec3 &iv) const { return this->a * iv.a + this->b * iv.b + this->c * iv.c + this->d; }
1117 - long operator*(const ivec4 &iv) const { return this->a * iv.a + this->b * iv.b + this->c * iv.c + this->d * iv.d; }
1118 -
1119 - operator long*() { return this->i; }
1120 - operator const long*() const { return this->i; }
1121 - // long &operator[](int _i) { return this->i[_i]; }
1122 - // const long &operator[](int _i) const { return this->i[_i]; }
1123 -
1124 - void set(long _a,long _b,long _c,long _d) { this->a = _a; this->b = _b; this->c = _c; this->d = _d; }
1125 - void reset(void) { this->a = this->b = this->c = this->d = 0; }
1126 - void swap(ivec4 &iv) { long tmp=a; a=iv.a; iv.a=tmp; tmp=b; b=iv.b; iv.b=tmp; tmp=c; c=iv.c; iv.c=tmp; tmp=d; d=iv.d; iv.d=tmp; }
1127 - void swap(ivec4 *iv) { this->swap(*iv); }
1128 -
1129 - union {
1130 - struct {long a,b,c,d;};
1131 - struct {long x,y,z,w;};
1132 - struct {long red,green,blue,alpha;};
1133 - long i[4];
1134 - };
1135 - };
1136 -
1137 - inline ivec3::ivec3(const ivec4 &iv) {
1138 - this->a = iv.a;
1139 - this->b = iv.b;
1140 - this->c = iv.c;
1141 - }
1142 -
1143 - inline long ivec3::operator*(const ivec4 &iv) const {
1144 - return this->a * iv.a + this->b * iv.b + this->c * iv.c + iv.d;
1145 - }
1146 -
1147 869 #endif