2 * Copyright (C) 2016 Alistair Leslie-Hughes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* This guard is the same as D3DX9 to prevent double-inclusion */
22 #ifndef __D3DX9MATH_H__
23 #define __D3DX9MATH_H__
27 #ifndef D3DVECTOR_DEFINED
28 #define D3DVECTOR_DEFINED
29 typedef struct _D3DVECTOR
37 #ifndef D3DMATRIX_DEFINED
38 #define D3DMATRIX_DEFINED
39 typedef struct _D3DMATRIX
45 float _11
, _12
, _13
, _14
;
46 float _21
, _22
, _23
, _24
;
47 float _31
, _32
, _33
, _34
;
48 float _41
, _42
, _43
, _44
;
55 typedef enum _D3DX_CPU_OPTIMIZATION
61 } D3DX_CPU_OPTIMIZATION
;
63 typedef struct D3DXFLOAT16
68 D3DXFLOAT16(const D3DXFLOAT16
&f
);
72 BOOL
operator==(const D3DXFLOAT16
&f
) const;
73 BOOL
operator!=(const D3DXFLOAT16
&f
) const;
76 } D3DXFLOAT16
, *LPD3DXFLOAT16
;
78 typedef struct D3DXCOLOR
83 D3DXCOLOR(UINT color
);
84 D3DXCOLOR(const float *color
);
85 D3DXCOLOR(const D3DXFLOAT16
*color
);
86 D3DXCOLOR(float r
, float g
, float b
, float a
);
88 operator UINT() const;
90 operator const float *() const;
92 D3DXCOLOR
& operator+=(const D3DXCOLOR
&color
);
93 D3DXCOLOR
& operator-=(const D3DXCOLOR
&color
);
94 D3DXCOLOR
& operator*=(float n
);
95 D3DXCOLOR
& operator/=(float n
);
97 D3DXCOLOR
operator+() const;
98 D3DXCOLOR
operator-() const;
100 D3DXCOLOR
operator+(const D3DXCOLOR
&color
) const;
101 D3DXCOLOR
operator-(const D3DXCOLOR
&color
) const;
102 D3DXCOLOR
operator*(float n
) const;
103 D3DXCOLOR
operator/(float n
) const;
105 friend D3DXCOLOR
operator*(float n
, const D3DXCOLOR
&color
);
107 BOOL
operator==(const D3DXCOLOR
&color
) const;
108 BOOL
operator!=(const D3DXCOLOR
&color
) const;
111 } D3DXCOLOR
, *LPD3DXCOLOR
;
113 typedef struct D3DXVECTOR2
117 D3DXVECTOR2(const float *pf
);
118 D3DXVECTOR2(float fx
, float fy
);
121 operator const float* () const;
123 D3DXVECTOR2
& operator += (const D3DXVECTOR2
&);
124 D3DXVECTOR2
& operator -= (const D3DXVECTOR2
&);
125 D3DXVECTOR2
& operator *= (float);
126 D3DXVECTOR2
& operator /= (float);
128 D3DXVECTOR2
operator + () const;
129 D3DXVECTOR2
operator - () const;
131 D3DXVECTOR2
operator + (const D3DXVECTOR2
&) const;
132 D3DXVECTOR2
operator - (const D3DXVECTOR2
&) const;
133 D3DXVECTOR2
operator * (float) const;
134 D3DXVECTOR2
operator / (float) const;
136 friend D3DXVECTOR2
operator * (float, const D3DXVECTOR2
&);
138 BOOL
operator == (const D3DXVECTOR2
&) const;
139 BOOL
operator != (const D3DXVECTOR2
&) const;
140 #endif /* __cplusplus */
142 } D3DXVECTOR2
, *LPD3DXVECTOR2
;
145 typedef struct D3DXVECTOR3
: public D3DVECTOR
148 D3DXVECTOR3(const float *pf
);
149 D3DXVECTOR3(const D3DVECTOR
& v
);
150 D3DXVECTOR3(float fx
, float fy
, float fz
);
153 operator const float* () const;
155 D3DXVECTOR3
& operator += (const D3DXVECTOR3
&);
156 D3DXVECTOR3
& operator -= (const D3DXVECTOR3
&);
157 D3DXVECTOR3
& operator *= (float);
158 D3DXVECTOR3
& operator /= (float);
160 D3DXVECTOR3
operator + () const;
161 D3DXVECTOR3
operator - () const;
163 D3DXVECTOR3
operator + (const D3DXVECTOR3
&) const;
164 D3DXVECTOR3
operator - (const D3DXVECTOR3
&) const;
165 D3DXVECTOR3
operator * (float) const;
166 D3DXVECTOR3
operator / (float) const;
168 friend D3DXVECTOR3
operator * (float, const struct D3DXVECTOR3
&);
170 BOOL
operator == (const D3DXVECTOR3
&) const;
171 BOOL
operator != (const D3DXVECTOR3
&) const;
172 } D3DXVECTOR3
, *LPD3DXVECTOR3
;
173 #else /* !__cplusplus */
174 typedef struct _D3DVECTOR D3DXVECTOR3
, *LPD3DXVECTOR3
;
175 #endif /* !__cplusplus */
177 typedef struct D3DXVECTOR4
181 D3DXVECTOR4(const float *pf
);
182 D3DXVECTOR4(float fx
, float fy
, float fz
, float fw
);
185 operator const float* () const;
187 D3DXVECTOR4
& operator += (const D3DXVECTOR4
&);
188 D3DXVECTOR4
& operator -= (const D3DXVECTOR4
&);
189 D3DXVECTOR4
& operator *= (float);
190 D3DXVECTOR4
& operator /= (float);
192 D3DXVECTOR4
operator + () const;
193 D3DXVECTOR4
operator - () const;
195 D3DXVECTOR4
operator + (const D3DXVECTOR4
&) const;
196 D3DXVECTOR4
operator - (const D3DXVECTOR4
&) const;
197 D3DXVECTOR4
operator * (float) const;
198 D3DXVECTOR4
operator / (float) const;
200 friend D3DXVECTOR4
operator * (float, const D3DXVECTOR4
&);
202 BOOL
operator == (const D3DXVECTOR4
&) const;
203 BOOL
operator != (const D3DXVECTOR4
&) const;
204 #endif /* __cplusplus */
206 } D3DXVECTOR4
, *LPD3DXVECTOR4
;
209 typedef struct D3DXMATRIX
: public D3DMATRIX
212 D3DXMATRIX(const float *pf
);
213 D3DXMATRIX(const D3DMATRIX
& mat
);
214 D3DXMATRIX(float f11
, float f12
, float f13
, float f14
,
215 float f21
, float f22
, float f23
, float f24
,
216 float f31
, float f32
, float f33
, float f34
,
217 float f41
, float f42
, float f43
, float f44
);
219 float& operator () (UINT row
, UINT col
);
220 float operator () (UINT row
, UINT col
) const;
223 operator const float* () const;
225 D3DXMATRIX
& operator *= (const D3DXMATRIX
&);
226 D3DXMATRIX
& operator += (const D3DXMATRIX
&);
227 D3DXMATRIX
& operator -= (const D3DXMATRIX
&);
228 D3DXMATRIX
& operator *= (float);
229 D3DXMATRIX
& operator /= (float);
231 D3DXMATRIX
operator + () const;
232 D3DXMATRIX
operator - () const;
234 D3DXMATRIX
operator * (const D3DXMATRIX
&) const;
235 D3DXMATRIX
operator + (const D3DXMATRIX
&) const;
236 D3DXMATRIX
operator - (const D3DXMATRIX
&) const;
237 D3DXMATRIX
operator * (float) const;
238 D3DXMATRIX
operator / (float) const;
240 friend D3DXMATRIX
operator * (float, const D3DXMATRIX
&);
242 BOOL
operator == (const D3DXMATRIX
&) const;
243 BOOL
operator != (const D3DXMATRIX
&) const;
244 } D3DXMATRIX
, *LPD3DXMATRIX
;
245 #else /* !__cplusplus */
246 typedef struct _D3DMATRIX D3DXMATRIX
, *LPD3DXMATRIX
;
247 #endif /* !__cplusplus */
253 D3DXCOLOR
*D3DXColorAdd(D3DXCOLOR
*out
, D3DXCOLOR c1
, D3DXCOLOR c2
);
254 D3DXCOLOR
*D3DXColorLerp(D3DXCOLOR
*out
, D3DXCOLOR c1
, D3DXCOLOR c2
, float s
);
255 D3DXCOLOR
*D3DXColorModulate(D3DXCOLOR
*out
, D3DXCOLOR c1
, D3DXCOLOR c2
);
256 D3DXCOLOR
*D3DXColorScale(D3DXCOLOR
*out
, D3DXCOLOR c
, float s
);
257 D3DXCOLOR
*D3DXColorSubtract(D3DXCOLOR
*out
, D3DXCOLOR c1
, D3DXCOLOR c2
);
258 D3DX_CPU_OPTIMIZATION WINAPI
D3DXCpuOptimizations(BOOL enable
);
264 #endif /* __D3DX9MATH_H__ */