OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
SkelVec3.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// SkelVec3.h : Skeletor
24
25#pragma once
26
27typedef enum {
28 svX,
29 svY,
30 svZ,
31 svW
32} SkelVec_Axis;
33
34typedef enum {
35 Vec3YAW,
36 Vec3PITCH,
37 Vec3ROLL
38} YPR_Axes;
39
40#ifdef __cplusplus
41
42class SkelVec3
43{
44public:
45 union {
46 float val[3];
47
48 struct {
49 float x;
50 float y;
51 float z;
52 };
53 };
54
55protected:
56 void copy(const SkelVec3& skel);
57
58public:
59 SkelVec3(float x, float y, float z);
60 SkelVec3(vec3_t vec);
61 SkelVec3();
62
63 operator float *();
64 operator float *() const;
65
66 float& operator[](int index);
67 float operator[](int index) const;
68
69 const SkelVec3& operator+=(const SkelVec3& a);
70 const SkelVec3& operator+=(vec3_t a);
71
72 bool IsZero() const;
73 bool IsUnit() const;
74 void set(float x, float y, float z);
75
76 float Normalize();
77 void NormalizeFast();
78
79 void SetZero();
80 void SetXAxis();
81 void SetYAxis();
82 void SetZAxis();
83 void RotateYaw(float yaw, float deg);
84};
85
86inline SkelVec3::SkelVec3(float x, float y, float z)
87{
88 set(x, y, z);
89}
90
91inline SkelVec3::SkelVec3(vec3_t vec)
92{
93 this->x = vec[0];
94 this->y = vec[1];
95 this->z = vec[2];
96}
97
98inline SkelVec3::SkelVec3()
99{
100 SetZero();
101}
102
103inline SkelVec3::operator float *()
104{
105 return val;
106}
107
108inline SkelVec3::operator float *() const
109{
110 return (float *)val;
111}
112
113inline bool SkelVec3::IsZero() const
114{
115 return (x == 0.0f) && (y == 0.0f) && (z == 0.0f);
116}
117
118inline bool SkelVec3::IsUnit() const
119{
120 return VectorLength(*this) == 1;
121}
122
123inline void SkelVec3::set(float x, float y, float z)
124{
125 this->x = x;
126 this->y = y;
127 this->z = z;
128}
129
130inline float SkelVec3::Normalize()
131{
132 return VectorNormalize(val);
133}
134
135inline void SkelVec3::NormalizeFast()
136{
137 VectorNormalizeFast(val);
138}
139
140inline void SkelVec3::SetZero()
141{
142 this->x = 0.0f;
143 this->y = 0.0f;
144 this->z = 0.0f;
145}
146
147inline void SkelVec3::SetXAxis()
148{
149 x = 0.0f;
150}
151
152inline void SkelVec3::SetYAxis()
153{
154 y = 0.0f;
155}
156
157inline void SkelVec3::SetZAxis()
158{
159 z = 0.0f;
160}
161
162inline void SkelVec3::RotateYaw(float yaw, float deg)
163{
164 // FIXME: stub
165}
166
167inline float& SkelVec3::operator[](int index)
168{
169 return val[index];
170}
171
172inline float SkelVec3::operator[](int index) const
173{
174 return val[index];
175}
176
177inline const SkelVec3& SkelVec3::operator+=(const SkelVec3& a)
178{
179 x += a.x;
180 y += a.y;
181 z += a.z;
182
183 return *this;
184}
185
186inline const SkelVec3& SkelVec3::operator+=(vec3_t a)
187{
188 x += a[0];
189 y += a[1];
190 z += a[2];
191
192 return *this;
193}
194
195#else
196
197typedef struct {
198 union {
199 float val[3];
200
201 struct {
202 float x;
203 float y;
204 float z;
205 };
206 };
207} SkelVec3;
208
209#endif
Definition SkelVec3.h:197