OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
SkelMat3.h
1/*
2===========================================================================
3Copyright (C) 2023 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// SkelMat3.h : Skeletor
24
25#pragma once
26
27#ifdef __cplusplus
28
29class SkelMat3
30{
31public:
32 float val[3][3];
33
34protected:
35 void copy(const SkelMat3& m);
36
37public:
38 void MakeZero();
39 void MakeIdentity();
40
41 SkelMat3(const SkelVec3& x, const SkelVec3& y, const SkelVec3& z);
42 SkelMat3(const float *mat[3]);
43 SkelMat3();
44
45 SkelVec3 *XAxis();
46 SkelVec3 *YAxis();
47 SkelVec3 *ZAxis();
48
49 operator float *();
50 operator float *() const;
51
52 float *operator[](int index);
53 float *operator[](int index) const;
54
55 void GetEulerAngles(float *vec) const;
56 void GetScale(float *vec) const;
57 bool IsOrthonormal() const;
58 bool IsValid() const;
59
60 void Multiply(const float mat1[3][3], const float mat2[3][3]);
61 float det() const;
62 float trace() const;
63 SkelVec3 TransformVector(const SkelVec3 *skel);
64 void Transpose();
65};
66
67inline SkelMat3::SkelMat3(const SkelVec3& x, const SkelVec3& y, const SkelVec3& z)
68{
69 VectorCopy(x, val[0]);
70 VectorCopy(y, val[1]);
71 VectorCopy(z, val[2]);
72}
73
74inline SkelMat3::SkelMat3(const float *mat[3])
75{
76 memcpy(&val, mat, sizeof(val));
77}
78
79inline SkelMat3::SkelMat3()
80{
81 MakeIdentity();
82}
83
84inline void SkelMat3::copy(const SkelMat3& m)
85{
86 AxisCopy(m.val, val);
87}
88
89inline void SkelMat3::MakeZero()
90{
91 AxisClear(val);
92}
93
94inline void SkelMat3::MakeIdentity()
95{
96 MakeZero();
97 val[0][0] = 1.0f;
98 val[1][1] = 1.0f;
99 val[2][2] = 1.0f;
100}
101
102inline SkelVec3 *SkelMat3::XAxis()
103{
104 return (SkelVec3 *)&val[0];
105}
106
107inline SkelVec3 *SkelMat3::YAxis()
108{
109 return (SkelVec3 *)&val[1];
110}
111
112inline SkelVec3 *SkelMat3::ZAxis()
113{
114 return (SkelVec3 *)&val[2];
115}
116
117inline SkelMat3::operator float *()
118{
119 return &val[0][0];
120}
121
122inline SkelMat3::operator float *() const
123{
124 return (float *)&val[0][0];
125}
126
127inline float *SkelMat3::operator[](int index)
128{
129 return val[index];
130}
131
132inline float *SkelMat3::operator[](int index) const
133{
134 return (float *)val[index];
135}
136
137inline void SkelMat3::GetEulerAngles(float *vec) const
138{
139 MatrixToEulerAngles(val, vec);
140}
141
142inline void SkelMat3::GetScale(float *vec) const
143{
144 // FIXME: stub
145}
146
147inline bool SkelMat3::IsOrthonormal() const
148{
149 // FIXME: stub
150 return false;
151}
152
153inline bool SkelMat3::IsValid() const
154{
155 // FIXME: stub
156 return false;
157}
158
159inline void SkelMat3::Multiply(const float mat1[3][3], const float mat2[3][3])
160{
161 MatrixMultiply(mat1, mat2, val);
162}
163
164inline float SkelMat3::det() const
165{
166 return (val[2][1] * val[1][0] - val[2][0] * val[1][1]) * val[0][2]
167 + (val[1][1] * val[2][2] - val[1][2] * val[2][1]) * val[0][0]
168 - (val[2][2] * val[1][0] - val[1][2] * val[2][0]) * val[0][1];
169}
170
171inline float SkelMat3::trace() const
172{
173 return val[0][0] + val[1][1] + val[2][2];
174}
175
176inline SkelVec3 SkelMat3::TransformVector(const SkelVec3 *skel)
177{
178 SkelVec3 out;
179 MatrixTransformVector(*skel, val, out);
180 return out;
181}
182
183inline void SkelMat3::Transpose()
184{
185 SkelMat3 out;
186 TransposeMatrix(val, out.val);
187 memcpy(val, out, sizeof(SkelMat3));
188}
189
190#else
191
192typedef struct {
193 float val[3][3];
194} SkelMat3;
195
196#endif
Definition SkelMat3.h:192
Definition SkelVec3.h:197