2 * Mathematical operations specific to D3DX9.
4 * Copyright (C) 2008 David Adam
5 * Copyright (C) 2008 Luis Busquets
6 * Copyright (C) 2008 Jérôme Gardou
7 * Copyright (C) 2008 Philip Nilsson
8 * Copyright (C) 2008 Henri Verbeet
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
30 #include "d3dx9_36_private.h"
32 #include <wine/debug.h>
34 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
37 #define copysignf(x, y) ((x) < 0.0f ? -fabsf(y) : fabsf(y))
40 struct ID3DXMatrixStackImpl
42 ID3DXMatrixStack ID3DXMatrixStack_iface
;
46 unsigned int stack_size
;
50 static const unsigned int INITIAL_STACK_SIZE
= 32;
52 /*_________________D3DXColor____________________*/
54 D3DXCOLOR
* WINAPI
D3DXColorAdjustContrast(D3DXCOLOR
*pout
, const D3DXCOLOR
*pc
, FLOAT s
)
56 TRACE("pout %p, pc %p, s %f\n", pout
, pc
, s
);
58 pout
->r
= 0.5f
+ s
* (pc
->r
- 0.5f
);
59 pout
->g
= 0.5f
+ s
* (pc
->g
- 0.5f
);
60 pout
->b
= 0.5f
+ s
* (pc
->b
- 0.5f
);
65 D3DXCOLOR
* WINAPI
D3DXColorAdjustSaturation(D3DXCOLOR
*pout
, const D3DXCOLOR
*pc
, FLOAT s
)
69 TRACE("pout %p, pc %p, s %f\n", pout
, pc
, s
);
71 grey
= pc
->r
* 0.2125f
+ pc
->g
* 0.7154f
+ pc
->b
* 0.0721f
;
72 pout
->r
= grey
+ s
* (pc
->r
- grey
);
73 pout
->g
= grey
+ s
* (pc
->g
- grey
);
74 pout
->b
= grey
+ s
* (pc
->b
- grey
);
79 /*_________________Misc__________________________*/
81 FLOAT WINAPI
D3DXFresnelTerm(FLOAT costheta
, FLOAT refractionindex
)
83 FLOAT a
, d
, g
, result
;
85 TRACE("costheta %f, refractionindex %f\n", costheta
, refractionindex
);
87 g
= sqrtf(refractionindex
* refractionindex
+ costheta
* costheta
- 1.0f
);
90 result
= (costheta
* a
- 1.0f
) * (costheta
* a
- 1.0f
) / ((costheta
* d
+ 1.0f
) * (costheta
* d
+ 1.0f
)) + 1.0f
;
91 result
*= 0.5f
* d
* d
/ (a
* a
);
96 /*_________________D3DXMatrix____________________*/
98 D3DXMATRIX
* WINAPI
D3DXMatrixAffineTransformation(D3DXMATRIX
*out
, FLOAT scaling
, const D3DXVECTOR3
*rotationcenter
,
99 const D3DXQUATERNION
*rotation
, const D3DXVECTOR3
*translation
)
101 TRACE("out %p, scaling %f, rotationcenter %p, rotation %p, translation %p\n",
102 out
, scaling
, rotationcenter
, rotation
, translation
);
104 D3DXMatrixIdentity(out
);
108 FLOAT temp00
, temp01
, temp02
, temp10
, temp11
, temp12
, temp20
, temp21
, temp22
;
110 temp00
= 1.0f
- 2.0f
* (rotation
->y
* rotation
->y
+ rotation
->z
* rotation
->z
);
111 temp01
= 2.0f
* (rotation
->x
* rotation
->y
+ rotation
->z
* rotation
->w
);
112 temp02
= 2.0f
* (rotation
->x
* rotation
->z
- rotation
->y
* rotation
->w
);
113 temp10
= 2.0f
* (rotation
->x
* rotation
->y
- rotation
->z
* rotation
->w
);
114 temp11
= 1.0f
- 2.0f
* (rotation
->x
* rotation
->x
+ rotation
->z
* rotation
->z
);
115 temp12
= 2.0f
* (rotation
->y
* rotation
->z
+ rotation
->x
* rotation
->w
);
116 temp20
= 2.0f
* (rotation
->x
* rotation
->z
+ rotation
->y
* rotation
->w
);
117 temp21
= 2.0f
* (rotation
->y
* rotation
->z
- rotation
->x
* rotation
->w
);
118 temp22
= 1.0f
- 2.0f
* (rotation
->x
* rotation
->x
+ rotation
->y
* rotation
->y
);
120 out
->u
.m
[0][0] = scaling
* temp00
;
121 out
->u
.m
[0][1] = scaling
* temp01
;
122 out
->u
.m
[0][2] = scaling
* temp02
;
123 out
->u
.m
[1][0] = scaling
* temp10
;
124 out
->u
.m
[1][1] = scaling
* temp11
;
125 out
->u
.m
[1][2] = scaling
* temp12
;
126 out
->u
.m
[2][0] = scaling
* temp20
;
127 out
->u
.m
[2][1] = scaling
* temp21
;
128 out
->u
.m
[2][2] = scaling
* temp22
;
132 out
->u
.m
[3][0] = rotationcenter
->x
* (1.0f
- temp00
) - rotationcenter
->y
* temp10
133 - rotationcenter
->z
* temp20
;
134 out
->u
.m
[3][1] = rotationcenter
->y
* (1.0f
- temp11
) - rotationcenter
->x
* temp01
135 - rotationcenter
->z
* temp21
;
136 out
->u
.m
[3][2] = rotationcenter
->z
* (1.0f
- temp22
) - rotationcenter
->x
* temp02
137 - rotationcenter
->y
* temp12
;
142 out
->u
.m
[0][0] = scaling
;
143 out
->u
.m
[1][1] = scaling
;
144 out
->u
.m
[2][2] = scaling
;
149 out
->u
.m
[3][0] += translation
->x
;
150 out
->u
.m
[3][1] += translation
->y
;
151 out
->u
.m
[3][2] += translation
->z
;
157 D3DXMATRIX
* WINAPI
D3DXMatrixAffineTransformation2D(D3DXMATRIX
*out
, FLOAT scaling
,
158 const D3DXVECTOR2
*rotationcenter
, FLOAT rotation
, const D3DXVECTOR2
*translation
)
162 TRACE("out %p, scaling %f, rotationcenter %p, rotation %f, translation %p\n",
163 out
, scaling
, rotationcenter
, rotation
, translation
);
165 s
= sinf(rotation
/ 2.0f
);
166 tmp1
= 1.0f
- 2.0f
* s
* s
;
167 tmp2
= 2.0 * s
* cosf(rotation
/ 2.0f
);
169 D3DXMatrixIdentity(out
);
170 out
->u
.m
[0][0] = scaling
* tmp1
;
171 out
->u
.m
[0][1] = scaling
* tmp2
;
172 out
->u
.m
[1][0] = -scaling
* tmp2
;
173 out
->u
.m
[1][1] = scaling
* tmp1
;
179 x
= rotationcenter
->x
;
180 y
= rotationcenter
->y
;
182 out
->u
.m
[3][0] = y
* tmp2
- x
* tmp1
+ x
;
183 out
->u
.m
[3][1] = -x
* tmp2
- y
* tmp1
+ y
;
188 out
->u
.m
[3][0] += translation
->x
;
189 out
->u
.m
[3][1] += translation
->y
;
195 HRESULT WINAPI
D3DXMatrixDecompose(D3DXVECTOR3
*poutscale
, D3DXQUATERNION
*poutrotation
, D3DXVECTOR3
*pouttranslation
, const D3DXMATRIX
*pm
)
197 D3DXMATRIX normalized
;
200 TRACE("poutscale %p, poutrotation %p, pouttranslation %p, pm %p\n", poutscale
, poutrotation
, pouttranslation
, pm
);
202 /*Compute the scaling part.*/
206 poutscale
->x
=D3DXVec3Length(&vec
);
211 poutscale
->y
=D3DXVec3Length(&vec
);
216 poutscale
->z
=D3DXVec3Length(&vec
);
218 /*Compute the translation part.*/
219 pouttranslation
->x
=pm
->u
.m
[3][0];
220 pouttranslation
->y
=pm
->u
.m
[3][1];
221 pouttranslation
->z
=pm
->u
.m
[3][2];
223 /*Let's calculate the rotation now*/
224 if ( (poutscale
->x
== 0.0f
) || (poutscale
->y
== 0.0f
) || (poutscale
->z
== 0.0f
) ) return D3DERR_INVALIDCALL
;
226 normalized
.u
.m
[0][0]=pm
->u
.m
[0][0]/poutscale
->x
;
227 normalized
.u
.m
[0][1]=pm
->u
.m
[0][1]/poutscale
->x
;
228 normalized
.u
.m
[0][2]=pm
->u
.m
[0][2]/poutscale
->x
;
229 normalized
.u
.m
[1][0]=pm
->u
.m
[1][0]/poutscale
->y
;
230 normalized
.u
.m
[1][1]=pm
->u
.m
[1][1]/poutscale
->y
;
231 normalized
.u
.m
[1][2]=pm
->u
.m
[1][2]/poutscale
->y
;
232 normalized
.u
.m
[2][0]=pm
->u
.m
[2][0]/poutscale
->z
;
233 normalized
.u
.m
[2][1]=pm
->u
.m
[2][1]/poutscale
->z
;
234 normalized
.u
.m
[2][2]=pm
->u
.m
[2][2]/poutscale
->z
;
236 D3DXQuaternionRotationMatrix(poutrotation
,&normalized
);
240 FLOAT WINAPI
D3DXMatrixDeterminant(const D3DXMATRIX
*pm
)
244 TRACE("pm %p\n", pm
);
246 t
[0] = pm
->u
.m
[2][2] * pm
->u
.m
[3][3] - pm
->u
.m
[2][3] * pm
->u
.m
[3][2];
247 t
[1] = pm
->u
.m
[1][2] * pm
->u
.m
[3][3] - pm
->u
.m
[1][3] * pm
->u
.m
[3][2];
248 t
[2] = pm
->u
.m
[1][2] * pm
->u
.m
[2][3] - pm
->u
.m
[1][3] * pm
->u
.m
[2][2];
249 v
[0] = pm
->u
.m
[1][1] * t
[0] - pm
->u
.m
[2][1] * t
[1] + pm
->u
.m
[3][1] * t
[2];
250 v
[1] = -pm
->u
.m
[1][0] * t
[0] + pm
->u
.m
[2][0] * t
[1] - pm
->u
.m
[3][0] * t
[2];
252 t
[0] = pm
->u
.m
[1][0] * pm
->u
.m
[2][1] - pm
->u
.m
[2][0] * pm
->u
.m
[1][1];
253 t
[1] = pm
->u
.m
[1][0] * pm
->u
.m
[3][1] - pm
->u
.m
[3][0] * pm
->u
.m
[1][1];
254 t
[2] = pm
->u
.m
[2][0] * pm
->u
.m
[3][1] - pm
->u
.m
[3][0] * pm
->u
.m
[2][1];
255 v
[2] = pm
->u
.m
[3][3] * t
[0] - pm
->u
.m
[2][3] * t
[1] + pm
->u
.m
[1][3] * t
[2];
256 v
[3] = -pm
->u
.m
[3][2] * t
[0] + pm
->u
.m
[2][2] * t
[1] - pm
->u
.m
[1][2] * t
[2];
258 return pm
->u
.m
[0][0] * v
[0] + pm
->u
.m
[0][1] * v
[1] +
259 pm
->u
.m
[0][2] * v
[2] + pm
->u
.m
[0][3] * v
[3];
262 D3DXMATRIX
* WINAPI
D3DXMatrixInverse(D3DXMATRIX
*pout
, FLOAT
*pdeterminant
, const D3DXMATRIX
*pm
)
264 FLOAT det
, t
[3], v
[16];
267 TRACE("pout %p, pdeterminant %p, pm %p\n", pout
, pdeterminant
, pm
);
269 t
[0] = pm
->u
.m
[2][2] * pm
->u
.m
[3][3] - pm
->u
.m
[2][3] * pm
->u
.m
[3][2];
270 t
[1] = pm
->u
.m
[1][2] * pm
->u
.m
[3][3] - pm
->u
.m
[1][3] * pm
->u
.m
[3][2];
271 t
[2] = pm
->u
.m
[1][2] * pm
->u
.m
[2][3] - pm
->u
.m
[1][3] * pm
->u
.m
[2][2];
272 v
[0] = pm
->u
.m
[1][1] * t
[0] - pm
->u
.m
[2][1] * t
[1] + pm
->u
.m
[3][1] * t
[2];
273 v
[4] = -pm
->u
.m
[1][0] * t
[0] + pm
->u
.m
[2][0] * t
[1] - pm
->u
.m
[3][0] * t
[2];
275 t
[0] = pm
->u
.m
[1][0] * pm
->u
.m
[2][1] - pm
->u
.m
[2][0] * pm
->u
.m
[1][1];
276 t
[1] = pm
->u
.m
[1][0] * pm
->u
.m
[3][1] - pm
->u
.m
[3][0] * pm
->u
.m
[1][1];
277 t
[2] = pm
->u
.m
[2][0] * pm
->u
.m
[3][1] - pm
->u
.m
[3][0] * pm
->u
.m
[2][1];
278 v
[8] = pm
->u
.m
[3][3] * t
[0] - pm
->u
.m
[2][3] * t
[1] + pm
->u
.m
[1][3] * t
[2];
279 v
[12] = -pm
->u
.m
[3][2] * t
[0] + pm
->u
.m
[2][2] * t
[1] - pm
->u
.m
[1][2] * t
[2];
281 det
= pm
->u
.m
[0][0] * v
[0] + pm
->u
.m
[0][1] * v
[4] +
282 pm
->u
.m
[0][2] * v
[8] + pm
->u
.m
[0][3] * v
[12];
288 t
[0] = pm
->u
.m
[2][2] * pm
->u
.m
[3][3] - pm
->u
.m
[2][3] * pm
->u
.m
[3][2];
289 t
[1] = pm
->u
.m
[0][2] * pm
->u
.m
[3][3] - pm
->u
.m
[0][3] * pm
->u
.m
[3][2];
290 t
[2] = pm
->u
.m
[0][2] * pm
->u
.m
[2][3] - pm
->u
.m
[0][3] * pm
->u
.m
[2][2];
291 v
[1] = -pm
->u
.m
[0][1] * t
[0] + pm
->u
.m
[2][1] * t
[1] - pm
->u
.m
[3][1] * t
[2];
292 v
[5] = pm
->u
.m
[0][0] * t
[0] - pm
->u
.m
[2][0] * t
[1] + pm
->u
.m
[3][0] * t
[2];
294 t
[0] = pm
->u
.m
[0][0] * pm
->u
.m
[2][1] - pm
->u
.m
[2][0] * pm
->u
.m
[0][1];
295 t
[1] = pm
->u
.m
[3][0] * pm
->u
.m
[0][1] - pm
->u
.m
[0][0] * pm
->u
.m
[3][1];
296 t
[2] = pm
->u
.m
[2][0] * pm
->u
.m
[3][1] - pm
->u
.m
[3][0] * pm
->u
.m
[2][1];
297 v
[9] = -pm
->u
.m
[3][3] * t
[0] - pm
->u
.m
[2][3] * t
[1]- pm
->u
.m
[0][3] * t
[2];
298 v
[13] = pm
->u
.m
[3][2] * t
[0] + pm
->u
.m
[2][2] * t
[1] + pm
->u
.m
[0][2] * t
[2];
300 t
[0] = pm
->u
.m
[1][2] * pm
->u
.m
[3][3] - pm
->u
.m
[1][3] * pm
->u
.m
[3][2];
301 t
[1] = pm
->u
.m
[0][2] * pm
->u
.m
[3][3] - pm
->u
.m
[0][3] * pm
->u
.m
[3][2];
302 t
[2] = pm
->u
.m
[0][2] * pm
->u
.m
[1][3] - pm
->u
.m
[0][3] * pm
->u
.m
[1][2];
303 v
[2] = pm
->u
.m
[0][1] * t
[0] - pm
->u
.m
[1][1] * t
[1] + pm
->u
.m
[3][1] * t
[2];
304 v
[6] = -pm
->u
.m
[0][0] * t
[0] + pm
->u
.m
[1][0] * t
[1] - pm
->u
.m
[3][0] * t
[2];
306 t
[0] = pm
->u
.m
[0][0] * pm
->u
.m
[1][1] - pm
->u
.m
[1][0] * pm
->u
.m
[0][1];
307 t
[1] = pm
->u
.m
[3][0] * pm
->u
.m
[0][1] - pm
->u
.m
[0][0] * pm
->u
.m
[3][1];
308 t
[2] = pm
->u
.m
[1][0] * pm
->u
.m
[3][1] - pm
->u
.m
[3][0] * pm
->u
.m
[1][1];
309 v
[10] = pm
->u
.m
[3][3] * t
[0] + pm
->u
.m
[1][3] * t
[1] + pm
->u
.m
[0][3] * t
[2];
310 v
[14] = -pm
->u
.m
[3][2] * t
[0] - pm
->u
.m
[1][2] * t
[1] - pm
->u
.m
[0][2] * t
[2];
312 t
[0] = pm
->u
.m
[1][2] * pm
->u
.m
[2][3] - pm
->u
.m
[1][3] * pm
->u
.m
[2][2];
313 t
[1] = pm
->u
.m
[0][2] * pm
->u
.m
[2][3] - pm
->u
.m
[0][3] * pm
->u
.m
[2][2];
314 t
[2] = pm
->u
.m
[0][2] * pm
->u
.m
[1][3] - pm
->u
.m
[0][3] * pm
->u
.m
[1][2];
315 v
[3] = -pm
->u
.m
[0][1] * t
[0] + pm
->u
.m
[1][1] * t
[1] - pm
->u
.m
[2][1] * t
[2];
316 v
[7] = pm
->u
.m
[0][0] * t
[0] - pm
->u
.m
[1][0] * t
[1] + pm
->u
.m
[2][0] * t
[2];
318 v
[11] = -pm
->u
.m
[0][0] * (pm
->u
.m
[1][1] * pm
->u
.m
[2][3] - pm
->u
.m
[1][3] * pm
->u
.m
[2][1]) +
319 pm
->u
.m
[1][0] * (pm
->u
.m
[0][1] * pm
->u
.m
[2][3] - pm
->u
.m
[0][3] * pm
->u
.m
[2][1]) -
320 pm
->u
.m
[2][0] * (pm
->u
.m
[0][1] * pm
->u
.m
[1][3] - pm
->u
.m
[0][3] * pm
->u
.m
[1][1]);
322 v
[15] = pm
->u
.m
[0][0] * (pm
->u
.m
[1][1] * pm
->u
.m
[2][2] - pm
->u
.m
[1][2] * pm
->u
.m
[2][1]) -
323 pm
->u
.m
[1][0] * (pm
->u
.m
[0][1] * pm
->u
.m
[2][2] - pm
->u
.m
[0][2] * pm
->u
.m
[2][1]) +
324 pm
->u
.m
[2][0] * (pm
->u
.m
[0][1] * pm
->u
.m
[1][2] - pm
->u
.m
[0][2] * pm
->u
.m
[1][1]);
328 for (i
= 0; i
< 4; i
++)
329 for (j
= 0; j
< 4; j
++)
330 pout
->u
.m
[i
][j
] = v
[4 * i
+ j
] * det
;
335 D3DXMATRIX
* WINAPI
D3DXMatrixLookAtLH(D3DXMATRIX
*out
, const D3DXVECTOR3
*eye
, const D3DXVECTOR3
*at
,
336 const D3DXVECTOR3
*up
)
338 D3DXVECTOR3 right
, upn
, vec
;
340 TRACE("out %p, eye %p, at %p, up %p\n", out
, eye
, at
, up
);
342 D3DXVec3Subtract(&vec
, at
, eye
);
343 D3DXVec3Normalize(&vec
, &vec
);
344 D3DXVec3Cross(&right
, up
, &vec
);
345 D3DXVec3Cross(&upn
, &vec
, &right
);
346 D3DXVec3Normalize(&right
, &right
);
347 D3DXVec3Normalize(&upn
, &upn
);
348 out
->u
.m
[0][0] = right
.x
;
349 out
->u
.m
[1][0] = right
.y
;
350 out
->u
.m
[2][0] = right
.z
;
351 out
->u
.m
[3][0] = -D3DXVec3Dot(&right
, eye
);
352 out
->u
.m
[0][1] = upn
.x
;
353 out
->u
.m
[1][1] = upn
.y
;
354 out
->u
.m
[2][1] = upn
.z
;
355 out
->u
.m
[3][1] = -D3DXVec3Dot(&upn
, eye
);
356 out
->u
.m
[0][2] = vec
.x
;
357 out
->u
.m
[1][2] = vec
.y
;
358 out
->u
.m
[2][2] = vec
.z
;
359 out
->u
.m
[3][2] = -D3DXVec3Dot(&vec
, eye
);
360 out
->u
.m
[0][3] = 0.0f
;
361 out
->u
.m
[1][3] = 0.0f
;
362 out
->u
.m
[2][3] = 0.0f
;
363 out
->u
.m
[3][3] = 1.0f
;
368 D3DXMATRIX
* WINAPI
D3DXMatrixLookAtRH(D3DXMATRIX
*out
, const D3DXVECTOR3
*eye
, const D3DXVECTOR3
*at
,
369 const D3DXVECTOR3
*up
)
371 D3DXVECTOR3 right
, upn
, vec
;
373 TRACE("out %p, eye %p, at %p, up %p\n", out
, eye
, at
, up
);
375 D3DXVec3Subtract(&vec
, at
, eye
);
376 D3DXVec3Normalize(&vec
, &vec
);
377 D3DXVec3Cross(&right
, up
, &vec
);
378 D3DXVec3Cross(&upn
, &vec
, &right
);
379 D3DXVec3Normalize(&right
, &right
);
380 D3DXVec3Normalize(&upn
, &upn
);
381 out
->u
.m
[0][0] = -right
.x
;
382 out
->u
.m
[1][0] = -right
.y
;
383 out
->u
.m
[2][0] = -right
.z
;
384 out
->u
.m
[3][0] = D3DXVec3Dot(&right
, eye
);
385 out
->u
.m
[0][1] = upn
.x
;
386 out
->u
.m
[1][1] = upn
.y
;
387 out
->u
.m
[2][1] = upn
.z
;
388 out
->u
.m
[3][1] = -D3DXVec3Dot(&upn
, eye
);
389 out
->u
.m
[0][2] = -vec
.x
;
390 out
->u
.m
[1][2] = -vec
.y
;
391 out
->u
.m
[2][2] = -vec
.z
;
392 out
->u
.m
[3][2] = D3DXVec3Dot(&vec
, eye
);
393 out
->u
.m
[0][3] = 0.0f
;
394 out
->u
.m
[1][3] = 0.0f
;
395 out
->u
.m
[2][3] = 0.0f
;
396 out
->u
.m
[3][3] = 1.0f
;
401 D3DXMATRIX
* WINAPI
D3DXMatrixMultiply(D3DXMATRIX
*pout
, const D3DXMATRIX
*pm1
, const D3DXMATRIX
*pm2
)
406 TRACE("pout %p, pm1 %p, pm2 %p\n", pout
, pm1
, pm2
);
412 out
.u
.m
[i
][j
] = pm1
->u
.m
[i
][0] * pm2
->u
.m
[0][j
] + pm1
->u
.m
[i
][1] * pm2
->u
.m
[1][j
] + pm1
->u
.m
[i
][2] * pm2
->u
.m
[2][j
] + pm1
->u
.m
[i
][3] * pm2
->u
.m
[3][j
];
420 D3DXMATRIX
* WINAPI
D3DXMatrixMultiplyTranspose(D3DXMATRIX
*pout
, const D3DXMATRIX
*pm1
, const D3DXMATRIX
*pm2
)
425 TRACE("pout %p, pm1 %p, pm2 %p\n", pout
, pm1
, pm2
);
427 for (i
= 0; i
< 4; i
++)
428 for (j
= 0; j
< 4; j
++)
429 temp
.u
.m
[j
][i
] = pm1
->u
.m
[i
][0] * pm2
->u
.m
[0][j
] + pm1
->u
.m
[i
][1] * pm2
->u
.m
[1][j
] + pm1
->u
.m
[i
][2] * pm2
->u
.m
[2][j
] + pm1
->u
.m
[i
][3] * pm2
->u
.m
[3][j
];
435 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoLH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
437 TRACE("pout %p, w %f, h %f, zn %f, zf %f\n", pout
, w
, h
, zn
, zf
);
439 D3DXMatrixIdentity(pout
);
440 pout
->u
.m
[0][0] = 2.0f
/ w
;
441 pout
->u
.m
[1][1] = 2.0f
/ h
;
442 pout
->u
.m
[2][2] = 1.0f
/ (zf
- zn
);
443 pout
->u
.m
[3][2] = zn
/ (zn
- zf
);
447 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoOffCenterLH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
449 TRACE("pout %p, l %f, r %f, b %f, t %f, zn %f, zf %f\n", pout
, l
, r
, b
, t
, zn
, zf
);
451 D3DXMatrixIdentity(pout
);
452 pout
->u
.m
[0][0] = 2.0f
/ (r
- l
);
453 pout
->u
.m
[1][1] = 2.0f
/ (t
- b
);
454 pout
->u
.m
[2][2] = 1.0f
/ (zf
-zn
);
455 pout
->u
.m
[3][0] = -1.0f
-2.0f
*l
/ (r
- l
);
456 pout
->u
.m
[3][1] = 1.0f
+ 2.0f
* t
/ (b
- t
);
457 pout
->u
.m
[3][2] = zn
/ (zn
-zf
);
461 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoOffCenterRH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
463 TRACE("pout %p, l %f, r %f, b %f, t %f, zn %f, zf %f\n", pout
, l
, r
, b
, t
, zn
, zf
);
465 D3DXMatrixIdentity(pout
);
466 pout
->u
.m
[0][0] = 2.0f
/ (r
- l
);
467 pout
->u
.m
[1][1] = 2.0f
/ (t
- b
);
468 pout
->u
.m
[2][2] = 1.0f
/ (zn
-zf
);
469 pout
->u
.m
[3][0] = -1.0f
-2.0f
*l
/ (r
- l
);
470 pout
->u
.m
[3][1] = 1.0f
+ 2.0f
* t
/ (b
- t
);
471 pout
->u
.m
[3][2] = zn
/ (zn
-zf
);
475 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoRH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
477 TRACE("pout %p, w %f, h %f, zn %f, zf %f\n", pout
, w
, h
, zn
, zf
);
479 D3DXMatrixIdentity(pout
);
480 pout
->u
.m
[0][0] = 2.0f
/ w
;
481 pout
->u
.m
[1][1] = 2.0f
/ h
;
482 pout
->u
.m
[2][2] = 1.0f
/ (zn
- zf
);
483 pout
->u
.m
[3][2] = zn
/ (zn
- zf
);
487 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveFovLH(D3DXMATRIX
*pout
, FLOAT fovy
, FLOAT aspect
, FLOAT zn
, FLOAT zf
)
489 TRACE("pout %p, fovy %f, aspect %f, zn %f, zf %f\n", pout
, fovy
, aspect
, zn
, zf
);
491 D3DXMatrixIdentity(pout
);
492 pout
->u
.m
[0][0] = 1.0f
/ (aspect
* tan(fovy
/2.0f
));
493 pout
->u
.m
[1][1] = 1.0f
/ tan(fovy
/2.0f
);
494 pout
->u
.m
[2][2] = zf
/ (zf
- zn
);
495 pout
->u
.m
[2][3] = 1.0f
;
496 pout
->u
.m
[3][2] = (zf
* zn
) / (zn
- zf
);
497 pout
->u
.m
[3][3] = 0.0f
;
501 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveFovRH(D3DXMATRIX
*pout
, FLOAT fovy
, FLOAT aspect
, FLOAT zn
, FLOAT zf
)
503 TRACE("pout %p, fovy %f, aspect %f, zn %f, zf %f\n", pout
, fovy
, aspect
, zn
, zf
);
505 D3DXMatrixIdentity(pout
);
506 pout
->u
.m
[0][0] = 1.0f
/ (aspect
* tan(fovy
/2.0f
));
507 pout
->u
.m
[1][1] = 1.0f
/ tan(fovy
/2.0f
);
508 pout
->u
.m
[2][2] = zf
/ (zn
- zf
);
509 pout
->u
.m
[2][3] = -1.0f
;
510 pout
->u
.m
[3][2] = (zf
* zn
) / (zn
- zf
);
511 pout
->u
.m
[3][3] = 0.0f
;
515 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveLH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
517 TRACE("pout %p, w %f, h %f, zn %f, zf %f\n", pout
, w
, h
, zn
, zf
);
519 D3DXMatrixIdentity(pout
);
520 pout
->u
.m
[0][0] = 2.0f
* zn
/ w
;
521 pout
->u
.m
[1][1] = 2.0f
* zn
/ h
;
522 pout
->u
.m
[2][2] = zf
/ (zf
- zn
);
523 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
- zf
);
524 pout
->u
.m
[2][3] = 1.0f
;
525 pout
->u
.m
[3][3] = 0.0f
;
529 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveOffCenterLH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
531 TRACE("pout %p, l %f, r %f, b %f, t %f, zn %f, zf %f\n", pout
, l
, r
, b
, t
, zn
, zf
);
533 D3DXMatrixIdentity(pout
);
534 pout
->u
.m
[0][0] = 2.0f
* zn
/ (r
- l
);
535 pout
->u
.m
[1][1] = -2.0f
* zn
/ (b
- t
);
536 pout
->u
.m
[2][0] = -1.0f
- 2.0f
* l
/ (r
- l
);
537 pout
->u
.m
[2][1] = 1.0f
+ 2.0f
* t
/ (b
- t
);
538 pout
->u
.m
[2][2] = - zf
/ (zn
- zf
);
539 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
-zf
);
540 pout
->u
.m
[2][3] = 1.0f
;
541 pout
->u
.m
[3][3] = 0.0f
;
545 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveOffCenterRH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
547 TRACE("pout %p, l %f, r %f, b %f, t %f, zn %f, zf %f\n", pout
, l
, r
, b
, t
, zn
, zf
);
549 D3DXMatrixIdentity(pout
);
550 pout
->u
.m
[0][0] = 2.0f
* zn
/ (r
- l
);
551 pout
->u
.m
[1][1] = -2.0f
* zn
/ (b
- t
);
552 pout
->u
.m
[2][0] = 1.0f
+ 2.0f
* l
/ (r
- l
);
553 pout
->u
.m
[2][1] = -1.0f
-2.0f
* t
/ (b
- t
);
554 pout
->u
.m
[2][2] = zf
/ (zn
- zf
);
555 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
-zf
);
556 pout
->u
.m
[2][3] = -1.0f
;
557 pout
->u
.m
[3][3] = 0.0f
;
561 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveRH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
563 TRACE("pout %p, w %f, h %f, zn %f, zf %f\n", pout
, w
, h
, zn
, zf
);
565 D3DXMatrixIdentity(pout
);
566 pout
->u
.m
[0][0] = 2.0f
* zn
/ w
;
567 pout
->u
.m
[1][1] = 2.0f
* zn
/ h
;
568 pout
->u
.m
[2][2] = zf
/ (zn
- zf
);
569 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
- zf
);
570 pout
->u
.m
[2][3] = -1.0f
;
571 pout
->u
.m
[3][3] = 0.0f
;
575 D3DXMATRIX
* WINAPI
D3DXMatrixReflect(D3DXMATRIX
*pout
, const D3DXPLANE
*pplane
)
579 TRACE("pout %p, pplane %p\n", pout
, pplane
);
581 D3DXPlaneNormalize(&Nplane
, pplane
);
582 D3DXMatrixIdentity(pout
);
583 pout
->u
.m
[0][0] = 1.0f
- 2.0f
* Nplane
.a
* Nplane
.a
;
584 pout
->u
.m
[0][1] = -2.0f
* Nplane
.a
* Nplane
.b
;
585 pout
->u
.m
[0][2] = -2.0f
* Nplane
.a
* Nplane
.c
;
586 pout
->u
.m
[1][0] = -2.0f
* Nplane
.a
* Nplane
.b
;
587 pout
->u
.m
[1][1] = 1.0f
- 2.0f
* Nplane
.b
* Nplane
.b
;
588 pout
->u
.m
[1][2] = -2.0f
* Nplane
.b
* Nplane
.c
;
589 pout
->u
.m
[2][0] = -2.0f
* Nplane
.c
* Nplane
.a
;
590 pout
->u
.m
[2][1] = -2.0f
* Nplane
.c
* Nplane
.b
;
591 pout
->u
.m
[2][2] = 1.0f
- 2.0f
* Nplane
.c
* Nplane
.c
;
592 pout
->u
.m
[3][0] = -2.0f
* Nplane
.d
* Nplane
.a
;
593 pout
->u
.m
[3][1] = -2.0f
* Nplane
.d
* Nplane
.b
;
594 pout
->u
.m
[3][2] = -2.0f
* Nplane
.d
* Nplane
.c
;
598 D3DXMATRIX
* WINAPI
D3DXMatrixRotationAxis(D3DXMATRIX
*out
, const D3DXVECTOR3
*v
, FLOAT angle
)
601 FLOAT sangle
, cangle
, cdiff
;
603 TRACE("out %p, v %p, angle %f\n", out
, v
, angle
);
605 D3DXVec3Normalize(&nv
, v
);
606 sangle
= sinf(angle
);
607 cangle
= cosf(angle
);
608 cdiff
= 1.0f
- cangle
;
610 out
->u
.m
[0][0] = cdiff
* nv
.x
* nv
.x
+ cangle
;
611 out
->u
.m
[1][0] = cdiff
* nv
.x
* nv
.y
- sangle
* nv
.z
;
612 out
->u
.m
[2][0] = cdiff
* nv
.x
* nv
.z
+ sangle
* nv
.y
;
613 out
->u
.m
[3][0] = 0.0f
;
614 out
->u
.m
[0][1] = cdiff
* nv
.y
* nv
.x
+ sangle
* nv
.z
;
615 out
->u
.m
[1][1] = cdiff
* nv
.y
* nv
.y
+ cangle
;
616 out
->u
.m
[2][1] = cdiff
* nv
.y
* nv
.z
- sangle
* nv
.x
;
617 out
->u
.m
[3][1] = 0.0f
;
618 out
->u
.m
[0][2] = cdiff
* nv
.z
* nv
.x
- sangle
* nv
.y
;
619 out
->u
.m
[1][2] = cdiff
* nv
.z
* nv
.y
+ sangle
* nv
.x
;
620 out
->u
.m
[2][2] = cdiff
* nv
.z
* nv
.z
+ cangle
;
621 out
->u
.m
[3][2] = 0.0f
;
622 out
->u
.m
[0][3] = 0.0f
;
623 out
->u
.m
[1][3] = 0.0f
;
624 out
->u
.m
[2][3] = 0.0f
;
625 out
->u
.m
[3][3] = 1.0f
;
630 D3DXMATRIX
* WINAPI
D3DXMatrixRotationQuaternion(D3DXMATRIX
*pout
, const D3DXQUATERNION
*pq
)
632 TRACE("pout %p, pq %p\n", pout
, pq
);
634 D3DXMatrixIdentity(pout
);
635 pout
->u
.m
[0][0] = 1.0f
- 2.0f
* (pq
->y
* pq
->y
+ pq
->z
* pq
->z
);
636 pout
->u
.m
[0][1] = 2.0f
* (pq
->x
*pq
->y
+ pq
->z
* pq
->w
);
637 pout
->u
.m
[0][2] = 2.0f
* (pq
->x
* pq
->z
- pq
->y
* pq
->w
);
638 pout
->u
.m
[1][0] = 2.0f
* (pq
->x
* pq
->y
- pq
->z
* pq
->w
);
639 pout
->u
.m
[1][1] = 1.0f
- 2.0f
* (pq
->x
* pq
->x
+ pq
->z
* pq
->z
);
640 pout
->u
.m
[1][2] = 2.0f
* (pq
->y
*pq
->z
+ pq
->x
*pq
->w
);
641 pout
->u
.m
[2][0] = 2.0f
* (pq
->x
* pq
->z
+ pq
->y
* pq
->w
);
642 pout
->u
.m
[2][1] = 2.0f
* (pq
->y
*pq
->z
- pq
->x
*pq
->w
);
643 pout
->u
.m
[2][2] = 1.0f
- 2.0f
* (pq
->x
* pq
->x
+ pq
->y
* pq
->y
);
647 D3DXMATRIX
* WINAPI
D3DXMatrixRotationX(D3DXMATRIX
*pout
, FLOAT angle
)
649 TRACE("pout %p, angle %f\n", pout
, angle
);
651 D3DXMatrixIdentity(pout
);
652 pout
->u
.m
[1][1] = cos(angle
);
653 pout
->u
.m
[2][2] = cos(angle
);
654 pout
->u
.m
[1][2] = sin(angle
);
655 pout
->u
.m
[2][1] = -sin(angle
);
659 D3DXMATRIX
* WINAPI
D3DXMatrixRotationY(D3DXMATRIX
*pout
, FLOAT angle
)
661 TRACE("pout %p, angle %f\n", pout
, angle
);
663 D3DXMatrixIdentity(pout
);
664 pout
->u
.m
[0][0] = cos(angle
);
665 pout
->u
.m
[2][2] = cos(angle
);
666 pout
->u
.m
[0][2] = -sin(angle
);
667 pout
->u
.m
[2][0] = sin(angle
);
671 D3DXMATRIX
* WINAPI
D3DXMatrixRotationYawPitchRoll(D3DXMATRIX
*out
, FLOAT yaw
, FLOAT pitch
, FLOAT roll
)
673 FLOAT sroll
, croll
, spitch
, cpitch
, syaw
, cyaw
;
675 TRACE("out %p, yaw %f, pitch %f, roll %f\n", out
, yaw
, pitch
, roll
);
679 spitch
= sinf(pitch
);
680 cpitch
= cosf(pitch
);
684 out
->u
.m
[0][0] = sroll
* spitch
* syaw
+ croll
* cyaw
;
685 out
->u
.m
[0][1] = sroll
* cpitch
;
686 out
->u
.m
[0][2] = sroll
* spitch
* cyaw
- croll
* syaw
;
687 out
->u
.m
[0][3] = 0.0f
;
688 out
->u
.m
[1][0] = croll
* spitch
* syaw
- sroll
* cyaw
;
689 out
->u
.m
[1][1] = croll
* cpitch
;
690 out
->u
.m
[1][2] = croll
* spitch
* cyaw
+ sroll
* syaw
;
691 out
->u
.m
[1][3] = 0.0f
;
692 out
->u
.m
[2][0] = cpitch
* syaw
;
693 out
->u
.m
[2][1] = -spitch
;
694 out
->u
.m
[2][2] = cpitch
* cyaw
;
695 out
->u
.m
[2][3] = 0.0f
;
696 out
->u
.m
[3][0] = 0.0f
;
697 out
->u
.m
[3][1] = 0.0f
;
698 out
->u
.m
[3][2] = 0.0f
;
699 out
->u
.m
[3][3] = 1.0f
;
704 D3DXMATRIX
* WINAPI
D3DXMatrixRotationZ(D3DXMATRIX
*pout
, FLOAT angle
)
706 TRACE("pout %p, angle %f\n", pout
, angle
);
708 D3DXMatrixIdentity(pout
);
709 pout
->u
.m
[0][0] = cos(angle
);
710 pout
->u
.m
[1][1] = cos(angle
);
711 pout
->u
.m
[0][1] = sin(angle
);
712 pout
->u
.m
[1][0] = -sin(angle
);
716 D3DXMATRIX
* WINAPI
D3DXMatrixScaling(D3DXMATRIX
*pout
, FLOAT sx
, FLOAT sy
, FLOAT sz
)
718 TRACE("pout %p, sx %f, sy %f, sz %f\n", pout
, sx
, sy
, sz
);
720 D3DXMatrixIdentity(pout
);
721 pout
->u
.m
[0][0] = sx
;
722 pout
->u
.m
[1][1] = sy
;
723 pout
->u
.m
[2][2] = sz
;
727 D3DXMATRIX
* WINAPI
D3DXMatrixShadow(D3DXMATRIX
*pout
, const D3DXVECTOR4
*plight
, const D3DXPLANE
*pplane
)
732 TRACE("pout %p, plight %p, pplane %p\n", pout
, plight
, pplane
);
734 D3DXPlaneNormalize(&Nplane
, pplane
);
735 dot
= D3DXPlaneDot(&Nplane
, plight
);
736 pout
->u
.m
[0][0] = dot
- Nplane
.a
* plight
->x
;
737 pout
->u
.m
[0][1] = -Nplane
.a
* plight
->y
;
738 pout
->u
.m
[0][2] = -Nplane
.a
* plight
->z
;
739 pout
->u
.m
[0][3] = -Nplane
.a
* plight
->w
;
740 pout
->u
.m
[1][0] = -Nplane
.b
* plight
->x
;
741 pout
->u
.m
[1][1] = dot
- Nplane
.b
* plight
->y
;
742 pout
->u
.m
[1][2] = -Nplane
.b
* plight
->z
;
743 pout
->u
.m
[1][3] = -Nplane
.b
* plight
->w
;
744 pout
->u
.m
[2][0] = -Nplane
.c
* plight
->x
;
745 pout
->u
.m
[2][1] = -Nplane
.c
* plight
->y
;
746 pout
->u
.m
[2][2] = dot
- Nplane
.c
* plight
->z
;
747 pout
->u
.m
[2][3] = -Nplane
.c
* plight
->w
;
748 pout
->u
.m
[3][0] = -Nplane
.d
* plight
->x
;
749 pout
->u
.m
[3][1] = -Nplane
.d
* plight
->y
;
750 pout
->u
.m
[3][2] = -Nplane
.d
* plight
->z
;
751 pout
->u
.m
[3][3] = dot
- Nplane
.d
* plight
->w
;
755 D3DXMATRIX
* WINAPI
D3DXMatrixTransformation(D3DXMATRIX
*pout
, const D3DXVECTOR3
*pscalingcenter
, const D3DXQUATERNION
*pscalingrotation
, const D3DXVECTOR3
*pscaling
, const D3DXVECTOR3
*protationcenter
, const D3DXQUATERNION
*protation
, const D3DXVECTOR3
*ptranslation
)
757 D3DXMATRIX m1
, m2
, m3
, m4
, m5
, m6
, m7
;
761 TRACE("pout %p, pscalingcenter %p, pscalingrotation %p, pscaling %p, protationcentr %p, protation %p, ptranslation %p\n",
762 pout
, pscalingcenter
, pscalingrotation
, pscaling
, protationcenter
, protation
, ptranslation
);
764 if ( !pscalingcenter
)
772 psc
.x
= pscalingcenter
->x
;
773 psc
.y
= pscalingcenter
->y
;
774 psc
.z
= pscalingcenter
->z
;
777 if ( !protationcenter
)
785 prc
.x
= protationcenter
->x
;
786 prc
.y
= protationcenter
->y
;
787 prc
.z
= protationcenter
->z
;
798 pt
.x
= ptranslation
->x
;
799 pt
.y
= ptranslation
->y
;
800 pt
.z
= ptranslation
->z
;
803 D3DXMatrixTranslation(&m1
, -psc
.x
, -psc
.y
, -psc
.z
);
805 if ( !pscalingrotation
)
807 D3DXMatrixIdentity(&m2
);
808 D3DXMatrixIdentity(&m4
);
812 D3DXMatrixRotationQuaternion(&m4
, pscalingrotation
);
813 D3DXMatrixInverse(&m2
, NULL
, &m4
);
816 if ( !pscaling
) D3DXMatrixIdentity(&m3
);
817 else D3DXMatrixScaling(&m3
, pscaling
->x
, pscaling
->y
, pscaling
->z
);
819 if ( !protation
) D3DXMatrixIdentity(&m6
);
820 else D3DXMatrixRotationQuaternion(&m6
, protation
);
822 D3DXMatrixTranslation(&m5
, psc
.x
- prc
.x
, psc
.y
- prc
.y
, psc
.z
- prc
.z
);
823 D3DXMatrixTranslation(&m7
, prc
.x
+ pt
.x
, prc
.y
+ pt
.y
, prc
.z
+ pt
.z
);
824 D3DXMatrixMultiply(&m1
, &m1
, &m2
);
825 D3DXMatrixMultiply(&m1
, &m1
, &m3
);
826 D3DXMatrixMultiply(&m1
, &m1
, &m4
);
827 D3DXMatrixMultiply(&m1
, &m1
, &m5
);
828 D3DXMatrixMultiply(&m1
, &m1
, &m6
);
829 D3DXMatrixMultiply(pout
, &m1
, &m7
);
833 D3DXMATRIX
* WINAPI
D3DXMatrixTransformation2D(D3DXMATRIX
*pout
, const D3DXVECTOR2
*pscalingcenter
, FLOAT scalingrotation
, const D3DXVECTOR2
*pscaling
, const D3DXVECTOR2
*protationcenter
, FLOAT rotation
, const D3DXVECTOR2
*ptranslation
)
835 D3DXQUATERNION rot
, sca_rot
;
836 D3DXVECTOR3 rot_center
, sca
, sca_center
, trans
;
838 TRACE("pout %p, pscalingcenter %p, scalingrotation %f, pscaling %p, protztioncenter %p, rotation %f, ptranslation %p\n",
839 pout
, pscalingcenter
, scalingrotation
, pscaling
, protationcenter
, rotation
, ptranslation
);
841 if ( pscalingcenter
)
843 sca_center
.x
=pscalingcenter
->x
;
844 sca_center
.y
=pscalingcenter
->y
;
867 if ( protationcenter
)
869 rot_center
.x
=protationcenter
->x
;
870 rot_center
.y
=protationcenter
->y
;
882 trans
.x
=ptranslation
->x
;
883 trans
.y
=ptranslation
->y
;
893 rot
.w
=cos(rotation
/2.0f
);
896 rot
.z
=sin(rotation
/2.0f
);
898 sca_rot
.w
=cos(scalingrotation
/2.0f
);
901 sca_rot
.z
=sin(scalingrotation
/2.0f
);
903 D3DXMatrixTransformation(pout
, &sca_center
, &sca_rot
, &sca
, &rot_center
, &rot
, &trans
);
908 D3DXMATRIX
* WINAPI
D3DXMatrixTranslation(D3DXMATRIX
*pout
, FLOAT x
, FLOAT y
, FLOAT z
)
910 TRACE("pout %p, x %f, y %f, z %f\n", pout
, x
, y
, z
);
912 D3DXMatrixIdentity(pout
);
919 D3DXMATRIX
* WINAPI
D3DXMatrixTranspose(D3DXMATRIX
*pout
, const D3DXMATRIX
*pm
)
921 const D3DXMATRIX m
= *pm
;
924 TRACE("pout %p, pm %p\n", pout
, pm
);
927 for (j
=0; j
<4; j
++) pout
->u
.m
[i
][j
] = m
.u
.m
[j
][i
];
932 /*_________________D3DXMatrixStack____________________*/
935 static inline struct ID3DXMatrixStackImpl
*impl_from_ID3DXMatrixStack(ID3DXMatrixStack
*iface
)
937 return CONTAINING_RECORD(iface
, struct ID3DXMatrixStackImpl
, ID3DXMatrixStack_iface
);
940 static HRESULT WINAPI
ID3DXMatrixStackImpl_QueryInterface(ID3DXMatrixStack
*iface
, REFIID riid
, void **out
)
942 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
944 if (IsEqualGUID(riid
, &IID_ID3DXMatrixStack
)
945 || IsEqualGUID(riid
, &IID_IUnknown
))
947 ID3DXMatrixStack_AddRef(iface
);
952 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
955 return E_NOINTERFACE
;
958 static ULONG WINAPI
ID3DXMatrixStackImpl_AddRef(ID3DXMatrixStack
*iface
)
960 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
961 ULONG ref
= InterlockedIncrement(&This
->ref
);
962 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
966 static ULONG WINAPI
ID3DXMatrixStackImpl_Release(ID3DXMatrixStack
*iface
)
968 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
969 ULONG ref
= InterlockedDecrement(&This
->ref
);
972 HeapFree(GetProcessHeap(), 0, This
->stack
);
973 HeapFree(GetProcessHeap(), 0, This
);
975 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
979 static D3DXMATRIX
* WINAPI
ID3DXMatrixStackImpl_GetTop(ID3DXMatrixStack
*iface
)
981 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
983 TRACE("iface %p\n", iface
);
985 return &This
->stack
[This
->current
];
988 static HRESULT WINAPI
ID3DXMatrixStackImpl_LoadIdentity(ID3DXMatrixStack
*iface
)
990 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
992 TRACE("iface %p\n", iface
);
994 D3DXMatrixIdentity(&This
->stack
[This
->current
]);
999 static HRESULT WINAPI
ID3DXMatrixStackImpl_LoadMatrix(ID3DXMatrixStack
*iface
, const D3DXMATRIX
*pm
)
1001 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1003 TRACE("iface %p, pm %p\n", iface
, pm
);
1005 This
->stack
[This
->current
] = *pm
;
1010 static HRESULT WINAPI
ID3DXMatrixStackImpl_MultMatrix(ID3DXMatrixStack
*iface
, const D3DXMATRIX
*pm
)
1012 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1014 TRACE("iface %p, pm %p\n", iface
, pm
);
1016 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], pm
);
1021 static HRESULT WINAPI
ID3DXMatrixStackImpl_MultMatrixLocal(ID3DXMatrixStack
*iface
, const D3DXMATRIX
*pm
)
1023 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1025 TRACE("iface %p, pm %p\n", iface
, pm
);
1027 D3DXMatrixMultiply(&This
->stack
[This
->current
], pm
, &This
->stack
[This
->current
]);
1032 static HRESULT WINAPI
ID3DXMatrixStackImpl_Pop(ID3DXMatrixStack
*iface
)
1034 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1036 TRACE("iface %p\n", iface
);
1038 /* Popping the last element on the stack returns D3D_OK, but does nothing. */
1039 if (!This
->current
) return D3D_OK
;
1041 if (This
->current
<= This
->stack_size
/ 4 && This
->stack_size
>= INITIAL_STACK_SIZE
* 2)
1043 unsigned int new_size
;
1044 D3DXMATRIX
*new_stack
;
1046 new_size
= This
->stack_size
/ 2;
1047 new_stack
= HeapReAlloc(GetProcessHeap(), 0, This
->stack
, new_size
* sizeof(*new_stack
));
1050 This
->stack_size
= new_size
;
1051 This
->stack
= new_stack
;
1060 static HRESULT WINAPI
ID3DXMatrixStackImpl_Push(ID3DXMatrixStack
*iface
)
1062 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1064 TRACE("iface %p\n", iface
);
1066 if (This
->current
== This
->stack_size
- 1)
1068 unsigned int new_size
;
1069 D3DXMATRIX
*new_stack
;
1071 if (This
->stack_size
> UINT_MAX
/ 2) return E_OUTOFMEMORY
;
1073 new_size
= This
->stack_size
* 2;
1074 new_stack
= HeapReAlloc(GetProcessHeap(), 0, This
->stack
, new_size
* sizeof(*new_stack
));
1075 if (!new_stack
) return E_OUTOFMEMORY
;
1077 This
->stack_size
= new_size
;
1078 This
->stack
= new_stack
;
1082 This
->stack
[This
->current
] = This
->stack
[This
->current
- 1];
1087 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateAxis(ID3DXMatrixStack
*iface
, const D3DXVECTOR3
*pv
, FLOAT angle
)
1090 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1092 TRACE("iface %p, pv %p, angle %f\n", iface
, pv
, angle
);
1094 D3DXMatrixRotationAxis(&temp
, pv
, angle
);
1095 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
1100 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateAxisLocal(ID3DXMatrixStack
*iface
, const D3DXVECTOR3
*pv
, FLOAT angle
)
1103 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1105 TRACE("iface %p, pv %p, angle %f\n", iface
, pv
, angle
);
1107 D3DXMatrixRotationAxis(&temp
, pv
, angle
);
1108 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
, &This
->stack
[This
->current
]);
1113 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateYawPitchRoll(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1116 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1118 TRACE("iface %p, x %f, y %f, z %f\n", iface
, x
, y
, z
);
1120 D3DXMatrixRotationYawPitchRoll(&temp
, x
, y
, z
);
1121 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
1126 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateYawPitchRollLocal(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1129 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1131 TRACE("iface %p, x %f, y %f, z %f\n", iface
, x
, y
, z
);
1133 D3DXMatrixRotationYawPitchRoll(&temp
, x
, y
, z
);
1134 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
, &This
->stack
[This
->current
]);
1139 static HRESULT WINAPI
ID3DXMatrixStackImpl_Scale(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1142 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1144 TRACE("iface %p,x %f, y %f, z %f\n", iface
, x
, y
, z
);
1146 D3DXMatrixScaling(&temp
, x
, y
, z
);
1147 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
1152 static HRESULT WINAPI
ID3DXMatrixStackImpl_ScaleLocal(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1155 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1157 TRACE("iface %p, x %f, y %f, z %f\n", iface
, x
, y
, z
);
1159 D3DXMatrixScaling(&temp
, x
, y
, z
);
1160 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
, &This
->stack
[This
->current
]);
1165 static HRESULT WINAPI
ID3DXMatrixStackImpl_Translate(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1168 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1170 TRACE("iface %p, x %f, y %f, z %f\n", iface
, x
, y
, z
);
1172 D3DXMatrixTranslation(&temp
, x
, y
, z
);
1173 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
1178 static HRESULT WINAPI
ID3DXMatrixStackImpl_TranslateLocal(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1181 struct ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1183 TRACE("iface %p, x %f, y %f, z %f\n", iface
, x
, y
, z
);
1185 D3DXMatrixTranslation(&temp
, x
, y
, z
);
1186 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
,&This
->stack
[This
->current
]);
1191 static const ID3DXMatrixStackVtbl ID3DXMatrixStack_Vtbl
=
1193 ID3DXMatrixStackImpl_QueryInterface
,
1194 ID3DXMatrixStackImpl_AddRef
,
1195 ID3DXMatrixStackImpl_Release
,
1196 ID3DXMatrixStackImpl_Pop
,
1197 ID3DXMatrixStackImpl_Push
,
1198 ID3DXMatrixStackImpl_LoadIdentity
,
1199 ID3DXMatrixStackImpl_LoadMatrix
,
1200 ID3DXMatrixStackImpl_MultMatrix
,
1201 ID3DXMatrixStackImpl_MultMatrixLocal
,
1202 ID3DXMatrixStackImpl_RotateAxis
,
1203 ID3DXMatrixStackImpl_RotateAxisLocal
,
1204 ID3DXMatrixStackImpl_RotateYawPitchRoll
,
1205 ID3DXMatrixStackImpl_RotateYawPitchRollLocal
,
1206 ID3DXMatrixStackImpl_Scale
,
1207 ID3DXMatrixStackImpl_ScaleLocal
,
1208 ID3DXMatrixStackImpl_Translate
,
1209 ID3DXMatrixStackImpl_TranslateLocal
,
1210 ID3DXMatrixStackImpl_GetTop
1213 HRESULT WINAPI
D3DXCreateMatrixStack(DWORD flags
, ID3DXMatrixStack
**stack
)
1215 struct ID3DXMatrixStackImpl
*object
;
1217 TRACE("flags %#x, stack %p.\n", flags
, stack
);
1219 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
1222 return E_OUTOFMEMORY
;
1224 object
->ID3DXMatrixStack_iface
.lpVtbl
= &ID3DXMatrixStack_Vtbl
;
1227 if (!(object
->stack
= HeapAlloc(GetProcessHeap(), 0, INITIAL_STACK_SIZE
* sizeof(*object
->stack
))))
1229 HeapFree(GetProcessHeap(), 0, object
);
1231 return E_OUTOFMEMORY
;
1234 object
->current
= 0;
1235 object
->stack_size
= INITIAL_STACK_SIZE
;
1236 D3DXMatrixIdentity(&object
->stack
[0]);
1238 TRACE("Created matrix stack %p.\n", object
);
1240 *stack
= &object
->ID3DXMatrixStack_iface
;
1244 /*_________________D3DXPLANE________________*/
1246 D3DXPLANE
* WINAPI
D3DXPlaneFromPointNormal(D3DXPLANE
*pout
, const D3DXVECTOR3
*pvpoint
, const D3DXVECTOR3
*pvnormal
)
1248 TRACE("pout %p, pvpoint %p, pvnormal %p\n", pout
, pvpoint
, pvnormal
);
1250 pout
->a
= pvnormal
->x
;
1251 pout
->b
= pvnormal
->y
;
1252 pout
->c
= pvnormal
->z
;
1253 pout
->d
= -D3DXVec3Dot(pvpoint
, pvnormal
);
1257 D3DXPLANE
* WINAPI
D3DXPlaneFromPoints(D3DXPLANE
*pout
, const D3DXVECTOR3
*pv1
, const D3DXVECTOR3
*pv2
, const D3DXVECTOR3
*pv3
)
1259 D3DXVECTOR3 edge1
, edge2
, normal
, Nnormal
;
1261 TRACE("pout %p, pv1 %p, pv2 %p, pv3 %p\n", pout
, pv1
, pv2
, pv3
);
1263 edge1
.x
= 0.0f
; edge1
.y
= 0.0f
; edge1
.z
= 0.0f
;
1264 edge2
.x
= 0.0f
; edge2
.y
= 0.0f
; edge2
.z
= 0.0f
;
1265 D3DXVec3Subtract(&edge1
, pv2
, pv1
);
1266 D3DXVec3Subtract(&edge2
, pv3
, pv1
);
1267 D3DXVec3Cross(&normal
, &edge1
, &edge2
);
1268 D3DXVec3Normalize(&Nnormal
, &normal
);
1269 D3DXPlaneFromPointNormal(pout
, pv1
, &Nnormal
);
1273 D3DXVECTOR3
* WINAPI
D3DXPlaneIntersectLine(D3DXVECTOR3
*pout
, const D3DXPLANE
*pp
, const D3DXVECTOR3
*pv1
, const D3DXVECTOR3
*pv2
)
1275 D3DXVECTOR3 direction
, normal
;
1278 TRACE("pout %p, pp %p, pv1 %p, pv2 %p\n", pout
, pp
, pv1
, pv2
);
1283 direction
.x
= pv2
->x
- pv1
->x
;
1284 direction
.y
= pv2
->y
- pv1
->y
;
1285 direction
.z
= pv2
->z
- pv1
->z
;
1286 dot
= D3DXVec3Dot(&normal
, &direction
);
1287 if ( !dot
) return NULL
;
1288 temp
= ( pp
->d
+ D3DXVec3Dot(&normal
, pv1
) ) / dot
;
1289 pout
->x
= pv1
->x
- temp
* direction
.x
;
1290 pout
->y
= pv1
->y
- temp
* direction
.y
;
1291 pout
->z
= pv1
->z
- temp
* direction
.z
;
1295 D3DXPLANE
* WINAPI
D3DXPlaneNormalize(D3DXPLANE
*out
, const D3DXPLANE
*p
)
1299 TRACE("out %p, p %p\n", out
, p
);
1301 norm
= sqrtf(p
->a
* p
->a
+ p
->b
* p
->b
+ p
->c
* p
->c
);
1304 out
->a
= p
->a
/ norm
;
1305 out
->b
= p
->b
/ norm
;
1306 out
->c
= p
->c
/ norm
;
1307 out
->d
= p
->d
/ norm
;
1320 D3DXPLANE
* WINAPI
D3DXPlaneTransform(D3DXPLANE
*pout
, const D3DXPLANE
*pplane
, const D3DXMATRIX
*pm
)
1322 const D3DXPLANE plane
= *pplane
;
1324 TRACE("pout %p, pplane %p, pm %p\n", pout
, pplane
, pm
);
1326 pout
->a
= pm
->u
.m
[0][0] * plane
.a
+ pm
->u
.m
[1][0] * plane
.b
+ pm
->u
.m
[2][0] * plane
.c
+ pm
->u
.m
[3][0] * plane
.d
;
1327 pout
->b
= pm
->u
.m
[0][1] * plane
.a
+ pm
->u
.m
[1][1] * plane
.b
+ pm
->u
.m
[2][1] * plane
.c
+ pm
->u
.m
[3][1] * plane
.d
;
1328 pout
->c
= pm
->u
.m
[0][2] * plane
.a
+ pm
->u
.m
[1][2] * plane
.b
+ pm
->u
.m
[2][2] * plane
.c
+ pm
->u
.m
[3][2] * plane
.d
;
1329 pout
->d
= pm
->u
.m
[0][3] * plane
.a
+ pm
->u
.m
[1][3] * plane
.b
+ pm
->u
.m
[2][3] * plane
.c
+ pm
->u
.m
[3][3] * plane
.d
;
1333 D3DXPLANE
* WINAPI
D3DXPlaneTransformArray(D3DXPLANE
* out
, UINT outstride
, const D3DXPLANE
* in
, UINT instride
, const D3DXMATRIX
* matrix
, UINT elements
)
1337 TRACE("out %p, outstride %u, in %p, instride %u, matrix %p, elements %u\n", out
, outstride
, in
, instride
, matrix
, elements
);
1339 for (i
= 0; i
< elements
; ++i
) {
1341 (D3DXPLANE
*)((char*)out
+ outstride
* i
),
1342 (const D3DXPLANE
*)((const char*)in
+ instride
* i
),
1348 /*_________________D3DXQUATERNION________________*/
1350 D3DXQUATERNION
* WINAPI
D3DXQuaternionBaryCentric(D3DXQUATERNION
*pout
, const D3DXQUATERNION
*pq1
, const D3DXQUATERNION
*pq2
, const D3DXQUATERNION
*pq3
, FLOAT f
, FLOAT g
)
1352 D3DXQUATERNION temp1
, temp2
;
1354 TRACE("pout %p, pq1 %p, pq2 %p, pq3 %p, f %f, g %f\n", pout
, pq1
, pq2
, pq3
, f
, g
);
1356 D3DXQuaternionSlerp(pout
, D3DXQuaternionSlerp(&temp1
, pq1
, pq2
, f
+ g
), D3DXQuaternionSlerp(&temp2
, pq1
, pq3
, f
+g
), g
/ (f
+ g
));
1360 D3DXQUATERNION
* WINAPI
D3DXQuaternionExp(D3DXQUATERNION
*out
, const D3DXQUATERNION
*q
)
1364 TRACE("out %p, q %p\n", out
, q
);
1366 norm
= sqrtf(q
->x
* q
->x
+ q
->y
* q
->y
+ q
->z
* q
->z
);
1369 out
->x
= sinf(norm
) * q
->x
/ norm
;
1370 out
->y
= sinf(norm
) * q
->y
/ norm
;
1371 out
->z
= sinf(norm
) * q
->z
/ norm
;
1372 out
->w
= cosf(norm
);
1385 D3DXQUATERNION
* WINAPI
D3DXQuaternionInverse(D3DXQUATERNION
*pout
, const D3DXQUATERNION
*pq
)
1390 TRACE("pout %p, pq %p\n", pout
, pq
);
1392 norm
= D3DXQuaternionLengthSq(pq
);
1394 out
.x
= -pq
->x
/ norm
;
1395 out
.y
= -pq
->y
/ norm
;
1396 out
.z
= -pq
->z
/ norm
;
1397 out
.w
= pq
->w
/ norm
;
1403 D3DXQUATERNION
* WINAPI
D3DXQuaternionLn(D3DXQUATERNION
*out
, const D3DXQUATERNION
*q
)
1407 TRACE("out %p, q %p\n", out
, q
);
1409 if ((q
->w
>= 1.0f
) || (q
->w
== -1.0f
))
1412 t
= acosf(q
->w
) / sqrtf(1.0f
- q
->w
* q
->w
);
1422 D3DXQUATERNION
* WINAPI
D3DXQuaternionMultiply(D3DXQUATERNION
*pout
, const D3DXQUATERNION
*pq1
, const D3DXQUATERNION
*pq2
)
1426 TRACE("pout %p, pq1 %p, pq2 %p\n", pout
, pq1
, pq2
);
1428 out
.x
= pq2
->w
* pq1
->x
+ pq2
->x
* pq1
->w
+ pq2
->y
* pq1
->z
- pq2
->z
* pq1
->y
;
1429 out
.y
= pq2
->w
* pq1
->y
- pq2
->x
* pq1
->z
+ pq2
->y
* pq1
->w
+ pq2
->z
* pq1
->x
;
1430 out
.z
= pq2
->w
* pq1
->z
+ pq2
->x
* pq1
->y
- pq2
->y
* pq1
->x
+ pq2
->z
* pq1
->w
;
1431 out
.w
= pq2
->w
* pq1
->w
- pq2
->x
* pq1
->x
- pq2
->y
* pq1
->y
- pq2
->z
* pq1
->z
;
1436 D3DXQUATERNION
* WINAPI
D3DXQuaternionNormalize(D3DXQUATERNION
*out
, const D3DXQUATERNION
*q
)
1440 TRACE("out %p, q %p\n", out
, q
);
1442 norm
= D3DXQuaternionLength(q
);
1444 out
->x
= q
->x
/ norm
;
1445 out
->y
= q
->y
/ norm
;
1446 out
->z
= q
->z
/ norm
;
1447 out
->w
= q
->w
/ norm
;
1452 D3DXQUATERNION
* WINAPI
D3DXQuaternionRotationAxis(D3DXQUATERNION
*out
, const D3DXVECTOR3
*v
, FLOAT angle
)
1456 TRACE("out %p, v %p, angle %f\n", out
, v
, angle
);
1458 D3DXVec3Normalize(&temp
, v
);
1460 out
->x
= sinf(angle
/ 2.0f
) * temp
.x
;
1461 out
->y
= sinf(angle
/ 2.0f
) * temp
.y
;
1462 out
->z
= sinf(angle
/ 2.0f
) * temp
.z
;
1463 out
->w
= cosf(angle
/ 2.0f
);
1468 D3DXQUATERNION
* WINAPI
D3DXQuaternionRotationMatrix(D3DXQUATERNION
*out
, const D3DXMATRIX
*m
)
1472 TRACE("out %p, m %p\n", out
, m
);
1474 trace
= m
->u
.m
[0][0] + m
->u
.m
[1][1] + m
->u
.m
[2][2] + 1.0f
;
1477 s
= 2.0f
* sqrtf(trace
);
1478 out
->x
= (m
->u
.m
[1][2] - m
->u
.m
[2][1]) / s
;
1479 out
->y
= (m
->u
.m
[2][0] - m
->u
.m
[0][2]) / s
;
1480 out
->z
= (m
->u
.m
[0][1] - m
->u
.m
[1][0]) / s
;
1487 for (i
= 1; i
< 3; i
++)
1489 if (m
->u
.m
[i
][i
] > m
->u
.m
[maxi
][maxi
])
1496 s
= 2.0f
* sqrtf(1.0f
+ m
->u
.m
[0][0] - m
->u
.m
[1][1] - m
->u
.m
[2][2]);
1498 out
->y
= (m
->u
.m
[0][1] + m
->u
.m
[1][0]) / s
;
1499 out
->z
= (m
->u
.m
[0][2] + m
->u
.m
[2][0]) / s
;
1500 out
->w
= (m
->u
.m
[1][2] - m
->u
.m
[2][1]) / s
;
1504 s
= 2.0f
* sqrtf(1.0f
+ m
->u
.m
[1][1] - m
->u
.m
[0][0] - m
->u
.m
[2][2]);
1505 out
->x
= (m
->u
.m
[0][1] + m
->u
.m
[1][0]) / s
;
1507 out
->z
= (m
->u
.m
[1][2] + m
->u
.m
[2][1]) / s
;
1508 out
->w
= (m
->u
.m
[2][0] - m
->u
.m
[0][2]) / s
;
1512 s
= 2.0f
* sqrtf(1.0f
+ m
->u
.m
[2][2] - m
->u
.m
[0][0] - m
->u
.m
[1][1]);
1513 out
->x
= (m
->u
.m
[0][2] + m
->u
.m
[2][0]) / s
;
1514 out
->y
= (m
->u
.m
[1][2] + m
->u
.m
[2][1]) / s
;
1516 out
->w
= (m
->u
.m
[0][1] - m
->u
.m
[1][0]) / s
;
1524 D3DXQUATERNION
* WINAPI
D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION
*out
, FLOAT yaw
, FLOAT pitch
, FLOAT roll
)
1526 FLOAT syaw
, cyaw
, spitch
, cpitch
, sroll
, croll
;
1528 TRACE("out %p, yaw %f, pitch %f, roll %f\n", out
, yaw
, pitch
, roll
);
1530 syaw
= sinf(yaw
/ 2.0f
);
1531 cyaw
= cosf(yaw
/ 2.0f
);
1532 spitch
= sinf(pitch
/ 2.0f
);
1533 cpitch
= cosf(pitch
/ 2.0f
);
1534 sroll
= sinf(roll
/ 2.0f
);
1535 croll
= cosf(roll
/ 2.0f
);
1537 out
->x
= syaw
* cpitch
* sroll
+ cyaw
* spitch
* croll
;
1538 out
->y
= syaw
* cpitch
* croll
- cyaw
* spitch
* sroll
;
1539 out
->z
= cyaw
* cpitch
* sroll
- syaw
* spitch
* croll
;
1540 out
->w
= cyaw
* cpitch
* croll
+ syaw
* spitch
* sroll
;
1545 D3DXQUATERNION
* WINAPI
D3DXQuaternionSlerp(D3DXQUATERNION
*out
, const D3DXQUATERNION
*q1
,
1546 const D3DXQUATERNION
*q2
, FLOAT t
)
1550 TRACE("out %p, q1 %p, q2 %p, t %f\n", out
, q1
, q2
, t
);
1553 dot
= D3DXQuaternionDot(q1
, q2
);
1560 if (1.0f
- dot
> 0.001f
)
1562 FLOAT theta
= acosf(dot
);
1564 temp
= sinf(theta
* temp
) / sinf(theta
);
1565 t
= sinf(theta
* t
) / sinf(theta
);
1568 out
->x
= temp
* q1
->x
+ t
* q2
->x
;
1569 out
->y
= temp
* q1
->y
+ t
* q2
->y
;
1570 out
->z
= temp
* q1
->z
+ t
* q2
->z
;
1571 out
->w
= temp
* q1
->w
+ t
* q2
->w
;
1576 D3DXQUATERNION
* WINAPI
D3DXQuaternionSquad(D3DXQUATERNION
*pout
, const D3DXQUATERNION
*pq1
, const D3DXQUATERNION
*pq2
, const D3DXQUATERNION
*pq3
, const D3DXQUATERNION
*pq4
, FLOAT t
)
1578 D3DXQUATERNION temp1
, temp2
;
1580 TRACE("pout %p, pq1 %p, pq2 %p, pq3 %p, pq4 %p, t %f\n", pout
, pq1
, pq2
, pq3
, pq4
, t
);
1582 D3DXQuaternionSlerp(pout
, D3DXQuaternionSlerp(&temp1
, pq1
, pq4
, t
), D3DXQuaternionSlerp(&temp2
, pq2
, pq3
, t
), 2.0f
* t
* (1.0f
- t
));
1586 static D3DXQUATERNION
add_diff(const D3DXQUATERNION
*q1
, const D3DXQUATERNION
*q2
, const FLOAT add
)
1588 D3DXQUATERNION temp
;
1590 temp
.x
= q1
->x
+ add
* q2
->x
;
1591 temp
.y
= q1
->y
+ add
* q2
->y
;
1592 temp
.z
= q1
->z
+ add
* q2
->z
;
1593 temp
.w
= q1
->w
+ add
* q2
->w
;
1598 void WINAPI
D3DXQuaternionSquadSetup(D3DXQUATERNION
*paout
, D3DXQUATERNION
*pbout
, D3DXQUATERNION
*pcout
, const D3DXQUATERNION
*pq0
, const D3DXQUATERNION
*pq1
, const D3DXQUATERNION
*pq2
, const D3DXQUATERNION
*pq3
)
1600 D3DXQUATERNION q
, temp1
, temp2
, temp3
, zero
;
1602 TRACE("paout %p, pbout %p, pcout %p, pq0 %p, pq1 %p, pq2 %p, pq3 %p\n", paout
, pbout
, pcout
, pq0
, pq1
, pq2
, pq3
);
1609 if ( D3DXQuaternionDot(pq0
, pq1
) < 0.0f
)
1610 temp2
= add_diff(&zero
, pq0
, -1.0f
);
1614 if ( D3DXQuaternionDot(pq1
, pq2
) < 0.0f
)
1615 *pcout
= add_diff(&zero
, pq2
, -1.0f
);
1619 if ( D3DXQuaternionDot(pcout
, pq3
) < 0.0f
)
1620 temp3
= add_diff(&zero
, pq3
, -1.0f
);
1624 D3DXQuaternionInverse(&temp1
, pq1
);
1625 D3DXQuaternionMultiply(&temp2
, &temp1
, &temp2
);
1626 D3DXQuaternionLn(&temp2
, &temp2
);
1627 D3DXQuaternionMultiply(&q
, &temp1
, pcout
);
1628 D3DXQuaternionLn(&q
, &q
);
1629 temp1
= add_diff(&temp2
, &q
, 1.0f
);
1634 D3DXQuaternionExp(&temp1
, &temp1
);
1635 D3DXQuaternionMultiply(paout
, pq1
, &temp1
);
1637 D3DXQuaternionInverse(&temp1
, pcout
);
1638 D3DXQuaternionMultiply(&temp2
, &temp1
, pq1
);
1639 D3DXQuaternionLn(&temp2
, &temp2
);
1640 D3DXQuaternionMultiply(&q
, &temp1
, &temp3
);
1641 D3DXQuaternionLn(&q
, &q
);
1642 temp1
= add_diff(&temp2
, &q
, 1.0f
);
1647 D3DXQuaternionExp(&temp1
, &temp1
);
1648 D3DXQuaternionMultiply(pbout
, pcout
, &temp1
);
1653 void WINAPI
D3DXQuaternionToAxisAngle(const D3DXQUATERNION
*pq
, D3DXVECTOR3
*paxis
, FLOAT
*pangle
)
1655 TRACE("pq %p, paxis %p, pangle %p\n", pq
, paxis
, pangle
);
1660 *pangle
= 2.0f
* acos(pq
->w
);
1663 /*_________________D3DXVec2_____________________*/
1665 D3DXVECTOR2
* WINAPI
D3DXVec2BaryCentric(D3DXVECTOR2
*pout
, const D3DXVECTOR2
*pv1
, const D3DXVECTOR2
*pv2
, const D3DXVECTOR2
*pv3
, FLOAT f
, FLOAT g
)
1667 TRACE("pout %p, pv1 %p, pv2 %p, pv3 %p, f %f, g %f\n", pout
, pv1
, pv2
, pv3
, f
, g
);
1669 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
1670 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
1674 D3DXVECTOR2
* WINAPI
D3DXVec2CatmullRom(D3DXVECTOR2
*pout
, const D3DXVECTOR2
*pv0
, const D3DXVECTOR2
*pv1
, const D3DXVECTOR2
*pv2
, const D3DXVECTOR2
*pv3
, FLOAT s
)
1676 TRACE("pout %p, pv0 %p, pv1 %p, pv2 %p, pv3 %p, s %f\n", pout
, pv0
, pv1
, pv2
, pv3
, s
);
1678 pout
->x
= 0.5f
* (2.0f
* pv1
->x
+ (pv2
->x
- pv0
->x
) *s
+ (2.0f
*pv0
->x
- 5.0f
* pv1
->x
+ 4.0f
* pv2
->x
- pv3
->x
) * s
* s
+ (pv3
->x
-3.0f
* pv2
->x
+ 3.0f
* pv1
->x
- pv0
->x
) * s
* s
* s
);
1679 pout
->y
= 0.5f
* (2.0f
* pv1
->y
+ (pv2
->y
- pv0
->y
) *s
+ (2.0f
*pv0
->y
- 5.0f
* pv1
->y
+ 4.0f
* pv2
->y
- pv3
->y
) * s
* s
+ (pv3
->y
-3.0f
* pv2
->y
+ 3.0f
* pv1
->y
- pv0
->y
) * s
* s
* s
);
1683 D3DXVECTOR2
* WINAPI
D3DXVec2Hermite(D3DXVECTOR2
*pout
, const D3DXVECTOR2
*pv1
, const D3DXVECTOR2
*pt1
, const D3DXVECTOR2
*pv2
, const D3DXVECTOR2
*pt2
, FLOAT s
)
1685 FLOAT h1
, h2
, h3
, h4
;
1687 TRACE("pout %p, pv1 %p, pt1 %p, pv2 %p, pt2 %p, s %f\n", pout
, pv1
, pt1
, pv2
, pt2
, s
);
1689 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
1690 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
1691 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
1692 h4
= s
* s
* s
- s
* s
;
1694 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
1695 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
1699 D3DXVECTOR2
* WINAPI
D3DXVec2Normalize(D3DXVECTOR2
*pout
, const D3DXVECTOR2
*pv
)
1703 TRACE("pout %p, pv %p\n", pout
, pv
);
1705 norm
= D3DXVec2Length(pv
);
1713 pout
->x
= pv
->x
/ norm
;
1714 pout
->y
= pv
->y
/ norm
;
1720 D3DXVECTOR4
* WINAPI
D3DXVec2Transform(D3DXVECTOR4
*pout
, const D3DXVECTOR2
*pv
, const D3DXMATRIX
*pm
)
1722 TRACE("pout %p, pv %p, pm %p\n", pout
, pv
, pm
);
1724 pout
->x
= pm
->u
.m
[0][0] * pv
->x
+ pm
->u
.m
[1][0] * pv
->y
+ pm
->u
.m
[3][0];
1725 pout
->y
= pm
->u
.m
[0][1] * pv
->x
+ pm
->u
.m
[1][1] * pv
->y
+ pm
->u
.m
[3][1];
1726 pout
->z
= pm
->u
.m
[0][2] * pv
->x
+ pm
->u
.m
[1][2] * pv
->y
+ pm
->u
.m
[3][2];
1727 pout
->w
= pm
->u
.m
[0][3] * pv
->x
+ pm
->u
.m
[1][3] * pv
->y
+ pm
->u
.m
[3][3];
1731 D3DXVECTOR4
* WINAPI
D3DXVec2TransformArray(D3DXVECTOR4
* out
, UINT outstride
, const D3DXVECTOR2
* in
, UINT instride
, const D3DXMATRIX
* matrix
, UINT elements
)
1735 TRACE("out %p, outstride %u, in %p, instride %u, matrix %p, elements %u\n", out
, outstride
, in
, instride
, matrix
, elements
);
1737 for (i
= 0; i
< elements
; ++i
) {
1739 (D3DXVECTOR4
*)((char*)out
+ outstride
* i
),
1740 (const D3DXVECTOR2
*)((const char*)in
+ instride
* i
),
1746 D3DXVECTOR2
* WINAPI
D3DXVec2TransformCoord(D3DXVECTOR2
*pout
, const D3DXVECTOR2
*pv
, const D3DXMATRIX
*pm
)
1751 TRACE("pout %p, pv %p, pm %p\n", pout
, pv
, pm
);
1754 norm
= pm
->u
.m
[0][3] * pv
->x
+ pm
->u
.m
[1][3] * pv
->y
+ pm
->u
.m
[3][3];
1756 pout
->x
= (pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
+ pm
->u
.m
[3][0]) / norm
;
1757 pout
->y
= (pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
+ pm
->u
.m
[3][1]) / norm
;
1762 D3DXVECTOR2
* WINAPI
D3DXVec2TransformCoordArray(D3DXVECTOR2
* out
, UINT outstride
, const D3DXVECTOR2
* in
, UINT instride
, const D3DXMATRIX
* matrix
, UINT elements
)
1766 TRACE("out %p, outstride %u, in %p, instride %u, matrix %p, elements %u\n", out
, outstride
, in
, instride
, matrix
, elements
);
1768 for (i
= 0; i
< elements
; ++i
) {
1769 D3DXVec2TransformCoord(
1770 (D3DXVECTOR2
*)((char*)out
+ outstride
* i
),
1771 (const D3DXVECTOR2
*)((const char*)in
+ instride
* i
),
1777 D3DXVECTOR2
* WINAPI
D3DXVec2TransformNormal(D3DXVECTOR2
*pout
, const D3DXVECTOR2
*pv
, const D3DXMATRIX
*pm
)
1779 const D3DXVECTOR2 v
= *pv
;
1781 TRACE("pout %p, pv %p, pm %p\n", pout
, pv
, pm
);
1783 pout
->x
= pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
;
1784 pout
->y
= pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
;
1788 D3DXVECTOR2
* WINAPI
D3DXVec2TransformNormalArray(D3DXVECTOR2
* out
, UINT outstride
, const D3DXVECTOR2
*in
, UINT instride
, const D3DXMATRIX
*matrix
, UINT elements
)
1792 TRACE("out %p, outstride %u, in %p, instride %u, matrix %p, elements %u\n", out
, outstride
, in
, instride
, matrix
, elements
);
1794 for (i
= 0; i
< elements
; ++i
) {
1795 D3DXVec2TransformNormal(
1796 (D3DXVECTOR2
*)((char*)out
+ outstride
* i
),
1797 (const D3DXVECTOR2
*)((const char*)in
+ instride
* i
),
1803 /*_________________D3DXVec3_____________________*/
1805 D3DXVECTOR3
* WINAPI
D3DXVec3BaryCentric(D3DXVECTOR3
*pout
, const D3DXVECTOR3
*pv1
, const D3DXVECTOR3
*pv2
, const D3DXVECTOR3
*pv3
, FLOAT f
, FLOAT g
)
1807 TRACE("pout %p, pv1 %p, pv2 %p, pv3 %p, f %f, g %f\n", pout
, pv1
, pv2
, pv3
, f
, g
);
1809 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
1810 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
1811 pout
->z
= (1.0f
-f
-g
) * (pv1
->z
) + f
* (pv2
->z
) + g
* (pv3
->z
);
1815 D3DXVECTOR3
* WINAPI
D3DXVec3CatmullRom( D3DXVECTOR3
*pout
, const D3DXVECTOR3
*pv0
, const D3DXVECTOR3
*pv1
, const D3DXVECTOR3
*pv2
, const D3DXVECTOR3
*pv3
, FLOAT s
)
1817 TRACE("pout %p, pv0 %p, pv1 %p, pv2 %p, pv3 %p, s %f\n", pout
, pv0
, pv1
, pv2
, pv3
, s
);
1819 pout
->x
= 0.5f
* (2.0f
* pv1
->x
+ (pv2
->x
- pv0
->x
) *s
+ (2.0f
*pv0
->x
- 5.0f
* pv1
->x
+ 4.0f
* pv2
->x
- pv3
->x
) * s
* s
+ (pv3
->x
-3.0f
* pv2
->x
+ 3.0f
* pv1
->x
- pv0
->x
) * s
* s
* s
);
1820 pout
->y
= 0.5f
* (2.0f
* pv1
->y
+ (pv2
->y
- pv0
->y
) *s
+ (2.0f
*pv0
->y
- 5.0f
* pv1
->y
+ 4.0f
* pv2
->y
- pv3
->y
) * s
* s
+ (pv3
->y
-3.0f
* pv2
->y
+ 3.0f
* pv1
->y
- pv0
->y
) * s
* s
* s
);
1821 pout
->z
= 0.5f
* (2.0f
* pv1
->z
+ (pv2
->z
- pv0
->z
) *s
+ (2.0f
*pv0
->z
- 5.0f
* pv1
->z
+ 4.0f
* pv2
->z
- pv3
->z
) * s
* s
+ (pv3
->z
-3.0f
* pv2
->z
+ 3.0f
* pv1
->z
- pv0
->z
) * s
* s
* s
);
1825 D3DXVECTOR3
* WINAPI
D3DXVec3Hermite(D3DXVECTOR3
*pout
, const D3DXVECTOR3
*pv1
, const D3DXVECTOR3
*pt1
, const D3DXVECTOR3
*pv2
, const D3DXVECTOR3
*pt2
, FLOAT s
)
1827 FLOAT h1
, h2
, h3
, h4
;
1829 TRACE("pout %p, pv1 %p, pt1 %p, pv2 %p, pt2 %p, s %f\n", pout
, pv1
, pt1
, pv2
, pt2
, s
);
1831 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
1832 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
1833 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
1834 h4
= s
* s
* s
- s
* s
;
1836 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
1837 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
1838 pout
->z
= h1
* (pv1
->z
) + h2
* (pt1
->z
) + h3
* (pv2
->z
) + h4
* (pt2
->z
);
1842 D3DXVECTOR3
* WINAPI
D3DXVec3Normalize(D3DXVECTOR3
*pout
, const D3DXVECTOR3
*pv
)
1846 TRACE("pout %p, pv %p\n", pout
, pv
);
1848 norm
= D3DXVec3Length(pv
);
1857 pout
->x
= pv
->x
/ norm
;
1858 pout
->y
= pv
->y
/ norm
;
1859 pout
->z
= pv
->z
/ norm
;
1865 D3DXVECTOR3
* WINAPI
D3DXVec3Project(D3DXVECTOR3
*pout
, const D3DXVECTOR3
*pv
, const D3DVIEWPORT9
*pviewport
, const D3DXMATRIX
*pprojection
, const D3DXMATRIX
*pview
, const D3DXMATRIX
*pworld
)
1869 TRACE("pout %p, pv %p, pviewport %p, pprojection %p, pview %p, pworld %p\n", pout
, pv
, pviewport
, pprojection
, pview
, pworld
);
1871 D3DXMatrixIdentity(&m
);
1872 if (pworld
) D3DXMatrixMultiply(&m
, &m
, pworld
);
1873 if (pview
) D3DXMatrixMultiply(&m
, &m
, pview
);
1874 if (pprojection
) D3DXMatrixMultiply(&m
, &m
, pprojection
);
1876 D3DXVec3TransformCoord(pout
, pv
, &m
);
1880 pout
->x
= pviewport
->X
+ ( 1.0f
+ pout
->x
) * pviewport
->Width
/ 2.0f
;
1881 pout
->y
= pviewport
->Y
+ ( 1.0f
- pout
->y
) * pviewport
->Height
/ 2.0f
;
1882 pout
->z
= pviewport
->MinZ
+ pout
->z
* ( pviewport
->MaxZ
- pviewport
->MinZ
);
1887 D3DXVECTOR3
* WINAPI
D3DXVec3ProjectArray(D3DXVECTOR3
* out
, UINT outstride
, const D3DXVECTOR3
* in
, UINT instride
, const D3DVIEWPORT9
* viewport
, const D3DXMATRIX
* projection
, const D3DXMATRIX
* view
, const D3DXMATRIX
* world
, UINT elements
)
1891 TRACE("out %p, outstride %u, in %p, instride %u, viewport %p, projection %p, view %p, world %p, elements %u\n",
1892 out
, outstride
, in
, instride
, viewport
, projection
, view
, world
, elements
);
1894 for (i
= 0; i
< elements
; ++i
) {
1896 (D3DXVECTOR3
*)((char*)out
+ outstride
* i
),
1897 (const D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
1898 viewport
, projection
, view
, world
);
1903 D3DXVECTOR4
* WINAPI
D3DXVec3Transform(D3DXVECTOR4
*pout
, const D3DXVECTOR3
*pv
, const D3DXMATRIX
*pm
)
1905 TRACE("pout %p, pv %p, pm %p\n", pout
, pv
, pm
);
1907 pout
->x
= pm
->u
.m
[0][0] * pv
->x
+ pm
->u
.m
[1][0] * pv
->y
+ pm
->u
.m
[2][0] * pv
->z
+ pm
->u
.m
[3][0];
1908 pout
->y
= pm
->u
.m
[0][1] * pv
->x
+ pm
->u
.m
[1][1] * pv
->y
+ pm
->u
.m
[2][1] * pv
->z
+ pm
->u
.m
[3][1];
1909 pout
->z
= pm
->u
.m
[0][2] * pv
->x
+ pm
->u
.m
[1][2] * pv
->y
+ pm
->u
.m
[2][2] * pv
->z
+ pm
->u
.m
[3][2];
1910 pout
->w
= pm
->u
.m
[0][3] * pv
->x
+ pm
->u
.m
[1][3] * pv
->y
+ pm
->u
.m
[2][3] * pv
->z
+ pm
->u
.m
[3][3];
1914 D3DXVECTOR4
* WINAPI
D3DXVec3TransformArray(D3DXVECTOR4
* out
, UINT outstride
, const D3DXVECTOR3
* in
, UINT instride
, const D3DXMATRIX
* matrix
, UINT elements
)
1918 TRACE("out %p, outstride %u, in %p, instride %u, matrix %p, elements %u\n", out
, outstride
, in
, instride
, matrix
, elements
);
1920 for (i
= 0; i
< elements
; ++i
) {
1922 (D3DXVECTOR4
*)((char*)out
+ outstride
* i
),
1923 (const D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
1929 D3DXVECTOR3
* WINAPI
D3DXVec3TransformCoord(D3DXVECTOR3
*pout
, const D3DXVECTOR3
*pv
, const D3DXMATRIX
*pm
)
1934 TRACE("pout %p, pv %p, pm %p\n", pout
, pv
, pm
);
1936 norm
= pm
->u
.m
[0][3] * pv
->x
+ pm
->u
.m
[1][3] * pv
->y
+ pm
->u
.m
[2][3] *pv
->z
+ pm
->u
.m
[3][3];
1938 out
.x
= (pm
->u
.m
[0][0] * pv
->x
+ pm
->u
.m
[1][0] * pv
->y
+ pm
->u
.m
[2][0] * pv
->z
+ pm
->u
.m
[3][0]) / norm
;
1939 out
.y
= (pm
->u
.m
[0][1] * pv
->x
+ pm
->u
.m
[1][1] * pv
->y
+ pm
->u
.m
[2][1] * pv
->z
+ pm
->u
.m
[3][1]) / norm
;
1940 out
.z
= (pm
->u
.m
[0][2] * pv
->x
+ pm
->u
.m
[1][2] * pv
->y
+ pm
->u
.m
[2][2] * pv
->z
+ pm
->u
.m
[3][2]) / norm
;
1947 D3DXVECTOR3
* WINAPI
D3DXVec3TransformCoordArray(D3DXVECTOR3
* out
, UINT outstride
, const D3DXVECTOR3
* in
, UINT instride
, const D3DXMATRIX
* matrix
, UINT elements
)
1951 TRACE("out %p, outstride %u, in %p, instride %u, matrix %p, elements %u\n", out
, outstride
, in
, instride
, matrix
, elements
);
1953 for (i
= 0; i
< elements
; ++i
) {
1954 D3DXVec3TransformCoord(
1955 (D3DXVECTOR3
*)((char*)out
+ outstride
* i
),
1956 (const D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
1962 D3DXVECTOR3
* WINAPI
D3DXVec3TransformNormal(D3DXVECTOR3
*pout
, const D3DXVECTOR3
*pv
, const D3DXMATRIX
*pm
)
1964 const D3DXVECTOR3 v
= *pv
;
1966 TRACE("pout %p, pv %p, pm %p\n", pout
, pv
, pm
);
1968 pout
->x
= pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
+ pm
->u
.m
[2][0] * v
.z
;
1969 pout
->y
= pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
+ pm
->u
.m
[2][1] * v
.z
;
1970 pout
->z
= pm
->u
.m
[0][2] * v
.x
+ pm
->u
.m
[1][2] * v
.y
+ pm
->u
.m
[2][2] * v
.z
;
1975 D3DXVECTOR3
* WINAPI
D3DXVec3TransformNormalArray(D3DXVECTOR3
* out
, UINT outstride
, const D3DXVECTOR3
* in
, UINT instride
, const D3DXMATRIX
* matrix
, UINT elements
)
1979 TRACE("out %p, outstride %u, in %p, instride %u, matrix %p, elements %u\n", out
, outstride
, in
, instride
, matrix
, elements
);
1981 for (i
= 0; i
< elements
; ++i
) {
1982 D3DXVec3TransformNormal(
1983 (D3DXVECTOR3
*)((char*)out
+ outstride
* i
),
1984 (const D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
1990 D3DXVECTOR3
* WINAPI
D3DXVec3Unproject(D3DXVECTOR3
*pout
, const D3DXVECTOR3
*pv
, const D3DVIEWPORT9
*pviewport
, const D3DXMATRIX
*pprojection
, const D3DXMATRIX
*pview
, const D3DXMATRIX
*pworld
)
1994 TRACE("pout %p, pv %p, pviewport %p, pprojection %p, pview %p, pworlds %p\n", pout
, pv
, pviewport
, pprojection
, pview
, pworld
);
1996 D3DXMatrixIdentity(&m
);
1997 if (pworld
) D3DXMatrixMultiply(&m
, &m
, pworld
);
1998 if (pview
) D3DXMatrixMultiply(&m
, &m
, pview
);
1999 if (pprojection
) D3DXMatrixMultiply(&m
, &m
, pprojection
);
2000 D3DXMatrixInverse(&m
, NULL
, &m
);
2005 pout
->x
= 2.0f
* ( pout
->x
- pviewport
->X
) / pviewport
->Width
- 1.0f
;
2006 pout
->y
= 1.0f
- 2.0f
* ( pout
->y
- pviewport
->Y
) / pviewport
->Height
;
2007 pout
->z
= ( pout
->z
- pviewport
->MinZ
) / ( pviewport
->MaxZ
- pviewport
->MinZ
);
2009 D3DXVec3TransformCoord(pout
, pout
, &m
);
2013 D3DXVECTOR3
* WINAPI
D3DXVec3UnprojectArray(D3DXVECTOR3
* out
, UINT outstride
, const D3DXVECTOR3
* in
, UINT instride
, const D3DVIEWPORT9
* viewport
, const D3DXMATRIX
* projection
, const D3DXMATRIX
* view
, const D3DXMATRIX
* world
, UINT elements
)
2017 TRACE("out %p, outstride %u, in %p, instride %u, viewport %p, projection %p, view %p, world %p, elements %u\n",
2018 out
, outstride
, in
, instride
, viewport
, projection
, view
, world
, elements
);
2020 for (i
= 0; i
< elements
; ++i
) {
2022 (D3DXVECTOR3
*)((char*)out
+ outstride
* i
),
2023 (const D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
2024 viewport
, projection
, view
, world
);
2029 /*_________________D3DXVec4_____________________*/
2031 D3DXVECTOR4
* WINAPI
D3DXVec4BaryCentric(D3DXVECTOR4
*pout
, const D3DXVECTOR4
*pv1
, const D3DXVECTOR4
*pv2
, const D3DXVECTOR4
*pv3
, FLOAT f
, FLOAT g
)
2033 TRACE("pout %p, pv1 %p, pv2 %p, pv3 %p, f %f, g %f\n", pout
, pv1
, pv2
, pv3
, f
, g
);
2035 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
2036 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
2037 pout
->z
= (1.0f
-f
-g
) * (pv1
->z
) + f
* (pv2
->z
) + g
* (pv3
->z
);
2038 pout
->w
= (1.0f
-f
-g
) * (pv1
->w
) + f
* (pv2
->w
) + g
* (pv3
->w
);
2042 D3DXVECTOR4
* WINAPI
D3DXVec4CatmullRom(D3DXVECTOR4
*pout
, const D3DXVECTOR4
*pv0
, const D3DXVECTOR4
*pv1
, const D3DXVECTOR4
*pv2
, const D3DXVECTOR4
*pv3
, FLOAT s
)
2044 TRACE("pout %p, pv0 %p, pv1 %p, pv2 %p, pv3 %p, s %f\n", pout
, pv0
, pv1
, pv2
, pv3
, s
);
2046 pout
->x
= 0.5f
* (2.0f
* pv1
->x
+ (pv2
->x
- pv0
->x
) *s
+ (2.0f
*pv0
->x
- 5.0f
* pv1
->x
+ 4.0f
* pv2
->x
- pv3
->x
) * s
* s
+ (pv3
->x
-3.0f
* pv2
->x
+ 3.0f
* pv1
->x
- pv0
->x
) * s
* s
* s
);
2047 pout
->y
= 0.5f
* (2.0f
* pv1
->y
+ (pv2
->y
- pv0
->y
) *s
+ (2.0f
*pv0
->y
- 5.0f
* pv1
->y
+ 4.0f
* pv2
->y
- pv3
->y
) * s
* s
+ (pv3
->y
-3.0f
* pv2
->y
+ 3.0f
* pv1
->y
- pv0
->y
) * s
* s
* s
);
2048 pout
->z
= 0.5f
* (2.0f
* pv1
->z
+ (pv2
->z
- pv0
->z
) *s
+ (2.0f
*pv0
->z
- 5.0f
* pv1
->z
+ 4.0f
* pv2
->z
- pv3
->z
) * s
* s
+ (pv3
->z
-3.0f
* pv2
->z
+ 3.0f
* pv1
->z
- pv0
->z
) * s
* s
* s
);
2049 pout
->w
= 0.5f
* (2.0f
* pv1
->w
+ (pv2
->w
- pv0
->w
) *s
+ (2.0f
*pv0
->w
- 5.0f
* pv1
->w
+ 4.0f
* pv2
->w
- pv3
->w
) * s
* s
+ (pv3
->w
-3.0f
* pv2
->w
+ 3.0f
* pv1
->w
- pv0
->w
) * s
* s
* s
);
2053 D3DXVECTOR4
* WINAPI
D3DXVec4Cross(D3DXVECTOR4
*pout
, const D3DXVECTOR4
*pv1
, const D3DXVECTOR4
*pv2
, const D3DXVECTOR4
*pv3
)
2057 TRACE("pout %p, pv1 %p, pv2 %p, pv3 %p\n", pout
, pv1
, pv2
, pv3
);
2059 out
.x
= pv1
->y
* (pv2
->z
* pv3
->w
- pv3
->z
* pv2
->w
) - pv1
->z
* (pv2
->y
* pv3
->w
- pv3
->y
* pv2
->w
) + pv1
->w
* (pv2
->y
* pv3
->z
- pv2
->z
*pv3
->y
);
2060 out
.y
= -(pv1
->x
* (pv2
->z
* pv3
->w
- pv3
->z
* pv2
->w
) - pv1
->z
* (pv2
->x
* pv3
->w
- pv3
->x
* pv2
->w
) + pv1
->w
* (pv2
->x
* pv3
->z
- pv3
->x
* pv2
->z
));
2061 out
.z
= pv1
->x
* (pv2
->y
* pv3
->w
- pv3
->y
* pv2
->w
) - pv1
->y
* (pv2
->x
*pv3
->w
- pv3
->x
* pv2
->w
) + pv1
->w
* (pv2
->x
* pv3
->y
- pv3
->x
* pv2
->y
);
2062 out
.w
= -(pv1
->x
* (pv2
->y
* pv3
->z
- pv3
->y
* pv2
->z
) - pv1
->y
* (pv2
->x
* pv3
->z
- pv3
->x
*pv2
->z
) + pv1
->z
* (pv2
->x
* pv3
->y
- pv3
->x
* pv2
->y
));
2067 D3DXVECTOR4
* WINAPI
D3DXVec4Hermite(D3DXVECTOR4
*pout
, const D3DXVECTOR4
*pv1
, const D3DXVECTOR4
*pt1
, const D3DXVECTOR4
*pv2
, const D3DXVECTOR4
*pt2
, FLOAT s
)
2069 FLOAT h1
, h2
, h3
, h4
;
2071 TRACE("pout %p, pv1 %p, pt1 %p, pv2 %p, pt2 %p, s %f\n", pout
, pv1
, pt1
, pv2
, pt2
, s
);
2073 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
2074 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
2075 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
2076 h4
= s
* s
* s
- s
* s
;
2078 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
2079 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
2080 pout
->z
= h1
* (pv1
->z
) + h2
* (pt1
->z
) + h3
* (pv2
->z
) + h4
* (pt2
->z
);
2081 pout
->w
= h1
* (pv1
->w
) + h2
* (pt1
->w
) + h3
* (pv2
->w
) + h4
* (pt2
->w
);
2085 D3DXVECTOR4
* WINAPI
D3DXVec4Normalize(D3DXVECTOR4
*pout
, const D3DXVECTOR4
*pv
)
2089 TRACE("pout %p, pv %p\n", pout
, pv
);
2091 norm
= D3DXVec4Length(pv
);
2093 pout
->x
= pv
->x
/ norm
;
2094 pout
->y
= pv
->y
/ norm
;
2095 pout
->z
= pv
->z
/ norm
;
2096 pout
->w
= pv
->w
/ norm
;
2101 D3DXVECTOR4
* WINAPI
D3DXVec4Transform(D3DXVECTOR4
*pout
, const D3DXVECTOR4
*pv
, const D3DXMATRIX
*pm
)
2105 TRACE("pout %p, pv %p, pm %p\n", pout
, pv
, pm
);
2107 out
.x
= pm
->u
.m
[0][0] * pv
->x
+ pm
->u
.m
[1][0] * pv
->y
+ pm
->u
.m
[2][0] * pv
->z
+ pm
->u
.m
[3][0] * pv
->w
;
2108 out
.y
= pm
->u
.m
[0][1] * pv
->x
+ pm
->u
.m
[1][1] * pv
->y
+ pm
->u
.m
[2][1] * pv
->z
+ pm
->u
.m
[3][1] * pv
->w
;
2109 out
.z
= pm
->u
.m
[0][2] * pv
->x
+ pm
->u
.m
[1][2] * pv
->y
+ pm
->u
.m
[2][2] * pv
->z
+ pm
->u
.m
[3][2] * pv
->w
;
2110 out
.w
= pm
->u
.m
[0][3] * pv
->x
+ pm
->u
.m
[1][3] * pv
->y
+ pm
->u
.m
[2][3] * pv
->z
+ pm
->u
.m
[3][3] * pv
->w
;
2115 D3DXVECTOR4
* WINAPI
D3DXVec4TransformArray(D3DXVECTOR4
* out
, UINT outstride
, const D3DXVECTOR4
* in
, UINT instride
, const D3DXMATRIX
* matrix
, UINT elements
)
2119 TRACE("out %p, outstride %u, in %p, instride %u, matrix %p, elements %u\n", out
, outstride
, in
, instride
, matrix
, elements
);
2121 for (i
= 0; i
< elements
; ++i
) {
2123 (D3DXVECTOR4
*)((char*)out
+ outstride
* i
),
2124 (const D3DXVECTOR4
*)((const char*)in
+ instride
* i
),
2130 unsigned short float_32_to_16(const float in
)
2132 int exp
= 0, origexp
;
2133 float tmp
= fabs(in
);
2134 int sign
= (copysignf(1, in
) < 0);
2135 unsigned int mantissa
;
2138 /* Deal with special numbers */
2139 if (isinf(in
)) return (sign
? 0xffff : 0x7fff);
2140 if (isnan(in
)) return (sign
? 0xffff : 0x7fff);
2141 if (in
== 0.0f
) return (sign
? 0x8000 : 0x0000);
2143 if (tmp
< powf(2, 10))
2149 } while (tmp
< powf(2, 10));
2151 else if (tmp
>= powf(2, 11))
2157 } while (tmp
>= powf(2, 11));
2160 exp
+= 10; /* Normalize the mantissa */
2161 exp
+= 15; /* Exponent is encoded with excess 15 */
2165 mantissa
= (unsigned int) tmp
;
2166 if ((tmp
- mantissa
== 0.5f
&& mantissa
% 2 == 1) || /* round half to even */
2167 (tmp
- mantissa
> 0.5f
))
2169 mantissa
++; /* round to nearest, away from zero */
2171 if (mantissa
== 2048)
2180 ret
= 0x7fff; /* INF */
2184 unsigned int rounding
= 0;
2186 /* Denormalized half float */
2188 /* return 0x0000 (=0.0) for numbers too small to represent in half floats */
2190 return (sign
? 0x8000 : 0x0000);
2194 /* the 13 extra bits from single precision are used for rounding */
2195 mantissa
= (unsigned int)(tmp
* powf(2, 13));
2196 mantissa
>>= 1 - exp
; /* denormalize */
2198 mantissa
-= ~(mantissa
>> 13) & 1; /* round half to even */
2199 /* remove 13 least significant bits to get half float precision */
2201 rounding
= mantissa
& 1;
2204 ret
= mantissa
+ rounding
;
2208 ret
= (exp
<< 10) | (mantissa
& 0x3ff);
2211 ret
|= ((sign
? 1 : 0) << 15); /* Add the sign */
2215 D3DXFLOAT16
*WINAPI
D3DXFloat32To16Array(D3DXFLOAT16
*pout
, const FLOAT
*pin
, UINT n
)
2219 TRACE("pout %p, pin %p, n %u\n", pout
, pin
, n
);
2221 for (i
= 0; i
< n
; ++i
)
2223 pout
[i
].value
= float_32_to_16(pin
[i
]);
2229 /* Native d3dx9's D3DXFloat16to32Array lacks support for NaN and Inf. Specifically, e = 16 is treated as a
2230 * regular number - e.g., 0x7fff is converted to 131008.0 and 0xffff to -131008.0. */
2231 static inline float float_16_to_32(const unsigned short in
)
2233 const unsigned short s
= (in
& 0x8000);
2234 const unsigned short e
= (in
& 0x7C00) >> 10;
2235 const unsigned short m
= in
& 0x3FF;
2236 const float sgn
= (s
? -1.0f
: 1.0f
);
2240 if (m
== 0) return sgn
* 0.0f
; /* +0.0 or -0.0 */
2241 else return sgn
* powf(2, -14.0f
) * (m
/ 1024.0f
);
2245 return sgn
* powf(2, e
- 15.0f
) * (1.0f
+ (m
/ 1024.0f
));
2249 FLOAT
*WINAPI
D3DXFloat16To32Array(FLOAT
*pout
, const D3DXFLOAT16
*pin
, UINT n
)
2253 TRACE("pout %p, pin %p, n %u\n", pout
, pin
, n
);
2255 for (i
= 0; i
< n
; ++i
)
2257 pout
[i
] = float_16_to_32(pin
[i
].value
);
2263 /*_________________D3DXSH________________*/
2265 FLOAT
* WINAPI
D3DXSHAdd(FLOAT
*out
, UINT order
, const FLOAT
*a
, const FLOAT
*b
)
2269 TRACE("out %p, order %u, a %p, b %p\n", out
, order
, a
, b
);
2271 for (i
= 0; i
< order
* order
; i
++)
2272 out
[i
] = a
[i
] + b
[i
];
2277 FLOAT WINAPI
D3DXSHDot(UINT order
, const FLOAT
*a
, const FLOAT
*b
)
2282 TRACE("order %u, a %p, b %p\n", order
, a
, b
);
2285 for (i
= 1; i
< order
* order
; i
++)
2291 static void weightedcapintegrale(FLOAT
*out
, FLOAT order
, FLOAT angle
)
2295 coeff
[0] = cosf(angle
);
2297 out
[0] = 2.0f
* D3DX_PI
* (1.0f
- coeff
[0]);
2298 out
[1] = D3DX_PI
* sinf(angle
) * sinf(angle
);
2302 out
[2] = coeff
[0] * out
[1];
2306 coeff
[1] = coeff
[0] * coeff
[0];
2307 coeff
[2] = coeff
[1] * coeff
[1];
2309 out
[3] = D3DX_PI
* (-1.25f
* coeff
[2] + 1.5f
* coeff
[1] - 0.25f
);
2313 out
[4] = -0.25f
* D3DX_PI
* coeff
[0] * (7.0f
* coeff
[2] - 10.0f
* coeff
[1] + 3.0f
);
2317 out
[5] = D3DX_PI
* (-2.625f
* coeff
[2] * coeff
[1] + 4.375f
* coeff
[2] - 1.875f
* coeff
[1] + 0.125f
);
2320 HRESULT WINAPI
D3DXSHEvalConeLight(UINT order
, const D3DXVECTOR3
*dir
, FLOAT radius
,
2321 FLOAT Rintensity
, FLOAT Gintensity
, FLOAT Bintensity
, FLOAT
*rout
, FLOAT
*gout
, FLOAT
*bout
)
2323 FLOAT cap
[6], clamped_angle
, norm
, scale
, temp
;
2326 TRACE("order %u, dir %p, radius %f, red %f, green %f, blue %f, rout %p, gout %p, bout %p\n",
2327 order
, dir
, radius
, Rintensity
, Gintensity
, Bintensity
, rout
, gout
, bout
);
2330 return D3DXSHEvalDirectionalLight(order
, dir
, Rintensity
, Gintensity
, Bintensity
, rout
, gout
, bout
);
2332 clamped_angle
= (radius
> D3DX_PI
/ 2.0f
) ? (D3DX_PI
/ 2.0f
) : radius
;
2333 norm
= sinf(clamped_angle
) * sinf(clamped_angle
);
2335 if (order
> D3DXSH_MAXORDER
)
2337 WARN("Order clamped at D3DXSH_MAXORDER\n");
2338 order
= D3DXSH_MAXORDER
;
2341 weightedcapintegrale(cap
, order
, radius
);
2342 D3DXSHEvalDirection(rout
, order
, dir
);
2344 for (i
= 0; i
< order
; i
++)
2346 scale
= cap
[i
] / norm
;
2348 for (j
= 0; j
< 2 * i
+ 1; j
++)
2351 temp
= rout
[index
] * scale
;
2353 rout
[index
] = temp
* Rintensity
;
2355 gout
[index
] = temp
* Gintensity
;
2357 bout
[index
] = temp
* Bintensity
;
2364 FLOAT
* WINAPI
D3DXSHEvalDirection(FLOAT
*out
, UINT order
, const D3DXVECTOR3
*dir
)
2366 const FLOAT dirxx
= dir
->x
* dir
->x
;
2367 const FLOAT dirxy
= dir
->x
* dir
->y
;
2368 const FLOAT dirxz
= dir
->x
* dir
->z
;
2369 const FLOAT diryy
= dir
->y
* dir
->y
;
2370 const FLOAT diryz
= dir
->y
* dir
->z
;
2371 const FLOAT dirzz
= dir
->z
* dir
->z
;
2372 const FLOAT dirxxxx
= dirxx
* dirxx
;
2373 const FLOAT diryyyy
= diryy
* diryy
;
2374 const FLOAT dirzzzz
= dirzz
* dirzz
;
2375 const FLOAT dirxyxy
= dirxy
* dirxy
;
2377 TRACE("out %p, order %u, dir %p\n", out
, order
, dir
);
2379 if ((order
< D3DXSH_MINORDER
) || (order
> D3DXSH_MAXORDER
))
2382 out
[0] = 0.5f
/ sqrtf(D3DX_PI
);
2383 out
[1] = -0.5f
/ sqrtf(D3DX_PI
/ 3.0f
) * dir
->y
;
2384 out
[2] = 0.5f
/ sqrtf(D3DX_PI
/ 3.0f
) * dir
->z
;
2385 out
[3] = -0.5f
/ sqrtf(D3DX_PI
/ 3.0f
) * dir
->x
;
2389 out
[4] = 0.5f
/ sqrtf(D3DX_PI
/ 15.0f
) * dirxy
;
2390 out
[5] = -0.5f
/ sqrtf(D3DX_PI
/ 15.0f
) * diryz
;
2391 out
[6] = 0.25f
/ sqrtf(D3DX_PI
/ 5.0f
) * (3.0f
* dirzz
- 1.0f
);
2392 out
[7] = -0.5f
/ sqrtf(D3DX_PI
/ 15.0f
) * dirxz
;
2393 out
[8] = 0.25f
/ sqrtf(D3DX_PI
/ 15.0f
) * (dirxx
- diryy
);
2397 out
[9] = -sqrtf(70.0f
/ D3DX_PI
) / 8.0f
* dir
->y
* (3.0f
* dirxx
- diryy
);
2398 out
[10] = sqrtf(105.0f
/ D3DX_PI
) / 2.0f
* dirxy
* dir
->z
;
2399 out
[11] = -sqrtf(42.0 / D3DX_PI
) / 8.0f
* dir
->y
* (-1.0f
+ 5.0f
* dirzz
);
2400 out
[12] = sqrtf(7.0f
/ D3DX_PI
) / 4.0f
* dir
->z
* (5.0f
* dirzz
- 3.0f
);
2401 out
[13] = sqrtf(42.0 / D3DX_PI
) / 8.0f
* dir
->x
* (1.0f
- 5.0f
* dirzz
);
2402 out
[14] = sqrtf(105.0f
/ D3DX_PI
) / 4.0f
* dir
->z
* (dirxx
- diryy
);
2403 out
[15] = -sqrtf(70.0f
/ D3DX_PI
) / 8.0f
* dir
->x
* (dirxx
- 3.0f
* diryy
);
2407 out
[16] = 0.75f
* sqrtf(35.0f
/ D3DX_PI
) * dirxy
* (dirxx
- diryy
);
2408 out
[17] = 3.0f
* dir
->z
* out
[9];
2409 out
[18] = 0.75f
* sqrtf(5.0f
/ D3DX_PI
) * dirxy
* (7.0f
* dirzz
- 1.0f
);
2410 out
[19] = 0.375f
* sqrtf(10.0f
/ D3DX_PI
) * diryz
* (3.0f
- 7.0f
* dirzz
);
2411 out
[20] = 3.0f
/ (16.0f
* sqrtf(D3DX_PI
)) * (35.0f
* dirzzzz
- 30.f
* dirzz
+ 3.0f
);
2412 out
[21] = 0.375f
* sqrtf(10.0f
/ D3DX_PI
) * dirxz
* (3.0f
- 7.0f
* dirzz
);
2413 out
[22] = 0.375f
* sqrtf(5.0f
/ D3DX_PI
) * (dirxx
- diryy
) * (7.0f
* dirzz
- 1.0f
);
2414 out
[23] = 3.0 * dir
->z
* out
[15];
2415 out
[24] = 3.0f
/ 16.0f
* sqrtf(35.0f
/ D3DX_PI
) * (dirxxxx
- 6.0f
* dirxyxy
+ diryyyy
);
2419 out
[25] = -3.0f
/ 32.0f
* sqrtf(154.0f
/ D3DX_PI
) * dir
->y
* (5.0f
* dirxxxx
- 10.0f
* dirxyxy
+ diryyyy
);
2420 out
[26] = 0.75f
* sqrtf(385.0f
/ D3DX_PI
) * dirxy
* dir
->z
* (dirxx
- diryy
);
2421 out
[27] = sqrtf(770.0f
/ D3DX_PI
) / 32.0f
* dir
->y
* (3.0f
* dirxx
- diryy
) * (1.0f
- 9.0f
* dirzz
);
2422 out
[28] = sqrtf(1155.0f
/ D3DX_PI
) / 4.0f
* dirxy
* dir
->z
* (3.0f
* dirzz
- 1.0f
);
2423 out
[29] = sqrtf(165.0f
/ D3DX_PI
) / 16.0f
* dir
->y
* (14.0f
* dirzz
- 21.0f
* dirzzzz
- 1.0f
);
2424 out
[30] = sqrtf(11.0f
/ D3DX_PI
) / 16.0f
* dir
->z
* (63.0f
* dirzzzz
- 70.0f
* dirzz
+ 15.0f
);
2425 out
[31] = sqrtf(165.0f
/ D3DX_PI
) / 16.0f
* dir
->x
* (14.0f
* dirzz
- 21.0f
* dirzzzz
- 1.0f
);
2426 out
[32] = sqrtf(1155.0f
/ D3DX_PI
) / 8.0f
* dir
->z
* (dirxx
- diryy
) * (3.0f
* dirzz
- 1.0f
);
2427 out
[33] = sqrtf(770.0f
/ D3DX_PI
) / 32.0f
* dir
->x
* (dirxx
- 3.0f
* diryy
) * (1.0f
- 9.0f
* dirzz
);
2428 out
[34] = 3.0f
/ 16.0f
* sqrtf(385.0f
/ D3DX_PI
) * dir
->z
* (dirxxxx
- 6.0 * dirxyxy
+ diryyyy
);
2429 out
[35] = -3.0f
/ 32.0f
* sqrtf(154.0f
/ D3DX_PI
) * dir
->x
* (dirxxxx
- 10.0f
* dirxyxy
+ 5.0f
* diryyyy
);
2434 HRESULT WINAPI
D3DXSHEvalDirectionalLight(UINT order
, const D3DXVECTOR3
*dir
, FLOAT Rintensity
, FLOAT Gintensity
, FLOAT Bintensity
, FLOAT
*Rout
, FLOAT
*Gout
, FLOAT
*Bout
)
2439 TRACE("Order %u, Vector %p, Red %f, Green %f, Blue %f, Rout %p, Gout %p, Bout %p\n", order
, dir
, Rintensity
, Gintensity
, Bintensity
, Rout
, Gout
, Bout
);
2448 D3DXSHEvalDirection(Rout
, order
, dir
);
2449 for (j
= 0; j
< order
* order
; j
++)
2453 Rout
[j
] = Rintensity
* temp
;
2455 Gout
[j
] = Gintensity
* temp
;
2457 Bout
[j
] = Bintensity
* temp
;
2463 HRESULT WINAPI
D3DXSHEvalHemisphereLight(UINT order
, const D3DXVECTOR3
*dir
, D3DXCOLOR top
, D3DXCOLOR bottom
,
2464 FLOAT
*rout
, FLOAT
*gout
, FLOAT
*bout
)
2466 FLOAT a
[2], temp
[4];
2469 TRACE("order %u, dir %p, rout %p, gout %p, bout %p\n", order
, dir
, rout
, gout
, bout
);
2471 D3DXSHEvalDirection(temp
, 2, dir
);
2473 a
[0] = (top
.r
+ bottom
.r
) * 3.0f
* D3DX_PI
;
2474 a
[1] = (top
.r
- bottom
.r
) * D3DX_PI
;
2475 for (i
= 0; i
< order
; i
++)
2476 for (j
= 0; j
< 2 * i
+ 1; j
++)
2478 rout
[i
* i
+ j
] = temp
[i
* i
+ j
] * a
[i
];
2480 rout
[i
* i
+ j
] = 0.0f
;
2484 a
[0] = (top
.g
+ bottom
.g
) * 3.0f
* D3DX_PI
;
2485 a
[1] = (top
.g
- bottom
.g
) * D3DX_PI
;
2486 for (i
= 0; i
< order
; i
++)
2487 for (j
= 0; j
< 2 * i
+ 1; j
++)
2489 gout
[i
* i
+ j
] = temp
[i
* i
+ j
] * a
[i
];
2491 gout
[i
* i
+ j
] = 0.0f
;
2496 a
[0] = (top
.b
+ bottom
.b
) * 3.0f
* D3DX_PI
;
2497 a
[1] = (top
.b
- bottom
.b
) * D3DX_PI
;
2498 for (i
= 0; i
< order
; i
++)
2499 for (j
= 0; j
< 2 * i
+ 1; j
++)
2501 bout
[i
* i
+ j
] = temp
[i
* i
+ j
] * a
[i
];
2503 bout
[i
* i
+ j
] = 0.0f
;
2509 HRESULT WINAPI
D3DXSHEvalSphericalLight(UINT order
, const D3DXVECTOR3
*dir
, FLOAT radius
,
2510 FLOAT Rintensity
, FLOAT Gintensity
, FLOAT Bintensity
, FLOAT
*rout
, FLOAT
*gout
, FLOAT
*bout
)
2513 FLOAT cap
[6], clamped_angle
, dist
, temp
;
2516 TRACE("order %u, dir %p, radius %f, red %f, green %f, blue %f, rout %p, gout %p, bout %p\n",
2517 order
, dir
, radius
, Rintensity
, Gintensity
, Bintensity
, rout
, gout
, bout
);
2519 if (order
> D3DXSH_MAXORDER
)
2521 WARN("Order clamped at D3DXSH_MAXORDER\n");
2522 order
= D3DXSH_MAXORDER
;
2528 dist
= D3DXVec3Length(dir
);
2529 clamped_angle
= (dist
<= radius
) ? D3DX_PI
/ 2.0f
: asinf(radius
/ dist
);
2531 weightedcapintegrale(cap
, order
, clamped_angle
);
2532 D3DXVec3Normalize(&normal
, dir
);
2533 D3DXSHEvalDirection(rout
, order
, &normal
);
2535 for (i
= 0; i
< order
; i
++)
2536 for (j
= 0; j
< 2 * i
+ 1; j
++)
2539 temp
= rout
[index
] * cap
[i
];
2541 rout
[index
] = temp
* Rintensity
;
2543 gout
[index
] = temp
* Gintensity
;
2545 bout
[index
] = temp
* Bintensity
;
2551 FLOAT
* WINAPI
D3DXSHMultiply2(FLOAT
*out
, const FLOAT
*a
, const FLOAT
*b
)
2555 TRACE("out %p, a %p, b %p\n", out
, a
, b
);
2557 ta
= 0.28209479f
* a
[0];
2558 tb
= 0.28209479f
* b
[0];
2560 out
[0] = 0.28209479f
* D3DXSHDot(2, a
, b
);
2561 out
[1] = ta
* b
[1] + tb
* a
[1];
2562 out
[2] = ta
* b
[2] + tb
* a
[2];
2563 out
[3] = ta
* b
[3] + tb
* a
[3];
2568 FLOAT
* WINAPI
D3DXSHMultiply3(FLOAT
*out
, const FLOAT
*a
, const FLOAT
*b
)
2572 TRACE("out %p, a %p, b %p\n", out
, a
, b
);
2574 out
[0] = 0.28209479f
* a
[0] * b
[0];
2576 ta
= 0.28209479f
* a
[0] - 0.12615662f
* a
[6] - 0.21850968f
* a
[8];
2577 tb
= 0.28209479f
* b
[0] - 0.12615662f
* b
[6] - 0.21850968f
* b
[8];
2578 out
[1] = ta
* b
[1] + tb
* a
[1];
2580 out
[0] += 0.28209479f
* t
;
2581 out
[6] = -0.12615662f
* t
;
2582 out
[8] = -0.21850968f
* t
;
2584 ta
= 0.21850968f
* a
[5];
2585 tb
= 0.21850968f
* b
[5];
2586 out
[1] += ta
* b
[2] + tb
* a
[2];
2587 out
[2] = ta
* b
[1] + tb
* a
[1];
2588 t
= a
[1] * b
[2] +a
[2] * b
[1];
2589 out
[5] = 0.21850968f
* t
;
2591 ta
= 0.21850968f
* a
[4];
2592 tb
= 0.21850968f
* b
[4];
2593 out
[1] += ta
* b
[3] + tb
* a
[3];
2594 out
[3] = ta
* b
[1] + tb
* a
[1];
2595 t
= a
[1] * b
[3] + a
[3] * b
[1];
2596 out
[4] = 0.21850968f
* t
;
2598 ta
= 0.28209480f
* a
[0] + 0.25231326f
* a
[6];
2599 tb
= 0.28209480f
* b
[0] + 0.25231326f
* b
[6];
2600 out
[2] += ta
* b
[2] + tb
* a
[2];
2602 out
[0] += 0.28209480f
* t
;
2603 out
[6] += 0.25231326f
* t
;
2605 ta
= 0.21850969f
* a
[7];
2606 tb
= 0.21850969f
* b
[7];
2607 out
[2] += ta
* b
[3] + tb
* a
[3];
2608 out
[3] += ta
* b
[2] + tb
* a
[2];
2609 t
= a
[2] * b
[3] + a
[3] * b
[2];
2610 out
[7] = 0.21850969f
* t
;
2612 ta
= 0.28209479f
* a
[0] - 0.12615663f
* a
[6] + 0.21850969f
* a
[8];
2613 tb
= 0.28209479f
* b
[0] - 0.12615663f
* b
[6] + 0.21850969f
* b
[8];
2614 out
[3] += ta
* b
[3] + tb
* a
[3];
2616 out
[0] += 0.28209479f
* t
;
2617 out
[6] -= 0.12615663f
* t
;
2618 out
[8] += 0.21850969f
* t
;
2620 ta
= 0.28209479f
* a
[0] - 0.18022375f
* a
[6];
2621 tb
= 0.28209479f
* b
[0] - 0.18022375f
* b
[6];
2622 out
[4] += ta
* b
[4] + tb
* a
[4];
2624 out
[0] += 0.28209479f
* t
;
2625 out
[6] -= 0.18022375f
* t
;
2627 ta
= 0.15607835f
* a
[7];
2628 tb
= 0.15607835f
* b
[7];
2629 out
[4] += ta
* b
[5] + tb
* a
[5];
2630 out
[5] += ta
* b
[4] + tb
* a
[4];
2631 t
= a
[4] * b
[5] + a
[5] * b
[4];
2632 out
[7] += 0.15607834f
* t
;
2634 ta
= 0.28209479f
* a
[0] + 0.09011186 * a
[6] - 0.15607835f
* a
[8];
2635 tb
= 0.28209479f
* b
[0] + 0.09011186 * b
[6] - 0.15607835f
* b
[8];
2636 out
[5] += ta
* b
[5] + tb
* a
[5];
2638 out
[0] += 0.28209479f
* t
;
2639 out
[6] += 0.09011186f
* t
;
2640 out
[8] -= 0.15607835f
* t
;
2642 ta
= 0.28209480f
* a
[0];
2643 tb
= 0.28209480f
* b
[0];
2644 out
[6] += ta
* b
[6] + tb
* a
[6];
2646 out
[0] += 0.28209480f
* t
;
2647 out
[6] += 0.18022376f
* t
;
2649 ta
= 0.28209479f
* a
[0] + 0.09011186 * a
[6] + 0.15607835f
* a
[8];
2650 tb
= 0.28209479f
* b
[0] + 0.09011186 * b
[6] + 0.15607835f
* b
[8];
2651 out
[7] += ta
* b
[7] + tb
* a
[7];
2653 out
[0] += 0.28209479f
* t
;
2654 out
[6] += 0.09011186f
* t
;
2655 out
[8] += 0.15607835f
* t
;
2657 ta
= 0.28209479f
* a
[0] - 0.18022375f
* a
[6];
2658 tb
= 0.28209479f
* b
[0] - 0.18022375f
* b
[6];
2659 out
[8] += ta
* b
[8] + tb
* a
[8];
2661 out
[0] += 0.28209479f
* t
;
2662 out
[6] -= 0.18022375f
* t
;
2667 FLOAT
* WINAPI
D3DXSHMultiply4(FLOAT
*out
, const FLOAT
*a
, const FLOAT
*b
)
2671 TRACE("out %p, a %p, b %p\n", out
, a
, b
);
2673 out
[0] = 0.28209479f
* a
[0] * b
[0];
2675 ta
= 0.28209479f
* a
[0] - 0.12615663f
* a
[6] - 0.21850969f
* a
[8];
2676 tb
= 0.28209479f
* b
[0] - 0.12615663f
* b
[6] - 0.21850969f
* b
[8];
2677 out
[1] = ta
* b
[1] + tb
* a
[1];
2679 out
[0] += 0.28209479f
* t
;
2680 out
[6] = -0.12615663f
* t
;
2681 out
[8] = -0.21850969f
* t
;
2683 ta
= 0.21850969f
* a
[3] - 0.05839917f
* a
[13] - 0.22617901f
* a
[15];
2684 tb
= 0.21850969f
* b
[3] - 0.05839917f
* b
[13] - 0.22617901f
* b
[15];
2685 out
[1] += ta
* b
[4] + tb
* a
[4];
2686 out
[4] = ta
* b
[1] + tb
* a
[1];
2687 t
= a
[1] * b
[4] + a
[4] * b
[1];
2688 out
[3] = 0.21850969f
* t
;
2689 out
[13] = -0.05839917f
* t
;
2690 out
[15] = -0.22617901f
* t
;
2692 ta
= 0.21850969f
* a
[2] - 0.14304817f
* a
[12] - 0.18467439f
* a
[14];
2693 tb
= 0.21850969f
* b
[2] - 0.14304817f
* b
[12] - 0.18467439f
* b
[14];
2694 out
[1] += ta
* b
[5] + tb
* a
[5];
2695 out
[5] = ta
* b
[1] + tb
* a
[1];
2696 t
= a
[1] * b
[5] + a
[5] * b
[1];
2697 out
[2] = 0.21850969f
* t
;
2698 out
[12] = -0.14304817f
* t
;
2699 out
[14] = -0.18467439f
* t
;
2701 ta
= 0.20230066f
* a
[11];
2702 tb
= 0.20230066f
* b
[11];
2703 out
[1] += ta
* b
[6] + tb
* a
[6];
2704 out
[6] += ta
* b
[1] + tb
* a
[1];
2705 t
= a
[1] * b
[6] + a
[6] * b
[1];
2706 out
[11] = 0.20230066f
* t
;
2708 ta
= 0.22617901f
* a
[9] + 0.05839917f
* a
[11];
2709 tb
= 0.22617901f
* b
[9] + 0.05839917f
* b
[11];
2710 out
[1] += ta
* b
[8] + tb
* a
[8];
2711 out
[8] += ta
* b
[1] + tb
* a
[1];
2712 t
= a
[1] * b
[8] + a
[8] * b
[1];
2713 out
[9] = 0.22617901f
* t
;
2714 out
[11] += 0.05839917f
* t
;
2716 ta
= 0.28209480f
* a
[0] + 0.25231326f
* a
[6];
2717 tb
= 0.28209480f
* b
[0] + 0.25231326f
* b
[6];
2718 out
[2] += ta
* b
[2] + tb
* a
[2];
2720 out
[0] += 0.28209480f
* t
;
2721 out
[6] += 0.25231326f
* t
;
2723 ta
= 0.24776671f
* a
[12];
2724 tb
= 0.24776671f
* b
[12];
2725 out
[2] += ta
* b
[6] + tb
* a
[6];
2726 out
[6] += ta
* b
[2] + tb
* a
[2];
2727 t
= a
[2] * b
[6] + a
[6] * b
[2];
2728 out
[12] += 0.24776671f
* t
;
2730 ta
= 0.28209480f
* a
[0] - 0.12615663f
* a
[6] + 0.21850969f
* a
[8];
2731 tb
= 0.28209480f
* b
[0] - 0.12615663f
* b
[6] + 0.21850969f
* b
[8];
2732 out
[3] += ta
* b
[3] + tb
* a
[3];
2734 out
[0] += 0.28209480f
* t
;
2735 out
[6] -= 0.12615663f
* t
;
2736 out
[8] += 0.21850969f
* t
;
2738 ta
= 0.20230066f
* a
[13];
2739 tb
= 0.20230066f
* b
[13];
2740 out
[3] += ta
* b
[6] + tb
* a
[6];
2741 out
[6] += ta
* b
[3] + tb
* a
[3];
2742 t
= a
[3] * b
[6] + a
[6] * b
[3];
2743 out
[13] += 0.20230066f
* t
;
2745 ta
= 0.21850969f
* a
[2] - 0.14304817f
* a
[12] + 0.18467439f
* a
[14];
2746 tb
= 0.21850969f
* b
[2] - 0.14304817f
* b
[12] + 0.18467439f
* b
[14];
2747 out
[3] += ta
* b
[7] + tb
* a
[7];
2748 out
[7] = ta
* b
[3] + tb
* a
[3];
2749 t
= a
[3] * b
[7] + a
[7] * b
[3];
2750 out
[2] += 0.21850969f
* t
;
2751 out
[12] -= 0.14304817f
* t
;
2752 out
[14] += 0.18467439f
* t
;
2754 ta
= -0.05839917f
* a
[13] + 0.22617901f
* a
[15];
2755 tb
= -0.05839917f
* b
[13] + 0.22617901f
* b
[15];
2756 out
[3] += ta
* b
[8] + tb
* a
[8];
2757 out
[8] += ta
* b
[3] + tb
* a
[3];
2758 t
= a
[3] * b
[8] + a
[8] * b
[3];
2759 out
[13] -= 0.05839917f
* t
;
2760 out
[15] += 0.22617901f
* t
;
2762 ta
= 0.28209479f
* a
[0] - 0.18022375f
* a
[6];
2763 tb
= 0.28209479f
* b
[0] - 0.18022375f
* b
[6];
2764 out
[4] += ta
* b
[4] + tb
* a
[4];
2766 out
[0] += 0.28209479f
* t
;
2767 out
[6] -= 0.18022375f
* t
;
2769 ta
= 0.15607835f
* a
[7];
2770 tb
= 0.15607835f
* b
[7];
2771 out
[4] += ta
* b
[5] + tb
* a
[5];
2772 out
[5] += ta
* b
[4] + tb
* a
[4];
2773 t
= a
[4] * b
[5] + a
[5] * b
[4];
2774 out
[7] += 0.15607835f
* t
;
2776 ta
= 0.22617901f
* a
[3] - 0.09403160f
* a
[13];
2777 tb
= 0.22617901f
* b
[3] - 0.09403160f
* b
[13];
2778 out
[4] += ta
* b
[9] + tb
* a
[9];
2779 out
[9] += ta
* b
[4] + tb
* a
[4];
2780 t
= a
[4] * b
[9] + a
[9] * b
[4];
2781 out
[3] += 0.22617901f
* t
;
2782 out
[13] -= 0.09403160f
* t
;
2784 ta
= 0.18467439f
* a
[2] - 0.18806319f
* a
[12];
2785 tb
= 0.18467439f
* b
[2] - 0.18806319f
* b
[12];
2786 out
[4] += ta
* b
[10] + tb
* a
[10];
2787 out
[10] = ta
* b
[4] + tb
* a
[4];
2788 t
= a
[4] * b
[10] + a
[10] * b
[4];
2789 out
[2] += 0.18467439f
* t
;
2790 out
[12] -= 0.18806319f
* t
;
2792 ta
= -0.05839917f
* a
[3] + 0.14567312f
* a
[13] + 0.09403160f
* a
[15];
2793 tb
= -0.05839917f
* b
[3] + 0.14567312f
* b
[13] + 0.09403160f
* b
[15];
2794 out
[4] += ta
* b
[11] + tb
* a
[11];
2795 out
[11] += ta
* b
[4] + tb
* a
[4];
2796 t
= a
[4] * b
[11] + a
[11] * b
[4];
2797 out
[3] -= 0.05839917f
* t
;
2798 out
[13] += 0.14567312f
* t
;
2799 out
[15] += 0.09403160f
* t
;
2801 ta
= 0.28209479f
* a
[0] + 0.09011186f
* a
[6] - 0.15607835f
* a
[8];
2802 tb
= 0.28209479f
* b
[0] + 0.09011186f
* b
[6] - 0.15607835f
* b
[8];
2803 out
[5] += ta
* b
[5] + tb
* a
[5];
2805 out
[0] += 0.28209479f
* t
;
2806 out
[6] += 0.09011186f
* t
;
2807 out
[8] -= 0.15607835f
* t
;
2809 ta
= 0.14867701f
* a
[14];
2810 tb
= 0.14867701f
* b
[14];
2811 out
[5] += ta
* b
[9] + tb
* a
[9];
2812 out
[9] += ta
* b
[5] + tb
* a
[5];
2813 t
= a
[5] * b
[9] + a
[9] * b
[5];
2814 out
[14] += 0.14867701f
* t
;
2816 ta
= 0.18467439f
* a
[3] + 0.11516472f
* a
[13] - 0.14867701f
* a
[15];
2817 tb
= 0.18467439f
* b
[3] + 0.11516472f
* b
[13] - 0.14867701f
* b
[15];
2818 out
[5] += ta
* b
[10] + tb
* a
[10];
2819 out
[10] += ta
* b
[5] + tb
* a
[5];
2820 t
= a
[5] * b
[10] + a
[10] * b
[5];
2821 out
[3] += 0.18467439f
* t
;
2822 out
[13] += 0.11516472f
* t
;
2823 out
[15] -= 0.14867701f
* t
;
2825 ta
= 0.23359668f
* a
[2] + 0.05947080f
* a
[12] - 0.11516472f
* a
[14];
2826 tb
= 0.23359668f
* b
[2] + 0.05947080f
* b
[12] - 0.11516472f
* b
[14];
2827 out
[5] += ta
* b
[11] + tb
* a
[11];
2828 out
[11] += ta
* b
[5] + tb
* a
[5];
2829 t
= a
[5] * b
[11] + a
[11] * b
[5];
2830 out
[2] += 0.23359668f
* t
;
2831 out
[12] += 0.05947080f
* t
;
2832 out
[14] -= 0.11516472f
* t
;
2834 ta
= 0.28209479f
* a
[0];
2835 tb
= 0.28209479f
* b
[0];
2836 out
[6] += ta
* b
[6] + tb
* a
[6];
2838 out
[0] += 0.28209479f
* t
;
2839 out
[6] += 0.18022376f
* t
;
2841 ta
= 0.09011186f
* a
[6] + 0.28209479f
* a
[0] + 0.15607835f
* a
[8];
2842 tb
= 0.09011186f
* b
[6] + 0.28209479f
* b
[0] + 0.15607835f
* b
[8];
2843 out
[7] += ta
* b
[7] + tb
* a
[7];
2845 out
[6] += 0.09011186f
* t
;
2846 out
[0] += 0.28209479f
* t
;
2847 out
[8] += 0.15607835f
* t
;
2849 ta
= 0.14867701f
* a
[9] + 0.18467439f
* a
[1] + 0.11516472f
* a
[11];
2850 tb
= 0.14867701f
* b
[9] + 0.18467439f
* b
[1] + 0.11516472f
* b
[11];
2851 out
[7] += ta
* b
[10] + tb
* a
[10];
2852 out
[10] += ta
* b
[7] + tb
* a
[7];
2853 t
= a
[7] * b
[10] + a
[10] * b
[7];
2854 out
[9] += 0.14867701f
* t
;
2855 out
[1] += 0.18467439f
* t
;
2856 out
[11] += 0.11516472f
* t
;
2858 ta
= 0.05947080f
* a
[12] + 0.23359668f
* a
[2] + 0.11516472f
* a
[14];
2859 tb
= 0.05947080f
* b
[12] + 0.23359668f
* b
[2] + 0.11516472f
* b
[14];
2860 out
[7] += ta
* b
[13] + tb
* a
[13];
2861 out
[13] += ta
* b
[7]+ tb
* a
[7];
2862 t
= a
[7] * b
[13] + a
[13] * b
[7];
2863 out
[12] += 0.05947080f
* t
;
2864 out
[2] += 0.23359668f
* t
;
2865 out
[14] += 0.11516472f
* t
;
2867 ta
= 0.14867701f
* a
[15];
2868 tb
= 0.14867701f
* b
[15];
2869 out
[7] += ta
* b
[14] + tb
* a
[14];
2870 out
[14] += ta
* b
[7] + tb
* a
[7];
2871 t
= a
[7] * b
[14] + a
[14] * b
[7];
2872 out
[15] += 0.14867701f
* t
;
2874 ta
= 0.28209479f
* a
[0] - 0.18022375f
* a
[6];
2875 tb
= 0.28209479f
* b
[0] - 0.18022375f
* b
[6];
2876 out
[8] += ta
* b
[8] + tb
* a
[8];
2878 out
[0] += 0.28209479f
* t
;
2879 out
[6] -= 0.18022375f
* t
;
2881 ta
= -0.09403160f
* a
[11];
2882 tb
= -0.09403160f
* b
[11];
2883 out
[8] += ta
* b
[9] + tb
* a
[9];
2884 out
[9] += ta
* b
[8] + tb
* a
[8];
2885 t
= a
[8] * b
[9] + a
[9] * b
[8];
2886 out
[11] -= 0.09403160f
* t
;
2888 ta
= -0.09403160f
* a
[15];
2889 tb
= -0.09403160f
* b
[15];
2890 out
[8] += ta
* b
[13] + tb
* a
[13];
2891 out
[13] += ta
* b
[8] + tb
* a
[8];
2892 t
= a
[8] * b
[13] + a
[13] * b
[8];
2893 out
[15] -= 0.09403160f
* t
;
2895 ta
= 0.18467439f
* a
[2] - 0.18806319f
* a
[12];
2896 tb
= 0.18467439f
* b
[2] - 0.18806319f
* b
[12];
2897 out
[8] += ta
* b
[14] + tb
* a
[14];
2898 out
[14] += ta
* b
[8] + tb
* a
[8];
2899 t
= a
[8] * b
[14] + a
[14] * b
[8];
2900 out
[2] += 0.18467439f
* t
;
2901 out
[12] -= 0.18806319f
* t
;
2903 ta
= -0.21026104f
* a
[6] + 0.28209479f
* a
[0];
2904 tb
= -0.21026104f
* b
[6] + 0.28209479f
* b
[0];
2905 out
[9] += ta
* b
[9] + tb
* a
[9];
2907 out
[6] -= 0.21026104f
* t
;
2908 out
[0] += 0.28209479f
* t
;
2910 ta
= 0.28209479f
* a
[0];
2911 tb
= 0.28209479f
* b
[0];
2912 out
[10] += ta
* b
[10] + tb
* a
[10];
2914 out
[0] += 0.28209479f
* t
;
2916 ta
= 0.28209479f
* a
[0] + 0.12615663f
* a
[6] - 0.14567312f
* a
[8];
2917 tb
= 0.28209479f
* b
[0] + 0.12615663f
* b
[6] - 0.14567312f
* b
[8];
2918 out
[11] += ta
* b
[11] + tb
* a
[11];
2920 out
[0] += 0.28209479f
* t
;
2921 out
[6] += 0.12615663f
* t
;
2922 out
[8] -= 0.14567312f
* t
;
2924 ta
= 0.28209479f
* a
[0] + 0.16820885f
* a
[6];
2925 tb
= 0.28209479f
* b
[0] + 0.16820885f
* b
[6];
2926 out
[12] += ta
* b
[12] + tb
* a
[12];
2928 out
[0] += 0.28209479f
* t
;
2929 out
[6] += 0.16820885f
* t
;
2931 ta
=0.28209479f
* a
[0] + 0.14567312f
* a
[8] + 0.12615663f
* a
[6];
2932 tb
=0.28209479f
* b
[0] + 0.14567312f
* b
[8] + 0.12615663f
* b
[6];
2933 out
[13] += ta
* b
[13] + tb
* a
[13];
2935 out
[0] += 0.28209479f
* t
;
2936 out
[8] += 0.14567312f
* t
;
2937 out
[6] += 0.12615663f
* t
;
2939 ta
= 0.28209479f
* a
[0];
2940 tb
= 0.28209479f
* b
[0];
2941 out
[14] += ta
* b
[14] + tb
* a
[14];
2943 out
[0] += 0.28209479f
* t
;
2945 ta
= 0.28209479f
* a
[0] - 0.21026104f
* a
[6];
2946 tb
= 0.28209479f
* b
[0] - 0.21026104f
* b
[6];
2947 out
[15] += ta
* b
[15] + tb
* a
[15];
2949 out
[0] += 0.28209479f
* t
;
2950 out
[6] -= 0.21026104f
* t
;
2955 static void rotate_X(FLOAT
*out
, UINT order
, FLOAT a
, FLOAT
*in
)
2960 out
[2] = -a
* in
[1];
2965 out
[6] = -0.5f
* in
[6] - 0.8660253882f
* in
[8];
2966 out
[7] = -a
* in
[4];
2967 out
[8] = -0.8660253882f
* in
[6] + 0.5f
* in
[8];
2968 out
[9] = -a
* 0.7905694842f
* in
[12] + a
* 0.6123724580f
* in
[14];
2971 out
[11] = -a
* 0.6123724580f
* in
[12] - a
* 0.7905694842f
* in
[14];
2972 out
[12] = a
* 0.7905694842f
* in
[9] + a
* 0.6123724580f
* in
[11];
2973 out
[13] = -0.25f
* in
[13] - 0.9682458639f
* in
[15];
2974 out
[14] = -a
* 0.6123724580f
* in
[9] + a
* 0.7905694842f
* in
[11];
2975 out
[15] = -0.9682458639f
* in
[13] + 0.25f
* in
[15];
2979 out
[16] = -a
* 0.9354143739f
* in
[21] + a
* 0.3535533845f
* in
[23];
2980 out
[17] = -0.75f
* in
[17] + 0.6614378095f
* in
[19];
2981 out
[18] = -a
* 0.3535533845f
* in
[21] - a
* 0.9354143739f
* in
[23];
2982 out
[19] = 0.6614378095f
* in
[17] + 0.75f
* in
[19];
2983 out
[20] = 0.375f
* in
[20] + 0.5590170026f
* in
[22] + 0.7395099998f
* in
[24];
2984 out
[21] = a
* 0.9354143739f
* in
[16] + a
* 0.3535533845f
* in
[18];
2985 out
[22] = 0.5590170026f
* in
[20] + 0.5f
* in
[22] - 0.6614378691f
* in
[24];
2986 out
[23] = -a
* 0.3535533845f
* in
[16] + a
* 0.9354143739f
* in
[18];
2987 out
[24] = 0.7395099998f
* in
[20] - 0.6614378691f
* in
[22] + 0.125f
* in
[24];
2991 out
[25] = a
* 0.7015607357f
* in
[30] - a
* 0.6846531630f
* in
[32] + a
* 0.1976423711f
* in
[34];
2992 out
[26] = -0.5f
* in
[26] + 0.8660253882f
* in
[28];
2993 out
[27] = a
* 0.5229125023f
* in
[30] + a
* 0.3061861992f
* in
[32] - a
* 0.7954951525 * in
[34];
2994 out
[28] = 0.8660253882f
* in
[26] + 0.5f
* in
[28];
2995 out
[29] = a
* 0.4841229022f
* in
[30] + a
* 0.6614378691f
* in
[32] + a
* 0.5728219748f
* in
[34];
2996 out
[30] = -a
* 0.7015607357f
* in
[25] - a
* 0.5229125023f
* in
[27] - a
* 0.4841229022f
* in
[29];
2997 out
[31] = 0.125f
* in
[31] + 0.4050463140f
* in
[33] + 0.9057110548f
* in
[35];
2998 out
[32] = a
* 0.6846531630f
* in
[25] - a
* 0.3061861992f
* in
[27] - a
* 0.6614378691f
* in
[29];
2999 out
[33] = 0.4050463140f
* in
[31] + 0.8125f
* in
[33] - 0.4192627370f
* in
[35];
3000 out
[34] = -a
* 0.1976423711f
* in
[25] + a
* 0.7954951525f
* in
[27] - a
* 0.5728219748f
* in
[29];
3001 out
[35] = 0.9057110548f
* in
[31] - 0.4192627370f
* in
[33] + 0.0624999329f
* in
[35];
3004 FLOAT
* WINAPI
D3DXSHRotate(FLOAT
*out
, UINT order
, const D3DXMATRIX
*matrix
, const FLOAT
*in
)
3006 FLOAT alpha
, beta
, gamma
, sinb
, temp
[36], temp1
[36];
3008 TRACE("out %p, order %u, matrix %p, in %p\n", out
, order
, matrix
, in
);
3012 if ((order
> D3DXSH_MAXORDER
) || (order
< D3DXSH_MINORDER
))
3017 out
[1] = matrix
->u
.m
[1][1] * in
[1] - matrix
->u
.m
[2][1] * in
[2] + matrix
->u
.m
[0][1] * in
[3];
3018 out
[2] = -matrix
->u
.m
[1][2] * in
[1] + matrix
->u
.m
[2][2] * in
[2] - matrix
->u
.m
[0][2] * in
[3];
3019 out
[3] = matrix
->u
.m
[1][0] * in
[1] - matrix
->u
.m
[2][0] * in
[2] + matrix
->u
.m
[0][0] * in
[3];
3024 matrix
->u
.m
[1][0] * matrix
->u
.m
[0][0], matrix
->u
.m
[1][1] * matrix
->u
.m
[0][1],
3025 matrix
->u
.m
[1][1] * matrix
->u
.m
[2][1], matrix
->u
.m
[1][0] * matrix
->u
.m
[2][0],
3026 matrix
->u
.m
[2][0] * matrix
->u
.m
[2][0], matrix
->u
.m
[2][1] * matrix
->u
.m
[2][1],
3027 matrix
->u
.m
[0][0] * matrix
->u
.m
[2][0], matrix
->u
.m
[0][1] * matrix
->u
.m
[2][1],
3028 matrix
->u
.m
[0][1] * matrix
->u
.m
[0][1], matrix
->u
.m
[1][0] * matrix
->u
.m
[1][0],
3029 matrix
->u
.m
[1][1] * matrix
->u
.m
[1][1], matrix
->u
.m
[0][0] * matrix
->u
.m
[0][0], };
3031 out
[4] = (matrix
->u
.m
[1][1] * matrix
->u
.m
[0][0] + matrix
->u
.m
[0][1] * matrix
->u
.m
[1][0]) * in
[4];
3032 out
[4] -= (matrix
->u
.m
[1][0] * matrix
->u
.m
[2][1] + matrix
->u
.m
[1][1] * matrix
->u
.m
[2][0]) * in
[5];
3033 out
[4] += 1.7320508076f
* matrix
->u
.m
[2][0] * matrix
->u
.m
[2][1] * in
[6];
3034 out
[4] -= (matrix
->u
.m
[0][1] * matrix
->u
.m
[2][0] + matrix
->u
.m
[0][0] * matrix
->u
.m
[2][1]) * in
[7];
3035 out
[4] += (matrix
->u
.m
[0][0] * matrix
->u
.m
[0][1] - matrix
->u
.m
[1][0] * matrix
->u
.m
[1][1]) * in
[8];
3037 out
[5] = (matrix
->u
.m
[1][1] * matrix
->u
.m
[2][2] + matrix
->u
.m
[1][2] * matrix
->u
.m
[2][1]) * in
[5];
3038 out
[5] -= (matrix
->u
.m
[1][1] * matrix
->u
.m
[0][2] + matrix
->u
.m
[1][2] * matrix
->u
.m
[0][1]) * in
[4];
3039 out
[5] -= 1.7320508076f
* matrix
->u
.m
[2][2] * matrix
->u
.m
[2][1] * in
[6];
3040 out
[5] += (matrix
->u
.m
[0][2] * matrix
->u
.m
[2][1] + matrix
->u
.m
[0][1] * matrix
->u
.m
[2][2]) * in
[7];
3041 out
[5] -= (matrix
->u
.m
[0][1] * matrix
->u
.m
[0][2] - matrix
->u
.m
[1][1] * matrix
->u
.m
[1][2]) * in
[8];
3043 out
[6] = (matrix
->u
.m
[2][2] * matrix
->u
.m
[2][2] - 0.5f
* (coeff
[4] + coeff
[5])) * in
[6];
3044 out
[6] -= (0.5773502692f
* (coeff
[0] + coeff
[1]) - 1.1547005384f
* matrix
->u
.m
[1][2] * matrix
->u
.m
[0][2]) * in
[4];
3045 out
[6] += (0.5773502692f
* (coeff
[2] + coeff
[3]) - 1.1547005384f
* matrix
->u
.m
[1][2] * matrix
->u
.m
[2][2]) * in
[5];
3046 out
[6] += (0.5773502692f
* (coeff
[6] + coeff
[7]) - 1.1547005384f
* matrix
->u
.m
[0][2] * matrix
->u
.m
[2][2]) * in
[7];
3047 out
[6] += (0.2886751347f
* (coeff
[9] - coeff
[8] + coeff
[10] - coeff
[11]) - 0.5773502692f
*
3048 (matrix
->u
.m
[1][2] * matrix
->u
.m
[1][2] - matrix
->u
.m
[0][2] * matrix
->u
.m
[0][2])) * in
[8];
3050 out
[7] = (matrix
->u
.m
[0][0] * matrix
->u
.m
[2][2] + matrix
->u
.m
[0][2] * matrix
->u
.m
[2][0]) * in
[7];
3051 out
[7] -= (matrix
->u
.m
[1][0] * matrix
->u
.m
[0][2] + matrix
->u
.m
[1][2] * matrix
->u
.m
[0][0]) * in
[4];
3052 out
[7] += (matrix
->u
.m
[1][0] * matrix
->u
.m
[2][2] + matrix
->u
.m
[1][2] * matrix
->u
.m
[2][0]) * in
[5];
3053 out
[7] -= 1.7320508076f
* matrix
->u
.m
[2][2] * matrix
->u
.m
[2][0] * in
[6];
3054 out
[7] -= (matrix
->u
.m
[0][0] * matrix
->u
.m
[0][2] - matrix
->u
.m
[1][0] * matrix
->u
.m
[1][2]) * in
[8];
3056 out
[8] = 0.5f
* (coeff
[11] - coeff
[8] - coeff
[9] + coeff
[10]) * in
[8];
3057 out
[8] += (coeff
[0] - coeff
[1]) * in
[4];
3058 out
[8] += (coeff
[2] - coeff
[3]) * in
[5];
3059 out
[8] += 0.86602540f
* (coeff
[4] - coeff
[5]) * in
[6];
3060 out
[8] += (coeff
[7] - coeff
[6]) * in
[7];
3066 if (fabsf(matrix
->u
.m
[2][2]) != 1.0f
)
3068 sinb
= sqrtf(1.0f
- matrix
->u
.m
[2][2] * matrix
->u
.m
[2][2]);
3069 alpha
= atan2f(matrix
->u
.m
[2][1] / sinb
, matrix
->u
.m
[2][0] / sinb
);
3070 beta
= atan2f(sinb
, matrix
->u
.m
[2][2]);
3071 gamma
= atan2f(matrix
->u
.m
[1][2] / sinb
, -matrix
->u
.m
[0][2] / sinb
);
3075 alpha
= atan2f(matrix
->u
.m
[0][1], matrix
->u
.m
[0][0]);
3080 D3DXSHRotateZ(temp
, order
, gamma
, in
);
3081 rotate_X(temp1
, order
, 1.0f
, temp
);
3082 D3DXSHRotateZ(temp
, order
, beta
, temp1
);
3083 rotate_X(temp1
, order
, -1.0f
, temp
);
3084 D3DXSHRotateZ(out
, order
, alpha
, temp1
);
3089 FLOAT
* WINAPI
D3DXSHRotateZ(FLOAT
*out
, UINT order
, FLOAT angle
, const FLOAT
*in
)
3094 TRACE("out %p, order %u, angle %f, in %p\n", out
, order
, angle
, in
);
3096 order
= min(max(order
, D3DXSH_MINORDER
), D3DXSH_MAXORDER
);
3100 for (i
= 1; i
< order
; i
++)
3104 c
[i
- 1] = cosf(i
* angle
);
3105 s
[i
- 1] = sinf(i
* angle
);
3108 out
[sum
- i
] = c
[i
- 1] * in
[sum
- i
];
3109 out
[sum
- i
] += s
[i
- 1] * in
[sum
+ i
];
3110 for (j
= i
- 1; j
> 0; j
--)
3112 out
[sum
- j
] = 0.0f
;
3113 out
[sum
- j
] = c
[j
- 1] * in
[sum
- j
];
3114 out
[sum
- j
] += s
[j
- 1] * in
[sum
+ j
];
3122 for (j
= 1; j
< i
; j
++)
3124 out
[sum
+ j
] = 0.0f
;
3125 out
[sum
+ j
] = -s
[j
- 1] * in
[sum
- j
];
3126 out
[sum
+ j
] += c
[j
- 1] * in
[sum
+ j
];
3128 out
[sum
+ i
] = -s
[i
- 1] * in
[sum
- i
];
3129 out
[sum
+ i
] += c
[i
- 1] * in
[sum
+ i
];
3135 FLOAT
* WINAPI
D3DXSHScale(FLOAT
*out
, UINT order
, const FLOAT
*a
, const FLOAT scale
)
3139 TRACE("out %p, order %u, a %p, scale %f\n", out
, order
, a
, scale
);
3141 for (i
= 0; i
< order
* order
; i
++)
3142 out
[i
] = a
[i
] * scale
;