Line data Source code
1 : /* Copyright (C) 2025 Wildfire Games.
2 : * This file is part of 0 A.D.
3 : *
4 : * 0 A.D. is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 2 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * 0 A.D. is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 : */
17 :
18 : #include "precompiled.h"
19 :
20 : #include "Maths.h"
21 :
22 : #include "DLL.h"
23 :
24 : #include <FMath/FMMatrix44.h>
25 : #include <FMath/FMVector3.h>
26 :
27 0 : void DumpMatrix(const FMMatrix44& m)
28 : {
29 0 : Log(LOG_INFO, "\n[%f %f %f %f]\n[%f %f %f %f]\n[%f %f %f %f]\n[%f %f %f %f]",
30 0 : m.m[0][0], m.m[0][1], m.m[0][2], m.m[0][3],
31 0 : m.m[1][0], m.m[1][1], m.m[1][2], m.m[1][3],
32 0 : m.m[2][0], m.m[2][1], m.m[2][2], m.m[2][3],
33 0 : m.m[3][0], m.m[3][1], m.m[3][2], m.m[3][3]
34 : );
35 0 : }
36 :
37 0 : FMMatrix44 DecomposeToScaleMatrix(const FMMatrix44& m)
38 : {
39 0 : FMVector3 scale, rotation, translation;
40 0 : float inverted;
41 0 : m.Decompose(scale, rotation, translation, inverted);
42 0 : return FMMatrix44::ScaleMatrix(scale);
43 : }
44 :
45 : /*
46 : FMMatrix44 operator+ (const FMMatrix44& a, const FMMatrix44& b)
47 : {
48 : FMMatrix44 r;
49 : for (int x = 0; x < 4; ++x)
50 : for (int y = 0; y < 4; ++y)
51 : r[x][y] = a[x][y] + b[x][y];
52 : return r;
53 : }
54 :
55 : FMMatrix44 operator/ (const FMMatrix44& a, const float b)
56 : {
57 : FMMatrix44 r;
58 : for (int x = 0; x < 4; ++x)
59 : for (int y = 0; y < 4; ++y)
60 : r[x][y] = a[x][y] / b;
61 : return r;
62 : }
63 :
64 : FMMatrix44 QuatToMatrix(float x, float y, float z, float w)
65 : {
66 : FMMatrix44 r;
67 :
68 : r[0][0] = 1.0f - (y*y*2 + z*z*2);
69 : r[1][0] = x*y*2 - w*z*2;
70 : r[2][0] = x*z*2 + w*y*2;
71 : r[3][0] = 0;
72 :
73 : r[0][1] = x*y*2 + w*z*2;
74 : r[1][1] = 1.0f - (x*x*2 + z*z*2);
75 : r[2][1] = y*z*2 - w*x*2;
76 : r[3][1] = 0;
77 :
78 : r[0][2] = x*z*2 - w*y*2;
79 : r[1][2] = y*z*2 + w*x*2;
80 : r[2][2] = 1.0f - (x*x*2 + y*y*2);
81 : r[3][2] = 0;
82 :
83 : r[0][3] = 0;
84 : r[1][3] = 0;
85 : r[2][3] = 0;
86 : r[3][3] = 1;
87 :
88 : return r;
89 : }
90 : */
|