-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmath.h
1318 lines (1087 loc) · 25.2 KB
/
vmath.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef __VMATH_H__
#define __VMATH_H__
#define _USE_MATH_DEFINES 1 // Include constants defined in math.h
#include <math.h>
namespace vmath
{
template <typename T, const int w, const int h> class matNM;
template <typename T, const int len> class vecN;
template <typename T> class Tquaternion;
template <typename T>
inline T degrees(T angleInRadians)
{
return angleInRadians * static_cast<T>(180.0/M_PI);
}
template <typename T>
inline T radians(T angleInDegrees)
{
return angleInDegrees * static_cast<T>(M_PI/180.0);
}
template <typename T>
struct random
{
operator T ()
{
static unsigned int seed = 0x13371337;
unsigned int res;
unsigned int tmp;
seed *= 16807;
tmp = seed ^ (seed >> 4) ^ (seed << 15);
res = (tmp >> 9) | 0x3F800000;
return static_cast<T>(res);
}
};
template<>
struct random<float>
{
operator float()
{
static unsigned int seed = 0x13371337;
float res;
unsigned int tmp;
seed *= 16807;
tmp = seed ^ (seed >> 4) ^ (seed << 15);
*((unsigned int *) &res) = (tmp >> 9) | 0x3F800000;
return (res - 1.0f);
}
};
template<>
struct random<unsigned int>
{
operator unsigned int()
{
static unsigned int seed = 0x13371337;
unsigned int res;
unsigned int tmp;
seed *= 16807;
tmp = seed ^ (seed >> 4) ^ (seed << 15);
res = (tmp >> 9) | 0x3F800000;
return res;
}
};
template <typename T, const int len>
class vecN
{
public:
typedef class vecN<T,len> my_type;
typedef T element_type;
// Default constructor does nothing, just like built-in types
inline vecN()
{
// Uninitialized variable
}
// Copy constructor
inline vecN(const vecN& that)
{
assign(that);
}
// Construction from scalar
inline vecN(T s)
{
int n;
for (n = 0; n < len; n++)
{
data[n] = s;
}
}
// Assignment operator
inline vecN& operator=(const vecN& that)
{
assign(that);
return *this;
}
inline vecN& operator=(const T& that)
{
int n;
for (n = 0; n < len; n++)
data[n] = that;
return *this;
}
inline vecN operator+(const vecN& that) const
{
my_type result;
int n;
for (n = 0; n < len; n++)
result.data[n] = data[n] + that.data[n];
return result;
}
inline vecN& operator+=(const vecN& that)
{
return (*this = *this + that);
}
inline vecN operator-() const
{
my_type result;
int n;
for (n = 0; n < len; n++)
result.data[n] = -data[n];
return result;
}
inline vecN operator-(const vecN& that) const
{
my_type result;
int n;
for (n = 0; n < len; n++)
result.data[n] = data[n] - that.data[n];
return result;
}
inline vecN& operator-=(const vecN& that)
{
return (*this = *this - that);
}
inline vecN operator*(const vecN& that) const
{
my_type result;
int n;
for (n = 0; n < len; n++)
result.data[n] = data[n] * that.data[n];
return result;
}
inline vecN& operator*=(const vecN& that)
{
return (*this = *this * that);
}
inline vecN operator*(const T& that) const
{
my_type result;
int n;
for (n = 0; n < len; n++)
result.data[n] = data[n] * that;
return result;
}
inline vecN& operator*=(const T& that)
{
assign(*this * that);
return *this;
}
inline vecN operator/(const vecN& that) const
{
my_type result;
int n;
for (n = 0; n < len; n++)
result.data[n] = data[n] / that.data[n];
return result;
}
inline vecN& operator/=(const vecN& that)
{
assign(*this / that);
return *this;
}
inline vecN operator/(const T& that) const
{
my_type result;
int n;
for (n = 0; n < len; n++)
result.data[n] = data[n] / that;
return result;
}
inline vecN& operator/=(const T& that)
{
assign(*this / that);
return *this;
}
inline T& operator[](int n) { return data[n]; }
inline const T& operator[](int n) const { return data[n]; }
inline static int size(void) { return len; }
inline operator const T* () const { return &data[0]; }
static inline vecN random()
{
vecN result;
int i;
for (i = 0; i < len; i++)
{
result[i] = vmath::random<T>();
}
return result;
}
protected:
T data[len];
inline void assign(const vecN& that)
{
int n;
for (n = 0; n < len; n++)
data[n] = that.data[n];
}
};
template <typename T>
class Tvec2 : public vecN<T,2>
{
public:
typedef vecN<T,2> base;
// Uninitialized variable
inline Tvec2() {}
// Copy constructor
inline Tvec2(const base& v) : base(v) {}
// vec2(x, y);
inline Tvec2(T x, T y)
{
base::data[0] = x;
base::data[1] = y;
}
};
template <typename T>
class Tvec3 : public vecN<T,3>
{
public:
typedef vecN<T,3> base;
// Uninitialized variable
inline Tvec3() {}
// Copy constructor
inline Tvec3(const base& v) : base(v) {}
// vec3(x, y, z);
inline Tvec3(T x, T y, T z)
{
base::data[0] = x;
base::data[1] = y;
base::data[2] = z;
}
// vec3(v, z);
inline Tvec3(const Tvec2<T>& v, T z)
{
base::data[0] = v[0];
base::data[1] = v[1];
base::data[2] = z;
}
// vec3(x, v)
inline Tvec3(T x, const Tvec2<T>& v)
{
base::data[0] = x;
base::data[1] = v[0];
base::data[2] = v[1];
}
};
template <typename T>
class Tvec4 : public vecN<T,4>
{
public:
typedef vecN<T,4> base;
// Uninitialized variable
inline Tvec4() {}
// Copy constructor
inline Tvec4(const base& v) : base(v) {}
// vec4(x, y, z, w);
inline Tvec4(T x, T y, T z, T w)
{
base::data[0] = x;
base::data[1] = y;
base::data[2] = z;
base::data[3] = w;
}
// vec4(v, z, w);
inline Tvec4(const Tvec2<T>& v, T z, T w)
{
base::data[0] = v[0];
base::data[1] = v[1];
base::data[2] = z;
base::data[3] = w;
}
// vec4(x, v, w);
inline Tvec4(T x, const Tvec2<T>& v, T w)
{
base::data[0] = x;
base::data[1] = v[0];
base::data[2] = v[1];
base::data[3] = w;
}
// vec4(x, y, v);
inline Tvec4(T x, T y, const Tvec2<T>& v)
{
base::data[0] = x;
base::data[1] = y;
base::data[2] = v[0];
base::data[3] = v[1];
}
// vec4(v1, v2);
inline Tvec4(const Tvec2<T>& u, const Tvec2<T>& v)
{
base::data[0] = u[0];
base::data[1] = u[1];
base::data[2] = v[0];
base::data[3] = v[1];
}
// vec4(v, w);
inline Tvec4(const Tvec3<T>& v, T w)
{
base::data[0] = v[0];
base::data[1] = v[1];
base::data[2] = v[2];
base::data[3] = w;
}
// vec4(x, v);
inline Tvec4(T x, const Tvec3<T>& v)
{
base::data[0] = x;
base::data[1] = v[0];
base::data[2] = v[1];
base::data[3] = v[2];
}
};
// These types don't exist in GLSL and don't have full implementations
// (constructors and such). This is enough to get some template functions
// to compile correctly.
typedef vecN<float, 1> vec1;
typedef vecN<int, 1> ivec1;
typedef vecN<unsigned int, 1> uvec1;
typedef vecN<double, 1> dvec1;
typedef Tvec2<float> vec2;
typedef Tvec2<int> ivec2;
typedef Tvec2<unsigned int> uvec2;
typedef Tvec2<double> dvec2;
typedef Tvec3<float> vec3;
typedef Tvec3<int> ivec3;
typedef Tvec3<unsigned int> uvec3;
typedef Tvec3<double> dvec3;
typedef Tvec4<float> vec4;
typedef Tvec4<int> ivec4;
typedef Tvec4<unsigned int> uvec4;
typedef Tvec4<double> dvec4;
template <typename T, int n>
static inline const vecN<T,n> operator * (T x, const vecN<T,n>& v)
{
return v * x;
}
template <typename T>
static inline const Tvec2<T> operator / (T x, const Tvec2<T>& v)
{
return Tvec2<T>(x / v[0], x / v[1]);
}
template <typename T>
static inline const Tvec3<T> operator / (T x, const Tvec3<T>& v)
{
return Tvec3<T>(x / v[0], x / v[1], x / v[2]);
}
template <typename T>
static inline const Tvec4<T> operator / (T x, const Tvec4<T>& v)
{
return Tvec4<T>(x / v[0], x / v[1], x / v[2], x / v[3]);
}
template <typename T, int len>
static inline T dot(const vecN<T,len>& a, const vecN<T,len>& b)
{
int n;
T total = T(0);
for (n = 0; n < len; n++)
{
total += a[n] * b[n];
}
return total;
}
template <typename T>
static inline vecN<T,3> cross(const vecN<T,3>& a, const vecN<T,3>& b)
{
return Tvec3<T>(a[1] * b[2] - b[1] * a[2],
a[2] * b[0] - b[2] * a[0],
a[0] * b[1] - b[0] * a[1]);
}
template <typename T, int len>
static inline T length(const vecN<T,len>& v)
{
T result(0);
for (int i = 0; i < v.size(); ++i)
{
result += v[i] * v[i];
}
return (T)sqrt(result);
}
template <typename T, int len>
static inline vecN<T,len> normalize(const vecN<T,len>& v)
{
return v / length(v);
}
template <typename T, int len>
static inline T distance(const vecN<T,len>& a, const vecN<T,len>& b)
{
return length(b - a);
}
template <typename T, int len>
static inline T angle(const vecN<T,len>& a, const vecN<T,len>& b)
{
return arccos(dot(a, b));
}
template <typename T>
class Tquaternion
{
public:
inline Tquaternion()
{
}
inline Tquaternion(const Tquaternion& q)
: r(q.r),
v(q.v)
{
}
inline Tquaternion(T _r)
: r(_r),
v(T(0))
{
}
inline Tquaternion(T _r, const Tvec3<T>& _v)
: r(_r),
v(_v)
{
}
inline Tquaternion(const Tvec4<T>& _v)
: r(_v[0]),
v(_v[1], _v[2], _v[3])
{
}
inline Tquaternion(T _x, T _y, T _z, T _w)
: r(_x),
v(_y, _z, _w)
{
}
inline T& operator[](int n)
{
return a[n];
}
inline const T& operator[](int n) const
{
return a[n];
}
inline Tquaternion operator+(const Tquaternion& q) const
{
return quaternion(r + q.r, v + q.v);
}
inline Tquaternion& operator+=(const Tquaternion& q)
{
r += q.r;
v += q.v;
return *this;
}
inline Tquaternion operator-(const Tquaternion& q) const
{
return quaternion(r - q.r, v - q.v);
}
inline Tquaternion& operator-=(const Tquaternion& q)
{
r -= q.r;
v -= q.v;
return *this;
}
inline Tquaternion operator-() const
{
return Tquaternion(-r, -v);
}
inline Tquaternion operator*(const T s) const
{
return Tquaternion(a[0] * s, a[1] * s, a[2] * s, a[3] * s);
}
inline Tquaternion& operator*=(const T s)
{
r *= s;
v *= s;
return *this;
}
inline Tquaternion operator*(const Tquaternion& q) const
{
const T x1 = a[0];
const T y1 = a[1];
const T z1 = a[2];
const T w1 = a[3];
const T x2 = q.a[0];
const T y2 = q.a[1];
const T z2 = q.a[2];
const T w2 = q.a[3];
return Tquaternion(w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2,
w1 * y2 + y1 * w2 + z1 * x2 - x1 * z2,
w1 * z2 + z1 * w2 + x1 * y2 - y1 * x2,
w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2);
}
inline Tquaternion operator/(const T s) const
{
return Tquaternion(a[0] / s, a[1] / s, a[2] / s, a[3] / s);
}
inline Tquaternion inverse() const
{
return (Tquaternion(-x, -y, -z, w)/
(pow(x, 2.f) + pow(y, 2.f) + pow(z, 2.f)
+ pow(w, 2.f)));
}
inline Tquaternion& operator/=(const T s)
{
r /= s;
v /= s;
return *this;
}
inline operator Tvec4<T>&()
{
return *(Tvec4<T>*)&a[0];
}
inline operator const Tvec4<T>&() const
{
return *(const Tvec4<T>*)&a[0];
}
inline bool operator==(const Tquaternion& q) const
{
return (r == q.r) && (v == q.v);
}
inline bool operator!=(const Tquaternion& q) const
{
return (r != q.r) || (v != q.v);
}
inline matNM<T,4,4> asMatrix() const
{
matNM<T,4,4> m;
const T xx = x * x;
const T yy = y * y;
const T zz = z * z;
const T ww = w * w;
const T xy = x * y;
const T xz = x * z;
const T xw = x * w;
const T yz = y * z;
const T yw = y * w;
const T zw = z * w;
m[0][0] = T(1) - T(2) * (yy + zz);
m[0][1] = T(2) * (xy - zw);
m[0][2] = T(2) * (xz + yw);
m[0][3] = T(0);
m[1][0] = T(2) * (xy + zw);
m[1][1] = T(1) - T(2) * (xx + zz);
m[1][2] = T(2) * (yz - xw);
m[1][3] = T(0);
m[2][0] = T(2) * (xz - yw);
m[2][1] = T(2) * (yz + xw);
m[2][2] = T(1) - T(2) * (xx + yy);
m[2][3] = T(0);
m[3][0] = T(0);
m[3][1] = T(0);
m[3][2] = T(0);
m[3][3] = T(1);
return m;
}
inline T length() const
{
return vmath::length( Tvec4<T>(r, v) );
}
private:
union
{
struct
{
T r;
Tvec3<T> v;
};
struct
{
T x;
T y;
T z;
T w;
};
T a[4];
};
};
typedef Tquaternion<float> quaternion;
typedef Tquaternion<int> iquaternion;
typedef Tquaternion<unsigned int> uquaternion;
typedef Tquaternion<double> dquaternion;
template <typename T>
static inline Tquaternion<T> operator*(T a, const Tquaternion<T>& b)
{
return b * a;
}
template <typename T>
static inline Tquaternion<T> operator/(T a, const Tquaternion<T>& b)
{
return Tquaternion<T>(a / b[0], a / b[1], a / b[2], a / b[3]);
}
template <typename T>
static inline Tquaternion<T> normalize(const Tquaternion<T>& q)
{
return q / length(vecN<T,4>(q));
}
template <typename T, const int w, const int h>
class matNM
{
public:
typedef class matNM<T,w,h> my_type;
typedef class vecN<T,h> vector_type;
// Default constructor does nothing, just like built-in types
inline matNM()
{
// Uninitialized variable
}
// Copy constructor
inline matNM(const matNM& that)
{
assign(that);
}
// Construction from element type
// explicit to prevent assignment from T
explicit inline matNM(T f)
{
for (int n = 0; n < w; n++)
{
data[n] = f;
}
}
// Construction from vector
inline matNM(const vector_type& v)
{
for (int n = 0; n < w; n++)
{
data[n] = v;
}
}
// Assignment operator
inline matNM& operator=(const my_type& that)
{
assign(that);
return *this;
}
inline matNM operator+(const my_type& that) const
{
my_type result;
int n;
for (n = 0; n < w; n++)
result.data[n] = data[n] + that.data[n];
return result;
}
inline my_type& operator+=(const my_type& that)
{
return (*this = *this + that);
}
inline my_type operator-(const my_type& that) const
{
my_type result;
int n;
for (n = 0; n < w; n++)
result.data[n] = data[n] - that.data[n];
return result;
}
inline my_type& operator-=(const my_type& that)
{
return (*this = *this - that);
}
inline my_type operator*(const T& that) const
{
my_type result;
int n;
for (n = 0; n < w; n++)
result.data[n] = data[n] * that;
return result;
}
inline my_type& operator*=(const T& that)
{
int n;
for (n = 0; n < w; n++)
data[n] = data[n] * that;
return *this;
}
// Matrix multiply.
// TODO: This only works for square matrices. Need more template skill to make a non-square version.
inline my_type operator*(const my_type& that) const
{
my_type result(0);
for (int j = 0; j < w; j++)
{
for (int i = 0; i < h; i++)
{
T sum(0);
for (int n = 0; n < w; n++)
{
sum += data[n][i] * that[j][n];
}
result[j][i] = sum;
}
}
return result;
}
inline my_type& operator*=(const my_type& that)
{
return (*this = *this * that);
}
inline vector_type& operator[](int n) { return data[n]; }
inline const vector_type& operator[](int n) const { return data[n]; }
inline operator T*() { return &data[0][0]; }
inline operator const T*() const { return &data[0][0]; }
inline matNM<T,h,w> transpose(void) const
{
matNM<T,h,w> result;
int x, y;
for (y = 0; y < w; y++)
{
for (x = 0; x < h; x++)
{
result[x][y] = data[y][x];
}
}
return result;
}
static inline my_type identity()
{
my_type result(0);
for (int i = 0; i < w; i++)
{
result[i][i] = 1;
}
return result;
}
static inline int width(void) { return w; }
static inline int height(void) { return h; }
protected:
// Column primary data (essentially, array of vectors)
vecN<T,h> data[w];
// Assignment function - called from assignment operator and copy constructor.
inline void assign(const matNM& that)
{
int n;
for (n = 0; n < w; n++)
data[n] = that.data[n];
}
};
/*
template <typename T, const int N>
class TmatN : public matNM<T,N,N>
{
public:
typedef matNM<T,N,N> base;
typedef TmatN<T,N> my_type;
inline TmatN() {}
inline TmatN(const my_type& that) : base(that) {}
inline TmatN(float f) : base(f) {}
inline TmatN(const vecN<T,4>& v) : base(v) {}
inline my_type transpose(void)
{
my_type result;
int x, y;
for (y = 0; y < h; y++)
{
for (x = 0; x < h; x++)
{
result[x][y] = data[y][x];
}
}
return result;
}
};
*/
template <typename T>
class Tmat4 : public matNM<T,4,4>
{
public:
typedef matNM<T,4,4> base;
typedef Tmat4<T> my_type;
inline Tmat4() {}
inline Tmat4(const my_type& that) : base(that) {}
inline Tmat4(const base& that) : base(that) {}
inline Tmat4(const vecN<T,4>& v) : base(v) {}
inline Tmat4(const vecN<T,4>& v0,
const vecN<T,4>& v1,
const vecN<T,4>& v2,
const vecN<T,4>& v3)
{
base::data[0] = v0;
base::data[1] = v1;
base::data[2] = v2;
base::data[3] = v3;
}
};
typedef Tmat4<float> mat4;
typedef Tmat4<int> imat4;
typedef Tmat4<unsigned int> umat4;
typedef Tmat4<double> dmat4;
template <typename T>
class Tmat3 : public matNM<T,3,3>
{
public:
typedef matNM<T,3,3> base;
typedef Tmat3<T> my_type;
inline Tmat3() {}
inline Tmat3(const my_type& that) : base(that) {}
inline Tmat3(const base& that) : base(that) {}
inline Tmat3(const vecN<T,3>& v) : base(v) {}
inline Tmat3(const vecN<T,3>& v0,
const vecN<T,3>& v1,
const vecN<T,3>& v2)
{
base::data[0] = v0;
base::data[1] = v1;
base::data[2] = v2;
}
};
typedef Tmat3<float> mat3;
typedef Tmat3<int> imat3;
typedef Tmat3<unsigned int>umat3;
typedef Tmat3<double> dmat3;
template <typename T>
class Tmat2 : public matNM<T,2,2>
{
public:
typedef matNM<T,2,2> base;
typedef Tmat2<T> my_type;
inline Tmat2() {}
inline Tmat2(const my_type& that) : base(that) {}
inline Tmat2(const base& that) : base(that) {}
inline Tmat2(const vecN<T,2>& v) : base(v) {}
inline Tmat2(const vecN<T,2>& v0,
const vecN<T,2>& v1)
{
base::data[0] = v0;
base::data[1] = v1;
}
};
typedef Tmat2<float> mat2;