-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrsMatrix.cpp
573 lines (494 loc) · 15.7 KB
/
rsMatrix.cpp
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
/*
* Copyright (C) 1999-2010 Terence M. Welsh
*
* This file is part of rsMath.
*
* rsMath is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* rsMath is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "rsMatrix.h"
#include "rsMath.h"
#include <math.h>
rsMatrix::rsMatrix(){
}
rsMatrix::~rsMatrix(){
}
void rsMatrix::identity(){
m[0] = 1.0f;
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;
m[4] = 0.0f;
m[5] = 1.0f;
m[6] = 0.0f;
m[7] = 0.0f;
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = 1.0f;
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
}
void rsMatrix::set(float* mat){
int i;
for(i=0; i<16; i++)
m[i] = mat[i];
}
void rsMatrix::get(float* mat){
int i;
for(i=0; i<16; i++)
mat[i] = m[i];
}
float* rsMatrix::get(){
return m;
}
void rsMatrix::copy(const rsMatrix &mat){
int i;
for(i=0; i<16; i++)
m[i] = mat[i];
}
void rsMatrix::preMult(const rsMatrix &postMat){
const float preMat0(m[0]);
const float preMat1(m[1]);
const float preMat2(m[2]);
const float preMat3(m[3]);
const float preMat4(m[4]);
const float preMat5(m[5]);
const float preMat6(m[6]);
const float preMat7(m[7]);
const float preMat8(m[8]);
const float preMat9(m[9]);
const float preMat10(m[10]);
const float preMat11(m[11]);
const float preMat12(m[12]);
const float preMat13(m[13]);
const float preMat14(m[14]);
const float preMat15(m[15]);
m[0] = preMat0 * postMat[0] + preMat4 * postMat[1] + preMat8 * postMat[2] + preMat12 * postMat[3];
m[1] = preMat1 * postMat[0] + preMat5 * postMat[1] + preMat9 * postMat[2] + preMat13 * postMat[3];
m[2] = preMat2 * postMat[0] + preMat6 * postMat[1] + preMat10 * postMat[2] + preMat14 * postMat[3];
m[3] = preMat3 * postMat[0] + preMat7 * postMat[1] + preMat11 * postMat[2] + preMat15 * postMat[3];
m[4] = preMat0 * postMat[4] + preMat4 * postMat[5] + preMat8 * postMat[6] + preMat12 * postMat[7];
m[5] = preMat1 * postMat[4] + preMat5 * postMat[5] + preMat9 * postMat[6] + preMat13 * postMat[7];
m[6] = preMat2 * postMat[4] + preMat6 * postMat[5] + preMat10 * postMat[6] + preMat14 * postMat[7];
m[7] = preMat3 * postMat[4] + preMat7 * postMat[5] + preMat11 * postMat[6] + preMat15 * postMat[7];
m[8] = preMat0 * postMat[8] + preMat4 * postMat[9] + preMat8 * postMat[10] + preMat12 * postMat[11];
m[9] = preMat1 * postMat[8] + preMat5 * postMat[9] + preMat9 * postMat[10] + preMat13 * postMat[11];
m[10] = preMat2 * postMat[8] + preMat6 * postMat[9] + preMat10 * postMat[10] + preMat14 * postMat[11];
m[11] = preMat3 * postMat[8] + preMat7 * postMat[9] + preMat11 * postMat[10] + preMat15 * postMat[11];
m[12] = preMat0 * postMat[12] + preMat4 * postMat[13] + preMat8 * postMat[14] + preMat12 * postMat[15];
m[13] = preMat1 * postMat[12] + preMat5 * postMat[13] + preMat9 * postMat[14] + preMat13 * postMat[15];
m[14] = preMat2 * postMat[12] + preMat6 * postMat[13] + preMat10 * postMat[14] + preMat14 * postMat[15];
m[15] = preMat3 * postMat[12] + preMat7 * postMat[13] + preMat11 * postMat[14] + preMat15 * postMat[15];
}
void rsMatrix::postMult(const rsMatrix &preMat){
const float postMat0(m[0]);
const float postMat1(m[1]);
const float postMat2(m[2]);
const float postMat3(m[3]);
const float postMat4(m[4]);
const float postMat5(m[5]);
const float postMat6(m[6]);
const float postMat7(m[7]);
const float postMat8(m[8]);
const float postMat9(m[9]);
const float postMat10(m[10]);
const float postMat11(m[11]);
const float postMat12(m[12]);
const float postMat13(m[13]);
const float postMat14(m[14]);
const float postMat15(m[15]);
m[0] = preMat[0] * postMat0 + preMat[4] * postMat1 + preMat[8] * postMat2 + preMat[12] * postMat3;
m[1] = preMat[1] * postMat0 + preMat[5] * postMat1 + preMat[9] * postMat2 + preMat[13] * postMat3;
m[2] = preMat[2] * postMat0 + preMat[6] * postMat1 + preMat[10] * postMat2 + preMat[14] * postMat3;
m[3] = preMat[3] * postMat0 + preMat[7] * postMat1 + preMat[11] * postMat2 + preMat[15] * postMat3;
m[4] = preMat[0] * postMat4 + preMat[4] * postMat5 + preMat[8] * postMat6 + preMat[12] * postMat7;
m[5] = preMat[1] * postMat4 + preMat[5] * postMat5 + preMat[9] * postMat6 + preMat[13] * postMat7;
m[6] = preMat[2] * postMat4 + preMat[6] * postMat5 + preMat[10] * postMat6 + preMat[14] * postMat7;
m[7] = preMat[3] * postMat4 + preMat[7] * postMat5 + preMat[11] * postMat6 + preMat[15] * postMat7;
m[8] = preMat[0] * postMat8 + preMat[4] * postMat9 + preMat[8] * postMat10 + preMat[12] * postMat11;
m[9] = preMat[1] * postMat8 + preMat[5] * postMat9 + preMat[9] * postMat10 + preMat[13] * postMat11;
m[10] = preMat[2] * postMat8 + preMat[6] * postMat9 + preMat[10] * postMat10 + preMat[14] * postMat11;
m[11] = preMat[3] * postMat8 + preMat[7] * postMat9 + preMat[11] * postMat10 + preMat[15] * postMat11;
m[12] = preMat[0] * postMat12 + preMat[4] * postMat13 + preMat[8] * postMat14 + preMat[12] * postMat15;
m[13] = preMat[1] * postMat12 + preMat[5] * postMat13 + preMat[9] * postMat14 + preMat[13] * postMat15;
m[14] = preMat[2] * postMat12 + preMat[6] * postMat13 + preMat[10] * postMat14 + preMat[14] * postMat15;
m[15] = preMat[3] * postMat12 + preMat[7] * postMat13 + preMat[11] * postMat14 + preMat[15] * postMat15;
}
void rsMatrix::makeTranslate(float x, float y, float z){
m[0] = 1.0f;
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;
m[4] = 0.0f;
m[5] = 1.0f;
m[6] = 0.0f;
m[7] = 0.0f;
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = 1.0f;
m[11] = 0.0f;
m[12] = x;
m[13] = y;
m[14] = z;
m[15] = 1.0f;
}
void rsMatrix::makeTranslate(float *p){
m[0] = 1.0f;
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;
m[4] = 0.0f;
m[5] = 1.0f;
m[6] = 0.0f;
m[7] = 0.0f;
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = 1.0f;
m[11] = 0.0f;
m[12] = p[0];
m[13] = p[1];
m[14] = p[2];
m[15] = 1.0f;
}
void rsMatrix::makeTranslate(const rsVec &vec){
m[0] = 1.0f;
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;
m[4] = 0.0f;
m[5] = 1.0f;
m[6] = 0.0f;
m[7] = 0.0f;
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = 1.0f;
m[11] = 0.0f;
m[12] = vec[0];
m[13] = vec[1];
m[14] = vec[2];
m[15] = 1.0f;
}
void rsMatrix::makeScale(float s){
m[0] = s;
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;
m[4] = 0.0f;
m[5] = s;
m[6] = 0.0f;
m[7] = 0.0f;
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = s;
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
}
void rsMatrix::makeScale(float x, float y, float z){
m[0] = x;
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;
m[4] = 0.0f;
m[5] = y;
m[6] = 0.0f;
m[7] = 0.0f;
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = z;
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
}
void rsMatrix::makeScale(float* s){
m[0] = s[0];
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;
m[4] = 0.0f;
m[5] = s[1];
m[6] = 0.0f;
m[7] = 0.0f;
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = s[2];
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
}
void rsMatrix::makeScale(const rsVec &vec){
m[0] = vec[0];
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;
m[4] = 0.0f;
m[5] = vec[1];
m[6] = 0.0f;
m[7] = 0.0f;
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = vec[2];
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
}
void rsMatrix::makeRotate(float a, float x, float y, float z){
rsQuat q;
q.make(a, x, y, z);
q.toMat(m);
}
void rsMatrix::makeRotate(float a, const rsVec &v){
rsQuat q;
q.make(a, v);
q.toMat(m);
}
void rsMatrix::makeRotate(rsQuat &q){
q.toMat(m);
}
void rsMatrix::translate(float x, float y, float z){
rsMatrix mat;
mat.makeTranslate(x, y, z);
this->postMult(mat);
}
void rsMatrix::translate(float *p){
rsMatrix mat;
mat.makeTranslate(p);
this->postMult(mat);
}
void rsMatrix::translate(const rsVec &vec){
rsMatrix mat;
mat.makeTranslate(vec);
this->postMult(mat);
}
void rsMatrix::scale(float s){
rsMatrix mat;
mat.makeScale(s);
this->postMult(mat);
}
void rsMatrix::scale(float x, float y, float z){
rsMatrix mat;
mat.makeScale(x, y, z);
this->postMult(mat);
}
void rsMatrix::scale(float* s){
rsMatrix mat;
mat.makeScale(s);
this->postMult(mat);
}
void rsMatrix::scale(const rsVec &vec){
rsMatrix mat;
mat.makeScale(vec);
this->postMult(mat);
}
void rsMatrix::rotate(float a, float x, float y, float z){
rsMatrix mat;
mat.makeRotate(a, x, y, z);
this->postMult(mat);
}
void rsMatrix::rotate(float a, const rsVec &v){
rsMatrix mat;
mat.makeRotate(a, v);
this->postMult(mat);
}
void rsMatrix::rotate(rsQuat &q){
rsMatrix mat;
mat.makeRotate(q);
this->postMult(mat);
}
float rsMatrix::determinant3(const float aa, const float ab, const float ac,
const float ba, const float bb, const float bc,
const float ca, const float cb, const float cc){
return (aa * bb * cc) + (ab * bc * ca) + (ac * ba * cb)
- (aa * bc * cb) - (ab * ba * cc) - (ac * bb * ca);
}
bool rsMatrix::invert(){
const float aa(m[0]);
const float ba(m[1]);
const float ca(m[2]);
const float da(m[3]);
const float ab(m[4]);
const float bb(m[5]);
const float cb(m[6]);
const float db(m[7]);
const float ac(m[8]);
const float bc(m[9]);
const float cc(m[10]);
const float dc(m[11]);
const float ad(m[12]);
const float bd(m[13]);
const float cd(m[14]);
const float dd(m[15]);
// calculate determinant
const float det3_1(determinant3(bb, bc, bd, cb, cc, cd, db, dc, dd));
const float det3_2(-determinant3(ab, ac, ad, cb, cc, cd, db, dc, dd));
const float det3_3(determinant3(ab, ac, ad, bb, bc, bd, db, dc, dd));
const float det3_4(-determinant3(ab, ac, ad, bb, bc, bd, cb, cc, cd));
const float det(aa * det3_1 + ba * det3_2 + ca * det3_3 + da * det3_4);
if(fabs(det) < RS_EPSILON)
return false; // matrix is singular, cannot be inverted
// reciprocal of determinant
const float rec_det(1.0f / det);
// calculate inverted matrix
m[0] = det3_1 * rec_det;
m[4] = det3_2 * rec_det;
m[8] = det3_3 * rec_det;
m[12] = det3_4 * rec_det;
m[1] = - determinant3(ba, bc, bd, ca, cc, cd, da, dc, dd) * rec_det;
m[5] = determinant3(aa, ac, ad, ca, cc, cd, da, dc, dd) * rec_det;
m[9] = - determinant3(aa, ac, ad, ba, bc, bd, da, dc, dd) * rec_det;
m[13] = determinant3(aa, ac, ad, ba, bc, bd, ca, cc, cd) * rec_det;
m[2] = determinant3(ba, bb, bd, ca, cb, cd, da, db, dd) * rec_det;
m[6] = - determinant3(aa, ab, ad, ca, cb, cd, da, db, dd) * rec_det;
m[10] = determinant3(aa, ab, ad, ba, bb, bd, da, db, dd) * rec_det;
m[14] = - determinant3(aa, ab, ad, ba, bb, bd, ca, cb, cd) * rec_det;
m[3] = - determinant3(ba, bb, bc, ca, cb, cc, da, db, dc) * rec_det;
m[7] = determinant3(aa, ab, ac, ca, cb, cc, da, db, dc) * rec_det;
m[11] = - determinant3(aa, ab, ac, ba, bb, bc, da, db, dc) * rec_det;
m[15] = determinant3(aa, ab, ac, ba, bb, bc, ca, cb, cc) * rec_det;
return true;
}
bool rsMatrix::invert(const rsMatrix &mat){
const float aa(mat[0]);
const float ba(mat[1]);
const float ca(mat[2]);
const float da(mat[3]);
const float ab(mat[4]);
const float bb(mat[5]);
const float cb(mat[6]);
const float db(mat[7]);
const float ac(mat[8]);
const float bc(mat[9]);
const float cc(mat[10]);
const float dc(mat[11]);
const float ad(mat[12]);
const float bd(mat[13]);
const float cd(mat[14]);
const float dd(mat[15]);
// calculate determinant
const float det3_1(determinant3(bb, bc, bd, cb, cc, cd, db, dc, dd));
const float det3_2(-determinant3(ab, ac, ad, cb, cc, cd, db, dc, dd));
const float det3_3(determinant3(ab, ac, ad, bb, bc, bd, db, dc, dd));
const float det3_4(-determinant3(ab, ac, ad, bb, bc, bd, cb, cc, cd));
const float det(aa * det3_1 + ba * det3_2 + ca * det3_3 + da * det3_4);
if(fabs(det) < RS_EPSILON)
return false; // matrix is singular, cannot be inverted
// reciprocal of determinant
const float rec_det(1.0f / det);
// calculate inverted matrix
m[0] = det3_1 * rec_det;
m[4] = det3_2 * rec_det;
m[8] = det3_3 * rec_det;
m[12] = det3_4 * rec_det;
m[1] = - determinant3(ba, bc, bd, ca, cc, cd, da, dc, dd) * rec_det;
m[5] = determinant3(aa, ac, ad, ca, cc, cd, da, dc, dd) * rec_det;
m[9] = - determinant3(aa, ac, ad, ba, bc, bd, da, dc, dd) * rec_det;
m[13] = determinant3(aa, ac, ad, ba, bc, bd, ca, cc, cd) * rec_det;
m[2] = determinant3(ba, bb, bd, ca, cb, cd, da, db, dd) * rec_det;
m[6] = - determinant3(aa, ab, ad, ca, cb, cd, da, db, dd) * rec_det;
m[10] = determinant3(aa, ab, ad, ba, bb, bd, da, db, dd) * rec_det;
m[14] = - determinant3(aa, ab, ad, ba, bb, bd, ca, cb, cd) * rec_det;
m[3] = - determinant3(ba, bb, bc, ca, cb, cc, da, db, dc) * rec_det;
m[7] = determinant3(aa, ab, ac, ca, cb, cc, da, db, dc) * rec_det;
m[11] = - determinant3(aa, ab, ac, ba, bb, bc, da, db, dc) * rec_det;
m[15] = determinant3(aa, ab, ac, ba, bb, bc, ca, cb, cc) * rec_det;
return true;
}
void rsMatrix::rotationInvert(const rsMatrix &mat){
float det = mat[0] * mat[5] * mat[10]
+ mat[4] * mat[9] * mat[2]
+ mat[8] * mat[1] * mat[6]
- mat[2] * mat[5] * mat[8]
- mat[6] * mat[9] * mat[0]
- mat[10] * mat[1] * mat[4];
m[0] = (mat[5] * mat[10] - mat[6] * mat[9]) / det;
m[1] = (mat[6] * mat[8] - mat[4] * mat[10]) / det;
m[2] = (mat[4] * mat[9] - mat[5] * mat[8]) / det;
m[4] = (mat[9] * mat[2] - mat[10] * mat[1]) / det;
m[5] = (mat[10] * mat[0] - mat[8] * mat[2]) / det;
m[6] = (mat[8] * mat[1] - mat[9] * mat[0]) / det;
m[8] = (mat[1] * mat[6] - mat[2] * mat[5]) / det;
m[9] = (mat[2] * mat[4] - mat[0] * mat[6]) / det;
m[10] = (mat[0] * mat[5] - mat[1] * mat[4]) / det;
m[3] = m[7] = m[11] = m[12] = m[13] = m[14] = 0.0f;
m[15] = 1.0f;
}
void rsMatrix::fromQuat(const rsQuat &q){
float s, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
// must have an axis
if(q[0] == 0.0f && q[1] == 0.0f && q[2] == 0.0f){
identity();
return;
}
s = 2.0f / (q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);
xs = q[0] * s;
ys = q[1] * s;
zs = q[2] * s;
wx = q[3] * xs;
wy = q[3] * ys;
wz = q[3] * zs;
xx = q[0] * xs;
xy = q[0] * ys;
xz = q[0] * zs;
yy = q[1] * ys;
yz = q[1] * zs;
zz = q[2] * zs;
m[0] = 1.0f - yy - zz;
m[1] = xy + wz;
m[2] = xz - wy;
m[3] = 0.0f;
m[4] = xy - wz;
m[5] = 1.0f - xx - zz;
m[6] = yz + wx;
m[7] = 0.0f;
m[8] = xz + wy;
m[9] = yz - wx;
m[10] = 1.0f - xx - yy;
m[11] = 0.0f;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
}
rsMatrix & rsMatrix::operator = (const rsMatrix &mat){
m[0]=mat[0]; m[1]=mat[1]; m[2]=mat[2]; m[3]=mat[3];
m[4]=mat[4]; m[5]=mat[5]; m[6]=mat[6]; m[7]=mat[7];
m[8]=mat[8]; m[9]=mat[9]; m[10]=mat[10]; m[11]=mat[11];
m[12]=mat[12]; m[13]=mat[13]; m[14]=mat[14]; m[15]=mat[15];
return *this;
}
std::ostream & rsMatrix::operator << (std::ostream &os){
return os
<< "| " << m[0] << " " << m[4] << " " << m[8] << " " << m[12] << " |" << std::endl
<< "| " << m[1] << " " << m[5] << " " << m[9] << " " << m[13] << " |" << std::endl
<< "| " << m[2] << " " << m[6] << " " << m[10] << " " << m[14] << " |" << std::endl
<< "| " << m[3] << " " << m[7] << " " << m[11] << " " << m[15] << " |" << std::endl;
}
/*std::ostream & operator << (std::ostream& os, const rsMatrix& mat){
return os
<< "| " << mat[0] << " " << mat[4] << " " << mat[8] << " " << mat[12] << " |" << std::endl
<< "| " << mat[1] << " " << mat[5] << " " << mat[9] << " " << mat[13] << " |" << std::endl
<< "| " << mat[2] << " " << mat[6] << " " << mat[10] << " " << mat[14] << " |" << std::endl
<< "| " << mat[3] << " " << mat[7] << " " << mat[11] << " " << mat[15] << " |" << std::endl;
}*/