MaxstARSDK
vecmath.h
Go to the documentation of this file.
1 /*==============================================================================
2 Copyright 2017 Maxst, Inc. All Rights Reserved.
3 ==============================================================================*/
4 
5 
6 /*
7 * Copyright 2013 The Android Open Source Project
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21 
22 #ifndef VECMATH_H_
23 #define VECMATH_H_
24 
25 #include <math.h>
26 #include <stdio.h>
27 
28 #define PI 3.1415926535897932384626433832795f
29 #define TO_DEGREE 57.2958
30 
31 namespace gl_helper
32 {
33  /******************************************************************
34  * Helper class for vector math operations
35  * Currently all implementations are in pure C++.
36  * Each class is an opaque class so caller does not have a direct access
37  * to each element. This is for an ease of future optimization to use vector operations.
38  *
39  */
40 
41  class Vec2;
42  class Vec3;
43  class Vec4;
44  class Mat4;
45 
46  /******************************************************************
47  * 2 elements vector class
48  *
49  */
50  class Vec2
51  {
52  public:
53  float x_;
54  float y_;
55 
56  public:
57  friend class Vec3;
58  friend class Vec4;
59  friend class Mat4;
60  friend class Quaternion;
61 
62  Vec2()
63  {
64  x_ = y_ = 0.f;
65  }
66 
67  Vec2(const float fX, const float fY)
68  {
69  x_ = fX;
70  y_ = fY;
71  }
72 
73  Vec2(const Vec2& vec)
74  {
75  x_ = vec.x_;
76  y_ = vec.y_;
77  }
78 
79  Vec2(const float* pVec)
80  {
81  x_ = (*pVec++);
82  y_ = (*pVec++);
83  }
84 
85  //Operators
86  Vec2 operator*(const Vec2& rhs) const
87  {
88  Vec2 ret;
89  ret.x_ = x_ * rhs.x_;
90  ret.y_ = y_ * rhs.y_;
91  return ret;
92  }
93 
94  Vec2 operator/(const Vec2& rhs) const
95  {
96  Vec2 ret;
97  ret.x_ = x_ / rhs.x_;
98  ret.y_ = y_ / rhs.y_;
99  return ret;
100  }
101 
102  Vec2 operator+(const Vec2& rhs) const
103  {
104  Vec2 ret;
105  ret.x_ = x_ + rhs.x_;
106  ret.y_ = y_ + rhs.y_;
107  return ret;
108  }
109 
110  Vec2 operator-(const Vec2& rhs) const
111  {
112  Vec2 ret;
113  ret.x_ = x_ - rhs.x_;
114  ret.y_ = y_ - rhs.y_;
115  return ret;
116  }
117 
118  Vec2& operator+=(const Vec2& rhs)
119  {
120  x_ += rhs.x_;
121  y_ += rhs.y_;
122  return *this;
123  }
124 
125  Vec2& operator-=(const Vec2& rhs)
126  {
127  x_ -= rhs.x_;
128  y_ -= rhs.y_;
129  return *this;
130  }
131 
132  Vec2& operator*=(const Vec2& rhs)
133  {
134  x_ *= rhs.x_;
135  y_ *= rhs.y_;
136  return *this;
137  }
138 
139  Vec2& operator/=(const Vec2& rhs)
140  {
141  x_ /= rhs.x_;
142  y_ /= rhs.y_;
143  return *this;
144  }
145 
146  //External operators
147  friend Vec2 operator-(const Vec2& rhs)
148  {
149  return Vec2(rhs) *= -1;
150  }
151 
152  friend Vec2 operator*(const float lhs, const Vec2& rhs)
153  {
154  Vec2 ret;
155  ret.x_ = lhs * rhs.x_;
156  ret.y_ = lhs * rhs.y_;
157  return ret;
158  }
159 
160  friend Vec2 operator/(const float lhs, const Vec2& rhs)
161  {
162  Vec2 ret;
163  ret.x_ = lhs / rhs.x_;
164  ret.y_ = lhs / rhs.y_;
165  return ret;
166  }
167 
168  // compare for order.
169  bool operator <(const Vec2& v) const
170  {
171  return (x_ < v.x_) || ((!(v.x_ < x_)) && (y_ < v.y_));
172  }
173 
174  //Operators with float
175  Vec2 operator*(const float& rhs) const
176  {
177  Vec2 ret;
178  ret.x_ = x_ * rhs;
179  ret.y_ = y_ * rhs;
180  return ret;
181  }
182 
183  Vec2& operator*=(const float& rhs)
184  {
185  x_ = x_ * rhs;
186  y_ = y_ * rhs;
187  return *this;
188  }
189 
190  Vec2 operator/(const float& rhs) const
191  {
192  Vec2 ret;
193  ret.x_ = x_ / rhs;
194  ret.y_ = y_ / rhs;
195  return ret;
196  }
197 
198  Vec2& operator/=(const float& rhs)
199  {
200  x_ = x_ / rhs;
201  y_ = y_ / rhs;
202  return *this;
203  }
204 
205  //Compare
206  bool operator==(const Vec2& rhs) const
207  {
208  if (x_ != rhs.x_ || y_ != rhs.y_)
209  return false;
210  return true;
211  }
212 
213  bool operator!=(const Vec2& rhs) const
214  {
215  if (x_ == rhs.x_)
216  return false;
217 
218  return true;
219  }
220 
221  float Length() const
222  {
223  return sqrtf(x_ * x_ + y_ * y_);
224  }
225 
227  {
228  float len = Length();
229  x_ = x_ / len;
230  y_ = y_ / len;
231  return *this;
232  }
233 
234  float Dot(const Vec2& rhs)
235  {
236  return x_ * rhs.x_ + y_ * rhs.y_;
237  }
238 
239  float Distance(const Vec2& rhs)
240  {
241  return sqrtf(((x_ - rhs.x_) * (x_ - rhs.x_)) + ((y_ - rhs.y_) * (y_ - rhs.y_)));
242  }
243 
244  bool Validate()
245  {
246  if (isnan(x_) || isnan(y_))
247  return false;
248  return true;
249  }
250 
251  void Value(float& fX, float& fY)
252  {
253  fX = x_;
254  fY = y_;
255  }
256 
257  void Dump()
258  {
259  printf("Vec2 %f %f", x_, y_);
260  }
261  };
262 
263  /******************************************************************
264  * 3 elements vector class
265  *
266  */
267  class Vec3
268  {
269  public:
270  friend class Vec4;
271  friend class Mat3;
272  friend class Mat4;
273  friend class Quaternion;
274 
275  float x_, y_, z_;
276 
278  {
279  x_ = y_ = z_ = 0.f;
280  }
281 
282  Vec3(const float fX, const float fY, const float fZ)
283  {
284  x_ = fX;
285  y_ = fY;
286  z_ = fZ;
287  }
288 
289  Vec3(const Vec3& vec)
290  {
291  x_ = vec.x_;
292  y_ = vec.y_;
293  z_ = vec.z_;
294  }
295 
296  Vec3(const float* pVec)
297  {
298  x_ = (*pVec++);
299  y_ = (*pVec++);
300  z_ = *pVec;
301  }
302 
303  Vec3(const Vec2& vec, float f)
304  {
305  x_ = vec.x_;
306  y_ = vec.y_;
307  z_ = f;
308  }
309 
310  // compare for order.
311  bool operator <(const Vec3& v) const
312  {
313  return (x_ < v.x_) && (y_ < v.y_) && (z_ < v.z_);
314  }
315 
316  //Operators
317  Vec3 operator*(const Vec3& rhs) const
318  {
319  Vec3 ret;
320  ret.x_ = x_ * rhs.x_;
321  ret.y_ = y_ * rhs.y_;
322  ret.z_ = z_ * rhs.z_;
323  return ret;
324  }
325 
326  Vec3 operator/(const Vec3& rhs) const
327  {
328  Vec3 ret;
329  ret.x_ = x_ / rhs.x_;
330  ret.y_ = y_ / rhs.y_;
331  ret.z_ = z_ / rhs.z_;
332  return ret;
333  }
334 
335  Vec3 operator+(const Vec3& rhs) const
336  {
337  Vec3 ret;
338  ret.x_ = x_ + rhs.x_;
339  ret.y_ = y_ + rhs.y_;
340  ret.z_ = z_ + rhs.z_;
341  return ret;
342  }
343 
344  Vec3 operator-(const Vec3& rhs) const
345  {
346  Vec3 ret;
347  ret.x_ = x_ - rhs.x_;
348  ret.y_ = y_ - rhs.y_;
349  ret.z_ = z_ - rhs.z_;
350  return ret;
351  }
352 
353  Vec3& operator+=(const Vec3& rhs)
354  {
355  x_ += rhs.x_;
356  y_ += rhs.y_;
357  z_ += rhs.z_;
358  return *this;
359  }
360 
361  Vec3& operator-=(const Vec3& rhs)
362  {
363  x_ -= rhs.x_;
364  y_ -= rhs.y_;
365  z_ -= rhs.z_;
366  return *this;
367  }
368 
369  Vec3& operator*=(const Vec3& rhs)
370  {
371  x_ *= rhs.x_;
372  y_ *= rhs.y_;
373  z_ *= rhs.z_;
374  return *this;
375  }
376 
377  Vec3& operator/=(const Vec3& rhs)
378  {
379  x_ /= rhs.x_;
380  y_ /= rhs.y_;
381  z_ /= rhs.z_;
382  return *this;
383  }
384 
385  //External operators
386  friend Vec3 operator-(const Vec3& rhs)
387  {
388  return Vec3(rhs) *= -1;
389  }
390 
391  friend Vec3 operator*(const float lhs, const Vec3& rhs)
392  {
393  Vec3 ret;
394  ret.x_ = lhs * rhs.x_;
395  ret.y_ = lhs * rhs.y_;
396  ret.z_ = lhs * rhs.z_;
397  return ret;
398  }
399 
400  friend Vec3 operator/(const float lhs, const Vec3& rhs)
401  {
402  Vec3 ret;
403  ret.x_ = lhs / rhs.x_;
404  ret.y_ = lhs / rhs.y_;
405  ret.z_ = lhs / rhs.z_;
406  return ret;
407  }
408 
409  //Operators with float
410  Vec3 operator*(const float& rhs) const
411  {
412  Vec3 ret;
413  ret.x_ = x_ * rhs;
414  ret.y_ = y_ * rhs;
415  ret.z_ = z_ * rhs;
416  return ret;
417  }
418 
419  Vec3& operator*=(const float& rhs)
420  {
421  x_ = x_ * rhs;
422  y_ = y_ * rhs;
423  z_ = z_ * rhs;
424  return *this;
425  }
426 
427  Vec3 operator/(const float& rhs) const
428  {
429  Vec3 ret;
430  ret.x_ = x_ / rhs;
431  ret.y_ = y_ / rhs;
432  ret.z_ = z_ / rhs;
433  return ret;
434  }
435 
436  Vec3& operator/=(const float& rhs)
437  {
438  x_ = x_ / rhs;
439  y_ = y_ / rhs;
440  z_ = z_ / rhs;
441  return *this;
442  }
443 
444  //Compare
445  bool operator==(const Vec3& rhs) const
446  {
447  if (x_ != rhs.x_ || y_ != rhs.y_ || z_ != rhs.z_)
448  return false;
449  return true;
450  }
451 
452  bool operator!=(const Vec3& rhs) const
453  {
454  if (x_ == rhs.x_)
455  return false;
456 
457  return true;
458  }
459 
460  float Length() const
461  {
462  return sqrtf(x_ * x_ + y_ * y_ + z_ * z_);
463  }
464 
466  {
467  float len = Length();
468  x_ = x_ / len;
469  y_ = y_ / len;
470  z_ = z_ / len;
471  return *this;
472  }
473 
474  float Dot(const Vec3& rhs)
475  {
476  return x_ * rhs.x_ + y_ * rhs.y_ + z_ * rhs.z_;
477  }
478 
479  float Distance(const Vec3& rhs)
480  {
481  return sqrtf(((x_ - rhs.x_) * (x_ - rhs.x_)) + ((y_ - rhs.y_) * (y_ - rhs.y_)) + ((z_ - rhs.z_) * (z_ - rhs.z_)));
482  }
483 
484  Vec3 Cross(const Vec3& rhs)
485  {
486  Vec3 ret;
487  ret.x_ = y_ * rhs.z_ - z_ * rhs.y_;
488  ret.y_ = z_ * rhs.x_ - x_ * rhs.z_;
489  ret.z_ = x_ * rhs.y_ - y_ * rhs.x_;
490  return ret;
491  }
492 
493  bool Validate()
494  {
495  if (isnan(x_) || isnan(y_) || isnan(z_))
496  return false;
497  return true;
498  }
499 
500  void Value(float& fX, float& fY, float& fZ)
501  {
502  fX = x_;
503  fY = y_;
504  fZ = z_;
505  }
506 
507  void Dump()
508  {
509  printf("Vec3 %f %f %f\n", x_, y_, z_);
510  }
511  };
512 
513  /******************************************************************
514  * 4 elements vector class
515  *
516  */
517  class Vec4
518  {
519  public:
520  float x_, y_, z_, w_;
521 
522  public:
523  friend class Vec3;
524  friend class Mat4;
525  friend class Quaternion;
526 
528  {
529  x_ = y_ = z_ = w_ = 0.f;
530  }
531 
532  Vec4(const float fX, const float fY, const float fZ, const float fW)
533  {
534  x_ = fX;
535  y_ = fY;
536  z_ = fZ;
537  w_ = fW;
538  }
539 
540  Vec4(const Vec4& vec)
541  {
542  x_ = vec.x_;
543  y_ = vec.y_;
544  z_ = vec.z_;
545  w_ = vec.w_;
546  }
547 
548  Vec4(const Vec3& vec, const float fW)
549  {
550  x_ = vec.x_;
551  y_ = vec.y_;
552  z_ = vec.z_;
553  w_ = fW;
554  }
555 
556  Vec4(const float* pVec)
557  {
558  x_ = (*pVec++);
559  y_ = (*pVec++);
560  z_ = *pVec;
561  w_ = *pVec;
562  }
563 
564  //Operators
565  Vec4 operator*(const Vec4& rhs) const
566  {
567  Vec4 ret;
568  ret.x_ = x_ * rhs.x_;
569  ret.y_ = y_ * rhs.y_;
570  ret.z_ = z_ * rhs.z_;
571  ret.w_ = z_ * rhs.w_;
572  return ret;
573  }
574 
575  Vec4 operator/(const Vec4& rhs) const
576  {
577  Vec4 ret;
578  ret.x_ = x_ / rhs.x_;
579  ret.y_ = y_ / rhs.y_;
580  ret.z_ = z_ / rhs.z_;
581  ret.w_ = z_ / rhs.w_;
582  return ret;
583  }
584 
585  Vec4 operator+(const Vec4& rhs) const
586  {
587  Vec4 ret;
588  ret.x_ = x_ + rhs.x_;
589  ret.y_ = y_ + rhs.y_;
590  ret.z_ = z_ + rhs.z_;
591  ret.w_ = z_ + rhs.w_;
592  return ret;
593  }
594 
595  Vec4 operator-(const Vec4& rhs) const
596  {
597  Vec4 ret;
598  ret.x_ = x_ - rhs.x_;
599  ret.y_ = y_ - rhs.y_;
600  ret.z_ = z_ - rhs.z_;
601  ret.w_ = z_ - rhs.w_;
602  return ret;
603  }
604 
605  Vec4& operator+=(const Vec4& rhs)
606  {
607  x_ += rhs.x_;
608  y_ += rhs.y_;
609  z_ += rhs.z_;
610  w_ += rhs.w_;
611  return *this;
612  }
613 
614  Vec4& operator-=(const Vec4& rhs)
615  {
616  x_ -= rhs.x_;
617  y_ -= rhs.y_;
618  z_ -= rhs.z_;
619  w_ -= rhs.w_;
620  return *this;
621  }
622 
623  Vec4& operator*=(const Vec4& rhs)
624  {
625  x_ *= rhs.x_;
626  y_ *= rhs.y_;
627  z_ *= rhs.z_;
628  w_ *= rhs.w_;
629  return *this;
630  }
631 
632  Vec4& operator/=(const Vec4& rhs)
633  {
634  x_ /= rhs.x_;
635  y_ /= rhs.y_;
636  z_ /= rhs.z_;
637  w_ /= rhs.w_;
638  return *this;
639  }
640 
641  //External operators
642  friend Vec4 operator-(const Vec4& rhs)
643  {
644  return Vec4(rhs) *= -1;
645  }
646 
647  friend Vec4 operator*(const float lhs, const Vec4& rhs)
648  {
649  Vec4 ret;
650  ret.x_ = lhs * rhs.x_;
651  ret.y_ = lhs * rhs.y_;
652  ret.z_ = lhs * rhs.z_;
653  ret.w_ = lhs * rhs.w_;
654  return ret;
655  }
656 
657  friend Vec4 operator/(const float lhs, const Vec4& rhs)
658  {
659  Vec4 ret;
660  ret.x_ = lhs / rhs.x_;
661  ret.y_ = lhs / rhs.y_;
662  ret.z_ = lhs / rhs.z_;
663  ret.w_ = lhs / rhs.w_;
664  return ret;
665  }
666 
667  //Operators with float
668  Vec4 operator*(const float& rhs) const
669  {
670  Vec4 ret;
671  ret.x_ = x_ * rhs;
672  ret.y_ = y_ * rhs;
673  ret.z_ = z_ * rhs;
674  ret.w_ = w_ * rhs;
675  return ret;
676  }
677 
678  Vec4& operator*=(const float& rhs)
679  {
680  x_ = x_ * rhs;
681  y_ = y_ * rhs;
682  z_ = z_ * rhs;
683  w_ = w_ * rhs;
684  return *this;
685  }
686 
687  Vec4 operator/(const float& rhs) const
688  {
689  Vec4 ret;
690  ret.x_ = x_ / rhs;
691  ret.y_ = y_ / rhs;
692  ret.z_ = z_ / rhs;
693  ret.w_ = w_ / rhs;
694  return ret;
695  }
696 
697  Vec4& operator/=(const float& rhs)
698  {
699  x_ = x_ / rhs;
700  y_ = y_ / rhs;
701  z_ = z_ / rhs;
702  w_ = w_ / rhs;
703  return *this;
704  }
705 
706  //Compare
707  bool operator==(const Vec4& rhs) const
708  {
709  if (x_ != rhs.x_ || y_ != rhs.y_ || z_ != rhs.z_ || w_ != rhs.w_)
710  return false;
711  return true;
712  }
713 
714  bool operator!=(const Vec4& rhs) const
715  {
716  if (x_ == rhs.x_)
717  return false;
718 
719  return true;
720  }
721 
722  float Length() const
723  {
724  return sqrtf(x_ * x_ + y_ * y_ + z_ * z_ + w_ * w_);
725  }
726 
728  {
729  float len = Length();
730  x_ = x_ / len;
731  y_ = y_ / len;
732  z_ = z_ / len;
733  w_ = w_ / len;
734  return *this;
735  }
736 
737  float Dot(const Vec3& rhs)
738  {
739  return x_ * rhs.x_ + y_ * rhs.y_ + z_ * rhs.z_;
740  }
741 
742  Vec3 Cross(const Vec3& rhs)
743  {
744  Vec3 ret;
745  ret.x_ = y_ * rhs.z_ - z_ * rhs.y_;
746  ret.y_ = z_ * rhs.x_ - x_ * rhs.z_;
747  ret.z_ = x_ * rhs.y_ - y_ * rhs.x_;
748  return ret;
749  }
750 
751  bool Validate()
752  {
753  if (isnan(x_) || isnan(y_) || isnan(z_) || isnan(w_))
754  return false;
755  return true;
756  }
757 
758  void Value(float& fX, float& fY, float& fZ, float& fW)
759  {
760  fX = x_;
761  fY = y_;
762  fZ = z_;
763  fW = w_;
764  }
765  };
766 
767  /******************************************************************
768  * 3x3 column major Matrix
769  *
770  */
771  class Mat3
772  {
773  private:
774  float f_[9];
775 
776  public:
777  friend class Vec3;
778 
779  Mat3() {
780  for (int i = 0; i < 9; i++) {
781  f_[i] = 0.f;
782  }
783  }
784 
785  Mat3(const float* mIn) {
786  for (int i = 0; i < 9; i++) {
787  f_[i] = mIn[i];
788  }
789  }
790 
791  Mat3 operator*(const Mat3& rhs) const {
792  Mat3 ret;
793 
794  ret.f_[0] = f_[0] * rhs.f_[0] + f_[3] * rhs.f_[1] + f_[6] * rhs.f_[2];
795  ret.f_[1] = f_[1] * rhs.f_[0] + f_[4] * rhs.f_[1] + f_[7] * rhs.f_[2];
796  ret.f_[2] = f_[2] * rhs.f_[0] + f_[5] * rhs.f_[1] + f_[8] * rhs.f_[2];
797 
798  ret.f_[3] = f_[0] * rhs.f_[3] + f_[3] * rhs.f_[4] + f_[6] * rhs.f_[5];
799  ret.f_[4] = f_[1] * rhs.f_[3] + f_[4] * rhs.f_[4] + f_[7] * rhs.f_[5];
800  ret.f_[5] = f_[2] * rhs.f_[3] + f_[5] * rhs.f_[4] + f_[8] * rhs.f_[5];
801 
802  ret.f_[6] = f_[0] * rhs.f_[6] + f_[3] * rhs.f_[7] + f_[6] * rhs.f_[8];
803  ret.f_[7] = f_[1] * rhs.f_[6] + f_[4] * rhs.f_[7] + f_[7] * rhs.f_[8];
804  ret.f_[8] = f_[2] * rhs.f_[6] + f_[5] * rhs.f_[7] + f_[8] * rhs.f_[8];
805 
806  return ret;
807  }
808 
809  Vec3 operator*(const Vec3& rhs) const {
810  Vec3 ret;
811  ret.x_ = rhs.x_ * f_[0] + rhs.y_ * f_[3] + rhs.z_ * f_[6];
812  ret.y_ = rhs.x_ * f_[1] + rhs.y_ * f_[4] + rhs.z_ * f_[7];
813  ret.z_ = rhs.x_ * f_[2] + rhs.y_ * f_[5] + rhs.z_ * f_[8];
814  return ret;
815  }
816 
817  Mat3 operator+(const Mat3& rhs) const {
818  Mat3 ret;
819  for (int i = 0; i < 9; ++i) {
820  ret.f_[i] = f_[i] + rhs.f_[i];
821  }
822  return ret;
823  }
824 
825  Mat3 operator-(const Mat3& rhs) const {
826  Mat3 ret;
827  for (int i = 0; i < 9; ++i) {
828  ret.f_[i] = f_[i] - rhs.f_[i];
829  }
830  return ret;
831  }
832 
833  Mat3& operator+=(const Mat3& rhs) {
834  for (int i = 0; i < 9; ++i) {
835  f_[i] += rhs.f_[i];
836  }
837  return *this;
838  }
839 
840  Mat3& operator-=(const Mat3& rhs) {
841  for (int i = 0; i < 9; ++i) {
842  f_[i] -= rhs.f_[i];
843  }
844  return *this;
845  }
846 
847  Mat3& operator*=(const Mat3& rhs) {
848  Mat3 ret;
849 
850  ret.f_[0] = f_[0] * rhs.f_[0] + f_[3] * rhs.f_[1] + f_[6] * rhs.f_[2];
851  ret.f_[1] = f_[1] * rhs.f_[0] + f_[4] * rhs.f_[1] + f_[7] * rhs.f_[2];
852  ret.f_[2] = f_[2] * rhs.f_[0] + f_[5] * rhs.f_[1] + f_[8] * rhs.f_[2];
853 
854  ret.f_[3] = f_[0] * rhs.f_[3] + f_[3] * rhs.f_[4] + f_[6] * rhs.f_[5];
855  ret.f_[4] = f_[1] * rhs.f_[3] + f_[4] * rhs.f_[4] + f_[7] * rhs.f_[5];
856  ret.f_[5] = f_[2] * rhs.f_[3] + f_[5] * rhs.f_[4] + f_[8] * rhs.f_[5];
857 
858  ret.f_[6] = f_[0] * rhs.f_[6] + f_[3] * rhs.f_[7] + f_[6] * rhs.f_[8];
859  ret.f_[7] = f_[1] * rhs.f_[6] + f_[4] * rhs.f_[7] + f_[7] * rhs.f_[8];
860  ret.f_[8] = f_[2] * rhs.f_[6] + f_[5] * rhs.f_[7] + f_[8] * rhs.f_[8];
861 
862  *this = ret;
863  return *this;
864  }
865 
866  Mat3 operator*(const float rhs) {
867  Mat3 ret;
868  for (int i = 0; i < 9; ++i) {
869  ret.f_[i] = f_[i] * rhs;
870  }
871  return ret;
872  }
873 
874  Mat3& operator*=(const float rhs) {
875  for (int i = 0; i < 9; ++i) {
876  f_[i] *= rhs;
877  }
878  return *this;
879  }
880 
881  Mat3& operator=(const Mat3& rhs) {
882  for (int i = 0; i < 9; ++i) {
883  f_[i] = rhs.f_[i];
884  }
885  return *this;
886  }
887 
889  Mat3 ret;
890 
891  float det =
892  f_[0] * f_[4] * f_[8] +
893  f_[1] * f_[5] * f_[6] +
894  f_[2] * f_[3] * f_[7] -
895  f_[0] * f_[5] * f_[7] -
896  f_[2] * f_[4] * f_[6] -
897  f_[1] * f_[3] * f_[8];
898 
899  if (det == 0) {
900  //Error
901  }
902  else {
903  ret.f_[0] = (f_[4] * f_[8] - f_[7] * f_[5]) / det;
904  ret.f_[1] = (f_[7] * f_[2] - f_[1] * f_[8]) / det;
905  ret.f_[2] = (f_[1] * f_[5] - f_[4] * f_[2]) / det;
906 
907  ret.f_[3] = (f_[6] * f_[5] - f_[3] * f_[8]) / det;
908  ret.f_[4] = (f_[0] * f_[8] - f_[6] * f_[2]) / det;
909  ret.f_[5] = (f_[3] * f_[2] - f_[0] * f_[5]) / det;
910 
911  ret.f_[6] = (f_[3] * f_[7] - f_[6] * f_[4]) / det;
912  ret.f_[7] = (f_[6] * f_[1] - f_[0] * f_[7]) / det;
913  ret.f_[8] = (f_[0] * f_[4] - f_[3] * f_[1]) / det;
914  }
915 
916  *this = ret;
917  return *this;
918  }
919 
921  Mat3 ret;
922  ret.f_[0] = f_[0];
923  ret.f_[1] = f_[3];
924  ret.f_[2] = f_[6];
925 
926  ret.f_[3] = f_[1];
927  ret.f_[4] = f_[4];
928  ret.f_[5] = f_[7];
929 
930  ret.f_[6] = f_[2];
931  ret.f_[7] = f_[5];
932  ret.f_[8] = f_[8];
933 
934  *this = ret;
935  return *this;
936  }
937 
938  float* Ptr() {
939  return f_;
940  }
941 
942 
943  static Mat3 Identity() {
944  Mat3 ret;
945 
946  ret.f_[0] = 1.f;
947  ret.f_[1] = 0.f;
948  ret.f_[2] = 0.f;
949  ret.f_[3] = 0.f;
950  ret.f_[4] = 1.f;
951  ret.f_[5] = 0.f;
952  ret.f_[6] = 0.f;
953  ret.f_[7] = 0.f;
954  ret.f_[8] = 1.f;
955 
956  return ret;
957  }
958 
959  static Mat3 Zero() {
960  Mat3 ret;
961 
962  ret.f_[0] = 0.0f;
963  ret.f_[1] = 0.0f;
964  ret.f_[2] = 0.0f;
965  ret.f_[3] = 0.0f;
966  ret.f_[4] = 0.0f;
967  ret.f_[5] = 0.0f;
968  ret.f_[6] = 0.0f;
969  ret.f_[7] = 0.0f;
970  ret.f_[8] = 0.0f;
971 
972  return ret;
973  }
974  };
975 
976  /******************************************************************
977  * 4x4 matrix
978  *
979  */
980  class Mat4
981  {
982  private:
983  float f_[16];
984 
985  public:
986  friend class Vec3;
987  friend class Vec4;
988  friend class Quaternion;
989 
991  {
992  for (int i = 0; i < 16; ++i)
993  f_[i] = 0.f;
994  }
995 
996  Mat4(const float* mIn)
997  {
998  for (int i = 0; i < 16; ++i)
999  f_[i] = mIn[i];
1000  }
1001 
1002  Mat4 operator*(const Mat4& rhs) const
1003  {
1004  Mat4 ret;
1005  ret.f_[0] = f_[0] * rhs.f_[0] + f_[4] * rhs.f_[1] + f_[8] * rhs.f_[2]
1006  + f_[12] * rhs.f_[3];
1007  ret.f_[1] = f_[1] * rhs.f_[0] + f_[5] * rhs.f_[1] + f_[9] * rhs.f_[2]
1008  + f_[13] * rhs.f_[3];
1009  ret.f_[2] = f_[2] * rhs.f_[0] + f_[6] * rhs.f_[1] + f_[10] * rhs.f_[2]
1010  + f_[14] * rhs.f_[3];
1011  ret.f_[3] = f_[3] * rhs.f_[0] + f_[7] * rhs.f_[1] + f_[11] * rhs.f_[2]
1012  + f_[15] * rhs.f_[3];
1013 
1014  ret.f_[4] = f_[0] * rhs.f_[4] + f_[4] * rhs.f_[5] + f_[8] * rhs.f_[6]
1015  + f_[12] * rhs.f_[7];
1016  ret.f_[5] = f_[1] * rhs.f_[4] + f_[5] * rhs.f_[5] + f_[9] * rhs.f_[6]
1017  + f_[13] * rhs.f_[7];
1018  ret.f_[6] = f_[2] * rhs.f_[4] + f_[6] * rhs.f_[5] + f_[10] * rhs.f_[6]
1019  + f_[14] * rhs.f_[7];
1020  ret.f_[7] = f_[3] * rhs.f_[4] + f_[7] * rhs.f_[5] + f_[11] * rhs.f_[6]
1021  + f_[15] * rhs.f_[7];
1022 
1023  ret.f_[8] = f_[0] * rhs.f_[8] + f_[4] * rhs.f_[9] + f_[8] * rhs.f_[10]
1024  + f_[12] * rhs.f_[11];
1025  ret.f_[9] = f_[1] * rhs.f_[8] + f_[5] * rhs.f_[9] + f_[9] * rhs.f_[10]
1026  + f_[13] * rhs.f_[11];
1027  ret.f_[10] = f_[2] * rhs.f_[8] + f_[6] * rhs.f_[9] + f_[10] * rhs.f_[10]
1028  + f_[14] * rhs.f_[11];
1029  ret.f_[11] = f_[3] * rhs.f_[8] + f_[7] * rhs.f_[9] + f_[11] * rhs.f_[10]
1030  + f_[15] * rhs.f_[11];
1031 
1032  ret.f_[12] = f_[0] * rhs.f_[12] + f_[4] * rhs.f_[13] + f_[8] * rhs.f_[14]
1033  + f_[12] * rhs.f_[15];
1034  ret.f_[13] = f_[1] * rhs.f_[12] + f_[5] * rhs.f_[13] + f_[9] * rhs.f_[14]
1035  + f_[13] * rhs.f_[15];
1036  ret.f_[14] = f_[2] * rhs.f_[12] + f_[6] * rhs.f_[13] + f_[10] * rhs.f_[14]
1037  + f_[14] * rhs.f_[15];
1038  ret.f_[15] = f_[3] * rhs.f_[12] + f_[7] * rhs.f_[13] + f_[11] * rhs.f_[14]
1039  + f_[15] * rhs.f_[15];
1040 
1041  return ret;
1042  }
1043 
1044  Vec4 operator*(const Vec4& rhs) const
1045  {
1046  Vec4 ret;
1047  ret.x_ = rhs.x_ * f_[0] + rhs.y_ * f_[4] + rhs.z_ * f_[8] + rhs.w_ * f_[12];
1048  ret.y_ = rhs.x_ * f_[1] + rhs.y_ * f_[5] + rhs.z_ * f_[9] + rhs.w_ * f_[13];
1049  ret.z_ = rhs.x_ * f_[2] + rhs.y_ * f_[6] + rhs.z_ * f_[10] + rhs.w_ * f_[14];
1050  ret.w_ = rhs.x_ * f_[3] + rhs.y_ * f_[7] + rhs.z_ * f_[11] + rhs.w_ * f_[15];
1051  return ret;
1052  }
1053 
1054  Mat4 operator+(const Mat4& rhs) const
1055  {
1056  Mat4 ret;
1057  for (int i = 0; i < 16; ++i)
1058  {
1059  ret.f_[i] = f_[i] + rhs.f_[i];
1060  }
1061  return ret;
1062  }
1063 
1064  Mat4 operator-(const Mat4& rhs) const
1065  {
1066  Mat4 ret;
1067  for (int i = 0; i < 16; ++i)
1068  {
1069  ret.f_[i] = f_[i] - rhs.f_[i];
1070  }
1071  return ret;
1072  }
1073 
1074  Mat4& operator+=(const Mat4& rhs)
1075  {
1076  for (int i = 0; i < 16; ++i)
1077  {
1078  f_[i] += rhs.f_[i];
1079  }
1080  return *this;
1081  }
1082 
1083  Mat4& operator-=(const Mat4& rhs)
1084  {
1085  for (int i = 0; i < 16; ++i)
1086  {
1087  f_[i] -= rhs.f_[i];
1088  }
1089  return *this;
1090  }
1091 
1092  Mat4& operator*=(const Mat4& rhs)
1093  {
1094  Mat4 ret;
1095  ret.f_[0] = f_[0] * rhs.f_[0] + f_[4] * rhs.f_[1] + f_[8] * rhs.f_[2]
1096  + f_[12] * rhs.f_[3];
1097  ret.f_[1] = f_[1] * rhs.f_[0] + f_[5] * rhs.f_[1] + f_[9] * rhs.f_[2]
1098  + f_[13] * rhs.f_[3];
1099  ret.f_[2] = f_[2] * rhs.f_[0] + f_[6] * rhs.f_[1] + f_[10] * rhs.f_[2]
1100  + f_[14] * rhs.f_[3];
1101  ret.f_[3] = f_[3] * rhs.f_[0] + f_[7] * rhs.f_[1] + f_[11] * rhs.f_[2]
1102  + f_[15] * rhs.f_[3];
1103 
1104  ret.f_[4] = f_[0] * rhs.f_[4] + f_[4] * rhs.f_[5] + f_[8] * rhs.f_[6]
1105  + f_[12] * rhs.f_[7];
1106  ret.f_[5] = f_[1] * rhs.f_[4] + f_[5] * rhs.f_[5] + f_[9] * rhs.f_[6]
1107  + f_[13] * rhs.f_[7];
1108  ret.f_[6] = f_[2] * rhs.f_[4] + f_[6] * rhs.f_[5] + f_[10] * rhs.f_[6]
1109  + f_[14] * rhs.f_[7];
1110  ret.f_[7] = f_[3] * rhs.f_[4] + f_[7] * rhs.f_[5] + f_[11] * rhs.f_[6]
1111  + f_[15] * rhs.f_[7];
1112 
1113  ret.f_[8] = f_[0] * rhs.f_[8] + f_[4] * rhs.f_[9] + f_[8] * rhs.f_[10]
1114  + f_[12] * rhs.f_[11];
1115  ret.f_[9] = f_[1] * rhs.f_[8] + f_[5] * rhs.f_[9] + f_[9] * rhs.f_[10]
1116  + f_[13] * rhs.f_[11];
1117  ret.f_[10] = f_[2] * rhs.f_[8] + f_[6] * rhs.f_[9] + f_[10] * rhs.f_[10]
1118  + f_[14] * rhs.f_[11];
1119  ret.f_[11] = f_[3] * rhs.f_[8] + f_[7] * rhs.f_[9] + f_[11] * rhs.f_[10]
1120  + f_[15] * rhs.f_[11];
1121 
1122  ret.f_[12] = f_[0] * rhs.f_[12] + f_[4] * rhs.f_[13] + f_[8] * rhs.f_[14]
1123  + f_[12] * rhs.f_[15];
1124  ret.f_[13] = f_[1] * rhs.f_[12] + f_[5] * rhs.f_[13] + f_[9] * rhs.f_[14]
1125  + f_[13] * rhs.f_[15];
1126  ret.f_[14] = f_[2] * rhs.f_[12] + f_[6] * rhs.f_[13] + f_[10] * rhs.f_[14]
1127  + f_[14] * rhs.f_[15];
1128  ret.f_[15] = f_[3] * rhs.f_[12] + f_[7] * rhs.f_[13] + f_[11] * rhs.f_[14]
1129  + f_[15] * rhs.f_[15];
1130 
1131  *this = ret;
1132  return *this;
1133  }
1134 
1135  Mat4 operator*(const float rhs)
1136  {
1137  Mat4 ret;
1138  for (int i = 0; i < 16; ++i)
1139  {
1140  ret.f_[i] = f_[i] * rhs;
1141  }
1142  return ret;
1143  }
1144 
1145  Mat4& operator*=(const float rhs)
1146  {
1147  for (int i = 0; i < 16; ++i)
1148  {
1149  f_[i] *= rhs;
1150  }
1151  return *this;
1152  }
1153 
1154  Mat4& operator=(const Mat4& rhs)
1155  {
1156  for (int i = 0; i < 16; ++i)
1157  {
1158  f_[i] = rhs.f_[i];
1159  }
1160  return *this;
1161  }
1162 
1164  {
1165  Mat4 ret;
1166  float det_1;
1167  float pos = 0;
1168  float neg = 0;
1169  float temp;
1170 
1171  temp = f_[0] * f_[5] * f_[10];
1172  if (temp >= 0)
1173  pos += temp;
1174  else
1175  neg += temp;
1176  temp = f_[4] * f_[9] * f_[2];
1177  if (temp >= 0)
1178  pos += temp;
1179  else
1180  neg += temp;
1181  temp = f_[8] * f_[1] * f_[6];
1182  if (temp >= 0)
1183  pos += temp;
1184  else
1185  neg += temp;
1186  temp = -f_[8] * f_[5] * f_[2];
1187  if (temp >= 0)
1188  pos += temp;
1189  else
1190  neg += temp;
1191  temp = -f_[4] * f_[1] * f_[10];
1192  if (temp >= 0)
1193  pos += temp;
1194  else
1195  neg += temp;
1196  temp = -f_[0] * f_[9] * f_[6];
1197  if (temp >= 0)
1198  pos += temp;
1199  else
1200  neg += temp;
1201  det_1 = pos + neg;
1202 
1203  if (det_1 == 0.0)
1204  {
1205  //Error
1206  }
1207  else
1208  {
1209  det_1 = 1.0f / det_1;
1210  ret.f_[0] = (f_[5] * f_[10] - f_[9] * f_[6]) * det_1;
1211  ret.f_[1] = -(f_[1] * f_[10] - f_[9] * f_[2]) * det_1;
1212  ret.f_[2] = (f_[1] * f_[6] - f_[5] * f_[2]) * det_1;
1213  ret.f_[4] = -(f_[4] * f_[10] - f_[8] * f_[6]) * det_1;
1214  ret.f_[5] = (f_[0] * f_[10] - f_[8] * f_[2]) * det_1;
1215  ret.f_[6] = -(f_[0] * f_[6] - f_[4] * f_[2]) * det_1;
1216  ret.f_[8] = (f_[4] * f_[9] - f_[8] * f_[5]) * det_1;
1217  ret.f_[9] = -(f_[0] * f_[9] - f_[8] * f_[1]) * det_1;
1218  ret.f_[10] = (f_[0] * f_[5] - f_[4] * f_[1]) * det_1;
1219 
1220  /* Calculate -C * inverse(A) */
1221  ret.f_[12] = -(f_[12] * ret.f_[0] + f_[13] * ret.f_[4] + f_[14] * ret.f_[8]);
1222  ret.f_[13] = -(f_[12] * ret.f_[1] + f_[13] * ret.f_[5] + f_[14] * ret.f_[9]);
1223  ret.f_[14] = -(f_[12] * ret.f_[2] + f_[13] * ret.f_[6] + f_[14] * ret.f_[10]);
1224 
1225  ret.f_[3] = 0.0f;
1226  ret.f_[7] = 0.0f;
1227  ret.f_[11] = 0.0f;
1228  ret.f_[15] = 1.0f;
1229  }
1230 
1231  *this = ret;
1232  return *this;
1233  }
1234 
1236  {
1237  Mat4 ret;
1238  ret.f_[0] = f_[0];
1239  ret.f_[1] = f_[4];
1240  ret.f_[2] = f_[8];
1241  ret.f_[3] = f_[12];
1242  ret.f_[4] = f_[1];
1243  ret.f_[5] = f_[5];
1244  ret.f_[6] = f_[9];
1245  ret.f_[7] = f_[13];
1246  ret.f_[8] = f_[2];
1247  ret.f_[9] = f_[6];
1248  ret.f_[10] = f_[10];
1249  ret.f_[11] = f_[14];
1250  ret.f_[12] = f_[3];
1251  ret.f_[13] = f_[7];
1252  ret.f_[14] = f_[11];
1253  ret.f_[15] = f_[15];
1254  *this = ret;
1255  return *this;
1256  }
1257 
1258  Mat4& PostTranslate(float tx, float ty, float tz)
1259  {
1260  f_[12] += (tx * f_[0]) + (ty * f_[4]) + (tz * f_[8]);
1261  f_[13] += (tx * f_[1]) + (ty * f_[5]) + (tz * f_[9]);
1262  f_[14] += (tx * f_[2]) + (ty * f_[6]) + (tz * f_[10]);
1263  f_[15] += (tx * f_[3]) + (ty * f_[7]) + (tz * f_[11]);
1264  return *this;
1265  }
1266 
1267  Mat4& PostRotate(float angle, float rx, float ry, float rz)
1268  {
1269  float sinAngle, cosAngle;
1270  float mag = (float)sqrtf(rx * rx + ry * ry + rz * rz);
1271 
1272  sinAngle = sinf(angle * PI / 180.0f);
1273  cosAngle = cosf(angle * PI / 180.0f);
1274 
1275  if (mag > 0.0f) {
1276  float xx, yy, zz, xy, yz, zx, xs, ys, zs;
1277  float oneMinusCos;
1278  Mat4 rotMat;
1279 
1280  rx /= mag;
1281  ry /= mag;
1282  rz /= mag;
1283 
1284  xx = rx * rx;
1285  yy = ry * ry;
1286  zz = rz * rz;
1287  xy = rx * ry;
1288  yz = ry * rz;
1289  zx = rz * rx;
1290  xs = rx * sinAngle;
1291  ys = ry * sinAngle;
1292  zs = rz * sinAngle;
1293 
1294  oneMinusCos = 1.0f - cosAngle;
1295  rotMat.Ptr()[0] = (oneMinusCos * xx) + cosAngle;
1296  rotMat.Ptr()[1] = (oneMinusCos * xy) - zs;
1297  rotMat.Ptr()[2] = (oneMinusCos * zx) + ys;
1298  rotMat.Ptr()[3] = 0.0F;
1299  rotMat.Ptr()[4] = (oneMinusCos * xy) + zs;
1300  rotMat.Ptr()[5] = (oneMinusCos * yy) + cosAngle;
1301  rotMat.Ptr()[6] = (oneMinusCos * yz) - xs;
1302  rotMat.Ptr()[7] = 0.0F;
1303  rotMat.Ptr()[8] = (oneMinusCos * zx) - ys;
1304  rotMat.Ptr()[9] = (oneMinusCos * yz) + xs;
1305  rotMat.Ptr()[10] = (oneMinusCos * zz) + cosAngle;
1306  rotMat.Ptr()[11] = 0.0F;
1307  rotMat.Ptr()[12] = 0.0F;
1308  rotMat.Ptr()[13] = 0.0F;
1309  rotMat.Ptr()[14] = 0.0F;
1310  rotMat.Ptr()[15] = 1.0F;
1311 
1312  *this *= rotMat;
1313  }
1314  return *this;
1315  }
1316 
1317  Mat4& PostScale(float sx, float sy, float sz)
1318  {
1319  f_[0] *= sx;
1320  f_[1] *= sx;
1321  f_[2] *= sx;
1322  f_[3] *= sx;
1323  f_[4] *= sy;
1324  f_[5] *= sy;
1325  f_[6] *= sy;
1326  f_[7] *= sy;
1327  f_[8] *= sz;
1328  f_[9] *= sz;
1329  f_[10] *= sz;
1330  f_[11] *= sz;
1331  return *this;
1332  }
1333 
1334  float* Ptr()
1335  {
1336  return f_;
1337  }
1338 
1339  //--------------------------------------------------------------------------------
1340  // Misc
1341  //--------------------------------------------------------------------------------
1342  static Mat4 Perspective(float width, float height, float nearPlane, float farPlane)
1343  {
1344  Mat4 result;
1345 #if 1
1346  float x = 1.0f;
1347  float y = width / height;
1348 
1349  result.Ptr()[0] = 2.0f * x;
1350  result.Ptr()[1] = 0.0f;
1351  result.Ptr()[2] = 0.0f;
1352  result.Ptr()[3] = 0.0f;
1353  result.Ptr()[4] = 0.0f;
1354  result.Ptr()[5] = 2.0f * -y;
1355  result.Ptr()[6] = 0.0f;
1356  result.Ptr()[7] = 0.0f;
1357  result.Ptr()[8] = 0.0f;
1358  result.Ptr()[9] = 0.0f;
1359  result.Ptr()[10] = (farPlane + nearPlane) / (farPlane - nearPlane);
1360  result.Ptr()[11] = 1.0f;
1361  result.Ptr()[12] = 0.0f;
1362  result.Ptr()[13] = 0.0f;
1363  result.Ptr()[14] = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
1364  result.Ptr()[15] = 0.0f;
1365 #else
1366  float n2 = 2.0f * nearPlane;
1367  float rcpnmf = 1.f / (nearPlane - farPlane);
1368 
1369  Mat4 result;
1370  result.f_[0] = n2 / width;
1371  result.f_[4] = 0;
1372  result.f_[8] = 0;
1373  result.f_[12] = 0;
1374  result.f_[1] = 0;
1375  result.f_[5] = n2 / height;
1376  result.f_[9] = 0;
1377  result.f_[13] = 0;
1378  result.f_[2] = 0;
1379  result.f_[6] = 0;
1380  result.f_[10] = (farPlane + nearPlane) * rcpnmf;
1381  result.f_[14] = farPlane * rcpnmf * n2;
1382  result.f_[3] = 0;
1383  result.f_[7] = 0;
1384  result.f_[11] = -1.0;
1385  result.f_[15] = 0;
1386 #endif
1387  return result;
1388  }
1389 
1390  static Mat4 Perspective(float fovy, int width, int height, float zNear, float zFar)
1391  {
1392  Mat4 result;
1393 
1394  float aspect = (float)width / (float)height;
1395  float f = 1.0f / (float)tan(fovy * (PI / 360.0f));
1396  float rangeReciprocal = 1.0f / (zNear - zFar);
1397 
1398  result.f_[0] = f / aspect;
1399  result.f_[1] = 0.0f;
1400  result.f_[2] = 0.0f;
1401  result.f_[3] = 0.0f;
1402 
1403  result.f_[4] = 0.0f;
1404  result.f_[5] = -f;
1405  result.f_[6] = 0.0f;
1406  result.f_[7] = 0.0f;
1407 
1408  result.f_[8] = 0.0f;
1409  result.f_[9] = 0.0f;
1410  result.f_[10] = -(zFar + zNear) * rangeReciprocal;
1411  result.f_[11] = 1.0f;
1412 
1413  result.f_[12] = 0.0f;
1414  result.f_[13] = 0.0f;
1415  result.f_[14] = 2.0f * zFar * zNear * rangeReciprocal;
1416  result.f_[15] = 0.0f;
1417 
1418  return result;
1419  }
1420 
1421  static Mat4 Perspective(float fx, float fy, float cx, float cy, int w, int h, float n, float f)
1422  {
1423  Mat4 result;
1424 
1425  result.f_[0] = 2.0f * fx / w;
1426  result.f_[1] = 0.0f;
1427  result.f_[2] = 0.0f;
1428  result.f_[3] = 0.0f;
1429 
1430  result.f_[4] = 0.0f;
1431  result.f_[5] = -2.0f * fy / h;
1432  result.f_[6] = 0.0f;
1433  result.f_[7] = 0.0f;
1434 
1435  result.f_[8] = 1.0f - 2.0f * cx / w;
1436  result.f_[9] = 2.0f * cy / h - 1.0f;
1437  result.f_[10] = -(f + n) / (n - f);
1438  result.f_[11] = 1.0f;
1439 
1440  result.f_[12] = 0.0f;
1441  result.f_[13] = 0.0f;
1442  result.f_[14] = 2.0f * f * n / (n - f);
1443  result.f_[15] = 0.0f;
1444 
1445 #if 0
1446  m[0][0] = 2.0 * fx / width;
1447  m[0][1] = 0.0;
1448  m[0][2] = 0.0;
1449  m[0][3] = 0.0;
1450 
1451  m[1][0] = 0.0;
1452  m[1][1] = -2.0 * fy / height;
1453  m[1][2] = 0.0;
1454  m[1][3] = 0.0;
1455 
1456  m[2][0] = 1.0 - 2.0 * cx / width;
1457  m[2][1] = 2.0 * cy / height - 1.0;
1458  m[2][2] = (zfar + znear) / (znear - zfar);
1459  m[2][3] = -1.0;
1460 
1461  m[3][0] = 0.0;
1462  m[3][1] = 0.0;
1463  m[3][2] = 2.0 * zfar * znear / (znear - zfar);
1464  m[3][3] = 0.0;
1465 #endif
1466 
1467  return result;
1468  }
1469 
1470  static Mat4 Ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane)
1471  {
1472  float r_l = right - left;
1473  float t_b = top - bottom;
1474  float f_n = farPlane - nearPlane;
1475 
1476  float tx = -(right + left) / (right - left);
1477  float ty = -(top + bottom) / (top - bottom);
1478  float tz = -(farPlane + nearPlane) / (farPlane - nearPlane);
1479 
1480  Mat4 result;
1481  result.f_[0] = 2.0f / r_l;
1482  result.f_[1] = 0.0f;
1483  result.f_[2] = 0.0f;
1484  result.f_[3] = tx;
1485 
1486  result.f_[4] = 0.0f;
1487  result.f_[5] = 2.0f / t_b;
1488  result.f_[6] = 0.0f;
1489  result.f_[7] = ty;
1490 
1491  result.f_[8] = 0.0f;
1492  result.f_[9] = 0.0f;
1493  result.f_[10] = 2.0f / f_n;
1494  result.f_[11] = tz;
1495 
1496  result.f_[12] = 0.0f;
1497  result.f_[13] = 0.0f;
1498  result.f_[14] = 0.0f;
1499  result.f_[15] = 1.0f;
1500 
1501  return result;
1502  }
1503 
1504  static Mat4 LookAt(const Vec3& vec_eye, const Vec3& vec_at, const Vec3& vec_up)
1505  {
1506  Vec3 vec_forward, vec_up_norm, vec_side;
1507  Mat4 result;
1508 
1509  vec_forward.x_ = vec_eye.x_ - vec_at.x_;
1510  vec_forward.y_ = vec_eye.y_ - vec_at.y_;
1511  vec_forward.z_ = vec_eye.z_ - vec_at.z_;
1512 
1513  vec_forward.Normalize();
1514  vec_up_norm = vec_up;
1515  vec_up_norm.Normalize();
1516  vec_side = vec_up_norm.Cross(vec_forward);
1517  vec_up_norm = vec_forward.Cross(vec_side);
1518 
1519  result.f_[0] = vec_side.x_;
1520  result.f_[4] = vec_side.y_;
1521  result.f_[8] = vec_side.z_;
1522  result.f_[12] = 0;
1523  result.f_[1] = vec_up_norm.x_;
1524  result.f_[5] = vec_up_norm.y_;
1525  result.f_[9] = vec_up_norm.z_;
1526  result.f_[13] = 0;
1527  result.f_[2] = vec_forward.x_;
1528  result.f_[6] = vec_forward.y_;
1529  result.f_[10] = vec_forward.z_;
1530  result.f_[14] = 0;
1531  result.f_[3] = 0;
1532  result.f_[7] = 0;
1533  result.f_[11] = 0;
1534  result.f_[15] = 1.0;
1535 
1536  result.PostTranslate(-vec_eye.x_, -vec_eye.y_, -vec_eye.z_);
1537  return result;
1538  }
1539 
1540  static Mat4 Translation(const float fX, const float fY, const float fZ)
1541  {
1542  Mat4 ret;
1543  ret.f_[0] = 1.0f;
1544  ret.f_[4] = 0.0f;
1545  ret.f_[8] = 0.0f;
1546  ret.f_[12] = fX;
1547  ret.f_[1] = 0.0f;
1548  ret.f_[5] = 1.0f;
1549  ret.f_[9] = 0.0f;
1550  ret.f_[13] = fY;
1551  ret.f_[2] = 0.0f;
1552  ret.f_[6] = 0.0f;
1553  ret.f_[10] = 1.0f;
1554  ret.f_[14] = fZ;
1555  ret.f_[3] = 0.0f;
1556  ret.f_[7] = 0.0f;
1557  ret.f_[11] = 0.0f;
1558  ret.f_[15] = 1.0f;
1559  return ret;
1560  }
1561 
1562  static Mat4 Translation(const Vec3 vec)
1563  {
1564  Mat4 ret;
1565  ret.f_[0] = 1.0f;
1566  ret.f_[4] = 0.0f;
1567  ret.f_[8] = 0.0f;
1568  ret.f_[12] = vec.x_;
1569  ret.f_[1] = 0.0f;
1570  ret.f_[5] = 1.0f;
1571  ret.f_[9] = 0.0f;
1572  ret.f_[13] = vec.y_;
1573  ret.f_[2] = 0.0f;
1574  ret.f_[6] = 0.0f;
1575  ret.f_[10] = 1.0f;
1576  ret.f_[14] = vec.z_;
1577  ret.f_[3] = 0.0f;
1578  ret.f_[7] = 0.0f;
1579  ret.f_[11] = 0.0f;
1580  ret.f_[15] = 1.0f;
1581  return ret;
1582  }
1583 
1584  static Mat4 RotationX(const float fAngle)
1585  {
1586  Mat4 ret;
1587  float fCosine, fSine;
1588 
1589  fCosine = cosf(fAngle);
1590  fSine = sinf(fAngle);
1591 
1592  ret.f_[0] = 1.0f;
1593  ret.f_[4] = 0.0f;
1594  ret.f_[8] = 0.0f;
1595  ret.f_[12] = 0.0f;
1596  ret.f_[1] = 0.0f;
1597  ret.f_[5] = fCosine;
1598  ret.f_[9] = fSine;
1599  ret.f_[13] = 0.0f;
1600  ret.f_[2] = 0.0f;
1601  ret.f_[6] = -fSine;
1602  ret.f_[10] = fCosine;
1603  ret.f_[14] = 0.0f;
1604  ret.f_[3] = 0.0f;
1605  ret.f_[7] = 0.0f;
1606  ret.f_[11] = 0.0f;
1607  ret.f_[15] = 1.0f;
1608  return ret;
1609  }
1610 
1611  static Mat4 RotationY(const float fAngle)
1612  {
1613  Mat4 ret;
1614  float fCosine, fSine;
1615 
1616  fCosine = cosf(fAngle);
1617  fSine = sinf(fAngle);
1618 
1619  ret.f_[0] = fCosine;
1620  ret.f_[4] = 0.0f;
1621  ret.f_[8] = -fSine;
1622  ret.f_[12] = 0.0f;
1623  ret.f_[1] = 0.0f;
1624  ret.f_[5] = 1.0f;
1625  ret.f_[9] = 0.0f;
1626  ret.f_[13] = 0.0f;
1627  ret.f_[2] = fSine;
1628  ret.f_[6] = 0.0f;
1629  ret.f_[10] = fCosine;
1630  ret.f_[14] = 0.0f;
1631  ret.f_[3] = 0.0f;
1632  ret.f_[7] = 0.0f;
1633  ret.f_[11] = 0.0f;
1634  ret.f_[15] = 1.0f;
1635  return ret;
1636  }
1637 
1638  static Mat4 RotationZ(const float fAngle)
1639  {
1640  Mat4 ret;
1641  float fCosine, fSine;
1642 
1643  fCosine = cosf(fAngle);
1644  fSine = sinf(fAngle);
1645 
1646  ret.f_[0] = fCosine;
1647  ret.f_[4] = fSine;
1648  ret.f_[8] = 0.0f;
1649  ret.f_[12] = 0.0f;
1650  ret.f_[1] = -fSine;
1651  ret.f_[5] = fCosine;
1652  ret.f_[9] = 0.0f;
1653  ret.f_[13] = 0.0f;
1654  ret.f_[2] = 0.0f;
1655  ret.f_[6] = 0.0f;
1656  ret.f_[10] = 1.0f;
1657  ret.f_[14] = 0.0f;
1658  ret.f_[3] = 0.0f;
1659  ret.f_[7] = 0.0f;
1660  ret.f_[11] = 0.0f;
1661  ret.f_[15] = 1.0f;
1662  return ret;
1663  }
1664 
1665  static Mat4 Scale(const float fX, const float fY, const float fZ)
1666  {
1667  Mat4 ret;
1668  ret.f_[0] = fX;
1669  ret.f_[1] = 0;
1670  ret.f_[2] = 0;
1671  ret.f_[3] = 0;
1672  ret.f_[4] = 0;
1673  ret.f_[5] = fY;
1674  ret.f_[6] = 0;
1675  ret.f_[7] = 0;
1676  ret.f_[8] = 0;
1677  ret.f_[9] = 0;
1678  ret.f_[10] = fZ;
1679  ret.f_[11] = 0;
1680  ret.f_[12] = 0;
1681  ret.f_[13] = 0;
1682  ret.f_[14] = 0;
1683  ret.f_[15] = 1.f;
1684  return ret;
1685  }
1686 
1687  static Mat4 Identity()
1688  {
1689  Mat4 ret;
1690  ret.f_[0] = 1.f;
1691  ret.f_[1] = 0;
1692  ret.f_[2] = 0;
1693  ret.f_[3] = 0;
1694  ret.f_[4] = 0;
1695  ret.f_[5] = 1.f;
1696  ret.f_[6] = 0;
1697  ret.f_[7] = 0;
1698  ret.f_[8] = 0;
1699  ret.f_[9] = 0;
1700  ret.f_[10] = 1.f;
1701  ret.f_[11] = 0;
1702  ret.f_[12] = 0;
1703  ret.f_[13] = 0;
1704  ret.f_[14] = 0;
1705  ret.f_[15] = 1.f;
1706  return ret;
1707  }
1708 
1709  static Mat4 Zero()
1710  {
1711  Mat4 ret;
1712 
1713  ret.f_[0] = 0.0f;
1714  ret.f_[1] = 0.0f;
1715  ret.f_[2] = 0.0f;
1716  ret.f_[3] = 0.0f;
1717  ret.f_[4] = 0.0f;
1718  ret.f_[5] = 0.0f;
1719  ret.f_[6] = 0.0f;
1720  ret.f_[7] = 0.0f;
1721  ret.f_[8] = 0.0f;
1722  ret.f_[9] = 0.0f;
1723  ret.f_[10] = 0.0f;
1724  ret.f_[11] = 0.0f;
1725  ret.f_[12] = 0.0f;
1726  ret.f_[13] = 0.0f;
1727  ret.f_[14] = 0.0f;
1728  ret.f_[15] = 0.0f;
1729  return ret;
1730  }
1731 
1732  void Dump()
1733  {
1734  printf("%f %f %f %f\n", f_[0], f_[1], f_[2], f_[3]);
1735  printf("%f %f %f %f\n", f_[4], f_[5], f_[6], f_[7]);
1736  printf("%f %f %f %f\n", f_[8], f_[9], f_[10], f_[11]);
1737  printf("%f %f %f %f\n", f_[12], f_[13], f_[14], f_[15]);
1738  }
1739  };
1740 
1741  /******************************************************************
1742  * Quaternion class
1743  *
1744  */
1746  {
1747  private:
1748  float x_, y_, z_, w_;
1749 
1750  public:
1751  friend class Vec3;
1752  friend class Vec4;
1753  friend class Mat4;
1754 
1756  {
1757  x_ = 0.f;
1758  y_ = 0.f;
1759  z_ = 0.f;
1760  w_ = 1.f;
1761  }
1762 
1763  Quaternion(const float fX, const float fY, const float fZ, const float fW)
1764  {
1765  x_ = fX;
1766  y_ = fY;
1767  z_ = fZ;
1768  w_ = fW;
1769  }
1770 
1771  Quaternion(const Vec3 vec, const float fW)
1772  {
1773  x_ = vec.x_;
1774  y_ = vec.y_;
1775  z_ = vec.z_;
1776  w_ = fW;
1777  }
1778 
1779  Quaternion(const float* p)
1780  {
1781  x_ = *p++;
1782  y_ = *p++;
1783  z_ = *p++;
1784  w_ = *p++;
1785  }
1786 
1788  {
1789  Quaternion ret;
1790  ret.x_ = x_ * rhs.w_ + y_ * rhs.z_ - z_ * rhs.y_ + w_ * rhs.x_;
1791  ret.y_ = -x_ * rhs.z_ + y_ * rhs.w_ + z_ * rhs.x_ + w_ * rhs.y_;
1792  ret.z_ = x_ * rhs.y_ - y_ * rhs.x_ + z_ * rhs.w_ + w_ * rhs.z_;
1793  ret.w_ = -x_ * rhs.x_ - y_ * rhs.y_ - z_ * rhs.z_ + w_ * rhs.w_;
1794  return ret;
1795  }
1796 
1798  {
1799  Quaternion ret;
1800  ret.x_ = x_ * rhs.w_ + y_ * rhs.z_ - z_ * rhs.y_ + w_ * rhs.x_;
1801  ret.y_ = -x_ * rhs.z_ + y_ * rhs.w_ + z_ * rhs.x_ + w_ * rhs.y_;
1802  ret.z_ = x_ * rhs.y_ - y_ * rhs.x_ + z_ * rhs.w_ + w_ * rhs.z_;
1803  ret.w_ = -x_ * rhs.x_ - y_ * rhs.y_ - z_ * rhs.z_ + w_ * rhs.w_;
1804  *this = ret;
1805  return *this;
1806  }
1807 
1809  {
1810  x_ = -x_;
1811  y_ = -y_;
1812  z_ = -z_;
1813  return *this;
1814  }
1815 
1816  //Non destuctive version
1818  {
1819  Quaternion ret;
1820  ret.x_ = -x_;
1821  ret.y_ = -y_;
1822  ret.z_ = -z_;
1823  ret.w_ = w_;
1824  return ret;
1825  }
1826 
1827  void ToMatrix(Mat4& mat)
1828  {
1829  float x2 = x_ * x_ * 2.0f;
1830  float y2 = y_ * y_ * 2.0f;
1831  float z2 = z_ * z_ * 2.0f;
1832  float xy = x_ * y_ * 2.0f;
1833  float yz = y_ * z_ * 2.0f;
1834  float zx = z_ * x_ * 2.0f;
1835  float xw = x_ * w_ * 2.0f;
1836  float yw = y_ * w_ * 2.0f;
1837  float zw = z_ * w_ * 2.0f;
1838 
1839  mat.f_[0] = 1.0f - y2 - z2;
1840  mat.f_[1] = xy + zw;
1841  mat.f_[2] = zx - yw;
1842  mat.f_[4] = xy - zw;
1843  mat.f_[5] = 1.0f - z2 - x2;
1844  mat.f_[6] = yz + xw;
1845  mat.f_[8] = zx + yw;
1846  mat.f_[9] = yz - xw;
1847  mat.f_[10] = 1.0f - x2 - y2;
1848 
1849  mat.f_[3] = mat.f_[7] = mat.f_[11] = mat.f_[12] = mat.f_[13] = mat.f_[14] = 0.0f;
1850  mat.f_[15] = 1.0f;
1851  }
1852 
1854  {
1855  float x2 = x_ * x_ * 2.0f;
1856  float y2 = y_ * y_ * 2.0f;
1857  float z2 = z_ * z_ * 2.0f;
1858  float xy = x_ * y_ * 2.0f;
1859  float yz = y_ * z_ * 2.0f;
1860  float zx = z_ * x_ * 2.0f;
1861  float xw = x_ * w_ * 2.0f;
1862  float yw = y_ * w_ * 2.0f;
1863  float zw = z_ * w_ * 2.0f;
1864 
1865  mat.f_[0] = 1.0f - y2 - z2;
1866  mat.f_[1] = xy + zw;
1867  mat.f_[2] = zx - yw;
1868  mat.f_[4] = xy - zw;
1869  mat.f_[5] = 1.0f - z2 - x2;
1870  mat.f_[6] = yz + xw;
1871  mat.f_[8] = zx + yw;
1872  mat.f_[9] = yz - xw;
1873  mat.f_[10] = 1.0f - x2 - y2;
1874 
1875  mat.f_[3] = mat.f_[7] = mat.f_[11] = 0.0f;
1876  mat.f_[15] = 1.0f;
1877  }
1878 
1879  static Quaternion RotationAxis(const Vec3 axis, const float angle)
1880  {
1881  Quaternion ret;
1882  float s = sinf(angle / 2);
1883  ret.x_ = s * axis.x_;
1884  ret.y_ = s * axis.y_;
1885  ret.z_ = s * axis.z_;
1886  ret.w_ = cosf(angle / 2);
1887  return ret;
1888  }
1889 
1890  void Value(float& fX, float& fY, float& fZ, float& fW)
1891  {
1892  fX = x_;
1893  fY = y_;
1894  fZ = z_;
1895  fW = w_;
1896  }
1897  };
1898 
1899 } //namespace ndk_helper
1900 #endif /* VECMATH_H_ */
Vec4 & operator*=(const float &rhs)
Definition: vecmath.h:678
void ToMatrixPreserveTranslate(Mat4 &mat)
Definition: vecmath.h:1853
Quaternion(const Vec3 vec, const float fW)
Definition: vecmath.h:1771
Vec3(const Vec2 &vec, float f)
Definition: vecmath.h:303
static Mat4 RotationX(const float fAngle)
Definition: vecmath.h:1584
Vec4 operator+(const Vec4 &rhs) const
Definition: vecmath.h:585
float Dot(const Vec3 &rhs)
Definition: vecmath.h:737
Mat3()
Definition: vecmath.h:779
void Value(float &fX, float &fY, float &fZ)
Definition: vecmath.h:500
Quaternion(const float fX, const float fY, const float fZ, const float fW)
Definition: vecmath.h:1763
Vec2 & operator+=(const Vec2 &rhs)
Definition: vecmath.h:118
Quaternion(const float *p)
Definition: vecmath.h:1779
Vec3 & operator/=(const Vec3 &rhs)
Definition: vecmath.h:377
Mat3 & operator-=(const Mat3 &rhs)
Definition: vecmath.h:840
Vec4 & operator+=(const Vec4 &rhs)
Definition: vecmath.h:605
Vec4(const float *pVec)
Definition: vecmath.h:556
Vec3 operator*(const float &rhs) const
Definition: vecmath.h:410
Mat3 & operator*=(const Mat3 &rhs)
Definition: vecmath.h:847
Mat3 & operator*=(const float rhs)
Definition: vecmath.h:874
Vec4 & operator-=(const Vec4 &rhs)
Definition: vecmath.h:614
static Mat4 Perspective(float fx, float fy, float cx, float cy, int w, int h, float n, float f)
Definition: vecmath.h:1421
Vec3 operator*(const Vec3 &rhs) const
Definition: vecmath.h:317
Mat3 & operator+=(const Mat3 &rhs)
Definition: vecmath.h:833
void Dump()
Definition: vecmath.h:257
void Dump()
Definition: vecmath.h:1732
Vec2 operator*(const Vec2 &rhs) const
Definition: vecmath.h:86
static Mat4 Identity()
Definition: vecmath.h:1687
Vec3 & operator*=(const float &rhs)
Definition: vecmath.h:419
#define PI
Definition: vecmath.h:28
Vec4 operator-(const Vec4 &rhs) const
Definition: vecmath.h:595
float w_
Definition: vecmath.h:520
static Mat4 Translation(const Vec3 vec)
Definition: vecmath.h:1562
Vec2 operator-(const Vec2 &rhs) const
Definition: vecmath.h:110
static Mat4 Perspective(float width, float height, float nearPlane, float farPlane)
Definition: vecmath.h:1342
Mat4 & PostTranslate(float tx, float ty, float tz)
Definition: vecmath.h:1258
Quaternion & operator*=(const Quaternion rhs)
Definition: vecmath.h:1797
Vec3 operator+(const Vec3 &rhs) const
Definition: vecmath.h:335
Definition: vecmath.h:50
friend class Vec4
Definition: vecmath.h:58
Vec3(const float fX, const float fY, const float fZ)
Definition: vecmath.h:282
Vec3 Normalize()
Definition: vecmath.h:465
Mat4 operator-(const Mat4 &rhs) const
Definition: vecmath.h:1064
Quaternion Conjugate()
Definition: vecmath.h:1808
Vec3 & operator/=(const float &rhs)
Definition: vecmath.h:436
Quaternion()
Definition: vecmath.h:1755
Vec2 operator/(const float &rhs) const
Definition: vecmath.h:190
float z_
Definition: vecmath.h:520
Vec4 operator/(const Vec4 &rhs) const
Definition: vecmath.h:575
static Mat3 Identity()
Definition: vecmath.h:943
friend Vec4 operator/(const float lhs, const Vec4 &rhs)
Definition: vecmath.h:657
friend Vec2 operator*(const float lhs, const Vec2 &rhs)
Definition: vecmath.h:152
Mat4 & operator-=(const Mat4 &rhs)
Definition: vecmath.h:1083
Definition: vecmath.h:267
float Dot(const Vec3 &rhs)
Definition: vecmath.h:474
Mat4 & operator*=(const Mat4 &rhs)
Definition: vecmath.h:1092
static Mat4 RotationZ(const float fAngle)
Definition: vecmath.h:1638
bool operator==(const Vec2 &rhs) const
Definition: vecmath.h:206
bool operator!=(const Vec3 &rhs) const
Definition: vecmath.h:452
Vec3 & operator+=(const Vec3 &rhs)
Definition: vecmath.h:353
bool Validate()
Definition: vecmath.h:751
void ToMatrix(Mat4 &mat)
Definition: vecmath.h:1827
Definition: vecmath.h:31
Vec3(const float *pVec)
Definition: vecmath.h:296
void Dump()
Definition: vecmath.h:507
Mat4 & operator+=(const Mat4 &rhs)
Definition: vecmath.h:1074
Vec4 & operator*=(const Vec4 &rhs)
Definition: vecmath.h:623
Vec4(const Vec3 &vec, const float fW)
Definition: vecmath.h:548
Mat4 & PostRotate(float angle, float rx, float ry, float rz)
Definition: vecmath.h:1267
Vec3 Cross(const Vec3 &rhs)
Definition: vecmath.h:484
Vec4 & operator/=(const float &rhs)
Definition: vecmath.h:697
float Length() const
Definition: vecmath.h:460
Mat4 operator+(const Mat4 &rhs) const
Definition: vecmath.h:1054
float x_
Definition: vecmath.h:520
float y_
Definition: vecmath.h:275
Vec2(const float fX, const float fY)
Definition: vecmath.h:67
friend Vec2 operator/(const float lhs, const Vec2 &rhs)
Definition: vecmath.h:160
Mat3 operator+(const Mat3 &rhs) const
Definition: vecmath.h:817
float Distance(const Vec2 &rhs)
Definition: vecmath.h:239
Mat3 operator-(const Mat3 &rhs) const
Definition: vecmath.h:825
static Mat3 Zero()
Definition: vecmath.h:959
Vec4(const float fX, const float fY, const float fZ, const float fW)
Definition: vecmath.h:532
Vec3(const Vec3 &vec)
Definition: vecmath.h:289
Vec3 & operator-=(const Vec3 &rhs)
Definition: vecmath.h:361
Vec2(const Vec2 &vec)
Definition: vecmath.h:73
Definition: vecmath.h:517
friend class Vec3
Definition: vecmath.h:57
Mat4 operator*(const float rhs)
Definition: vecmath.h:1135
static Mat4 RotationY(const float fAngle)
Definition: vecmath.h:1611
Vec3 operator/(const Vec3 &rhs) const
Definition: vecmath.h:326
static Mat4 Translation(const float fX, const float fY, const float fZ)
Definition: vecmath.h:1540
void Value(float &fX, float &fY)
Definition: vecmath.h:251
Mat3 Inverse()
Definition: vecmath.h:888
bool Validate()
Definition: vecmath.h:244
float Dot(const Vec2 &rhs)
Definition: vecmath.h:234
Mat3 Transpose()
Definition: vecmath.h:920
float Distance(const Vec3 &rhs)
Definition: vecmath.h:479
static Mat4 Perspective(float fovy, int width, int height, float zNear, float zFar)
Definition: vecmath.h:1390
Vec4 operator*(const Vec4 &rhs) const
Definition: vecmath.h:565
static Quaternion RotationAxis(const Vec3 axis, const float angle)
Definition: vecmath.h:1879
Vec2 & operator*=(const float &rhs)
Definition: vecmath.h:183
Vec4 operator*(const Vec4 &rhs) const
Definition: vecmath.h:1044
Vec2 operator+(const Vec2 &rhs) const
Definition: vecmath.h:102
friend Vec3 operator*(const float lhs, const Vec3 &rhs)
Definition: vecmath.h:391
Vec2 operator*(const float &rhs) const
Definition: vecmath.h:175
bool operator==(const Vec4 &rhs) const
Definition: vecmath.h:707
Vec4(const Vec4 &vec)
Definition: vecmath.h:540
Mat3(const float *mIn)
Definition: vecmath.h:785
Vec4 Normalize()
Definition: vecmath.h:727
friend Vec2 operator-(const Vec2 &rhs)
Definition: vecmath.h:147
Vec4 operator*(const float &rhs) const
Definition: vecmath.h:668
Vec2()
Definition: vecmath.h:62
Mat3 operator*(const float rhs)
Definition: vecmath.h:866
Vec2 operator/(const Vec2 &rhs) const
Definition: vecmath.h:94
Quaternion operator*(const Quaternion rhs)
Definition: vecmath.h:1787
Mat4()
Definition: vecmath.h:990
bool operator!=(const Vec4 &rhs) const
Definition: vecmath.h:714
static Mat4 Zero()
Definition: vecmath.h:1709
Vec4()
Definition: vecmath.h:527
Mat4 Transpose()
Definition: vecmath.h:1235
Definition: vecmath.h:1745
void Value(float &fX, float &fY, float &fZ, float &fW)
Definition: vecmath.h:758
Vec2 Normalize()
Definition: vecmath.h:226
float x_
Definition: vecmath.h:275
friend Vec4 operator-(const Vec4 &rhs)
Definition: vecmath.h:642
Definition: vecmath.h:771
Vec3()
Definition: vecmath.h:277
float y_
Definition: vecmath.h:54
float Length() const
Definition: vecmath.h:722
Vec4 & operator/=(const Vec4 &rhs)
Definition: vecmath.h:632
Vec3 operator/(const float &rhs) const
Definition: vecmath.h:427
Mat3 operator*(const Mat3 &rhs) const
Definition: vecmath.h:791
float y_
Definition: vecmath.h:520
Vec3 operator-(const Vec3 &rhs) const
Definition: vecmath.h:344
static Mat4 Scale(const float fX, const float fY, const float fZ)
Definition: vecmath.h:1665
static Mat4 Ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane)
Definition: vecmath.h:1470
bool operator!=(const Vec2 &rhs) const
Definition: vecmath.h:213
float * Ptr()
Definition: vecmath.h:938
Vec4 operator/(const float &rhs) const
Definition: vecmath.h:687
bool Validate()
Definition: vecmath.h:493
void Value(float &fX, float &fY, float &fZ, float &fW)
Definition: vecmath.h:1890
Vec2 & operator*=(const Vec2 &rhs)
Definition: vecmath.h:132
Quaternion Conjugated()
Definition: vecmath.h:1817
Vec3 Cross(const Vec3 &rhs)
Definition: vecmath.h:742
Mat4 & operator*=(const float rhs)
Definition: vecmath.h:1145
Mat4 & PostScale(float sx, float sy, float sz)
Definition: vecmath.h:1317
Vec3 operator*(const Vec3 &rhs) const
Definition: vecmath.h:809
static Mat4 LookAt(const Vec3 &vec_eye, const Vec3 &vec_at, const Vec3 &vec_up)
Definition: vecmath.h:1504
Vec2 & operator-=(const Vec2 &rhs)
Definition: vecmath.h:125
friend Vec3 operator/(const float lhs, const Vec3 &rhs)
Definition: vecmath.h:400
Vec2 & operator/=(const Vec2 &rhs)
Definition: vecmath.h:139
Mat4 operator*(const Mat4 &rhs) const
Definition: vecmath.h:1002
bool operator==(const Vec3 &rhs) const
Definition: vecmath.h:445
friend Vec3 operator-(const Vec3 &rhs)
Definition: vecmath.h:386
Vec2 & operator/=(const float &rhs)
Definition: vecmath.h:198
Mat4 & operator=(const Mat4 &rhs)
Definition: vecmath.h:1154
float * Ptr()
Definition: vecmath.h:1334
float x_
Definition: vecmath.h:53
Mat3 & operator=(const Mat3 &rhs)
Definition: vecmath.h:881
Definition: vecmath.h:980
Mat4(const float *mIn)
Definition: vecmath.h:996
float Length() const
Definition: vecmath.h:221
Mat4 Inverse()
Definition: vecmath.h:1163
bool operator<(const Vec2 &v) const
Definition: vecmath.h:169
friend Vec4 operator*(const float lhs, const Vec4 &rhs)
Definition: vecmath.h:647
Vec3 & operator*=(const Vec3 &rhs)
Definition: vecmath.h:369
Vec2(const float *pVec)
Definition: vecmath.h:79
float z_
Definition: vecmath.h:275