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
28 #include "wine/port.h"
32 #include "d3dx9_36_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
38 static const ID3DXMatrixStackVtbl ID3DXMatrixStack_Vtbl
;
40 typedef struct ID3DXMatrixStackImpl
42 ID3DXMatrixStack ID3DXMatrixStack_iface
;
46 unsigned int stack_size
;
48 } ID3DXMatrixStackImpl
;
51 /*_________________D3DXColor____________________*/
53 D3DXCOLOR
* WINAPI
D3DXColorAdjustContrast(D3DXCOLOR
*pout
, CONST D3DXCOLOR
*pc
, FLOAT s
)
55 TRACE("(%p, %p, %f)\n", pout
, pc
, s
);
57 pout
->r
= 0.5f
+ s
* (pc
->r
- 0.5f
);
58 pout
->g
= 0.5f
+ s
* (pc
->g
- 0.5f
);
59 pout
->b
= 0.5f
+ s
* (pc
->b
- 0.5f
);
64 D3DXCOLOR
* WINAPI
D3DXColorAdjustSaturation(D3DXCOLOR
*pout
, CONST D3DXCOLOR
*pc
, FLOAT s
)
68 TRACE("(%p, %p, %f)\n", pout
, pc
, s
);
70 grey
= pc
->r
* 0.2125f
+ pc
->g
* 0.7154f
+ pc
->b
* 0.0721f
;
71 pout
->r
= grey
+ s
* (pc
->r
- grey
);
72 pout
->g
= grey
+ s
* (pc
->g
- grey
);
73 pout
->b
= grey
+ s
* (pc
->b
- grey
);
78 /*_________________Misc__________________________*/
80 FLOAT WINAPI
D3DXFresnelTerm(FLOAT costheta
, FLOAT refractionindex
)
82 FLOAT a
, d
, g
, result
;
84 TRACE("(%f, %f)\n", costheta
, refractionindex
);
86 g
= sqrt(refractionindex
* refractionindex
+ costheta
* costheta
- 1.0f
);
89 result
= ( costheta
* a
- 1.0f
) * ( costheta
* a
- 1.0f
) / ( ( costheta
* d
+ 1.0f
) * ( costheta
* d
+ 1.0f
) ) + 1.0f
;
90 result
= result
* 0.5f
* d
* d
/ ( a
* a
);
94 /*_________________D3DXMatrix____________________*/
96 D3DXMATRIX
* WINAPI
D3DXMatrixAffineTransformation(D3DXMATRIX
*pout
, FLOAT scaling
, CONST D3DXVECTOR3
*rotationcenter
, CONST D3DXQUATERNION
*rotation
, CONST D3DXVECTOR3
*translation
)
98 D3DXMATRIX m1
, m2
, m3
, m4
, m5
;
100 TRACE("(%p, %f, %p, %p, %p)\n", pout
, scaling
, rotationcenter
, rotation
, translation
);
102 D3DXMatrixScaling(&m1
, scaling
, scaling
, scaling
);
104 if ( !rotationcenter
)
106 D3DXMatrixIdentity(&m2
);
107 D3DXMatrixIdentity(&m4
);
111 D3DXMatrixTranslation(&m2
, -rotationcenter
->x
, -rotationcenter
->y
, -rotationcenter
->z
);
112 D3DXMatrixTranslation(&m4
, rotationcenter
->x
, rotationcenter
->y
, rotationcenter
->z
);
115 if ( !rotation
) D3DXMatrixIdentity(&m3
);
116 else D3DXMatrixRotationQuaternion(&m3
, rotation
);
118 if ( !translation
) D3DXMatrixIdentity(&m5
);
119 else D3DXMatrixTranslation(&m5
, translation
->x
, translation
->y
, translation
->z
);
121 D3DXMatrixMultiply(&m1
, &m1
, &m2
);
122 D3DXMatrixMultiply(&m1
, &m1
, &m3
);
123 D3DXMatrixMultiply(&m1
, &m1
, &m4
);
124 D3DXMatrixMultiply(pout
, &m1
, &m5
);
128 D3DXMATRIX
* WINAPI
D3DXMatrixAffineTransformation2D(D3DXMATRIX
*pout
, FLOAT scaling
, CONST D3DXVECTOR2
*protationcenter
, FLOAT rotation
, CONST D3DXVECTOR2
*ptranslation
)
130 D3DXMATRIX m1
, m2
, m3
, m4
, m5
;
132 D3DXVECTOR3 rot_center
, trans
;
134 TRACE("(%p, %f, %p, %f, %p)\n", pout
, scaling
, protationcenter
, rotation
, ptranslation
);
136 rot
.w
=cos(rotation
/2.0f
);
139 rot
.z
=sin(rotation
/2.0f
);
141 if ( protationcenter
)
143 rot_center
.x
=protationcenter
->x
;
144 rot_center
.y
=protationcenter
->y
;
156 trans
.x
=ptranslation
->x
;
157 trans
.y
=ptranslation
->y
;
167 D3DXMatrixScaling(&m1
, scaling
, scaling
, 1.0f
);
168 D3DXMatrixTranslation(&m2
, -rot_center
.x
, -rot_center
.y
, -rot_center
.z
);
169 D3DXMatrixTranslation(&m4
, rot_center
.x
, rot_center
.y
, rot_center
.z
);
170 D3DXMatrixRotationQuaternion(&m3
, &rot
);
171 D3DXMatrixTranslation(&m5
, trans
.x
, trans
.y
, trans
.z
);
173 D3DXMatrixMultiply(&m1
, &m1
, &m2
);
174 D3DXMatrixMultiply(&m1
, &m1
, &m3
);
175 D3DXMatrixMultiply(&m1
, &m1
, &m4
);
176 D3DXMatrixMultiply(pout
, &m1
, &m5
);
181 HRESULT WINAPI
D3DXMatrixDecompose(D3DXVECTOR3
*poutscale
, D3DXQUATERNION
*poutrotation
, D3DXVECTOR3
*pouttranslation
, CONST D3DXMATRIX
*pm
)
183 D3DXMATRIX normalized
;
186 TRACE("(%p, %p, %p, %p)\n", poutscale
, poutrotation
, pouttranslation
, pm
);
188 /*Compute the scaling part.*/
192 poutscale
->x
=D3DXVec3Length(&vec
);
197 poutscale
->y
=D3DXVec3Length(&vec
);
202 poutscale
->z
=D3DXVec3Length(&vec
);
204 /*Compute the translation part.*/
205 pouttranslation
->x
=pm
->u
.m
[3][0];
206 pouttranslation
->y
=pm
->u
.m
[3][1];
207 pouttranslation
->z
=pm
->u
.m
[3][2];
209 /*Let's calculate the rotation now*/
210 if ( (poutscale
->x
== 0.0f
) || (poutscale
->y
== 0.0f
) || (poutscale
->z
== 0.0f
) ) return D3DERR_INVALIDCALL
;
212 normalized
.u
.m
[0][0]=pm
->u
.m
[0][0]/poutscale
->x
;
213 normalized
.u
.m
[0][1]=pm
->u
.m
[0][1]/poutscale
->x
;
214 normalized
.u
.m
[0][2]=pm
->u
.m
[0][2]/poutscale
->x
;
215 normalized
.u
.m
[1][0]=pm
->u
.m
[1][0]/poutscale
->y
;
216 normalized
.u
.m
[1][1]=pm
->u
.m
[1][1]/poutscale
->y
;
217 normalized
.u
.m
[1][2]=pm
->u
.m
[1][2]/poutscale
->y
;
218 normalized
.u
.m
[2][0]=pm
->u
.m
[2][0]/poutscale
->z
;
219 normalized
.u
.m
[2][1]=pm
->u
.m
[2][1]/poutscale
->z
;
220 normalized
.u
.m
[2][2]=pm
->u
.m
[2][2]/poutscale
->z
;
222 D3DXQuaternionRotationMatrix(poutrotation
,&normalized
);
226 FLOAT WINAPI
D3DXMatrixDeterminant(CONST D3DXMATRIX
*pm
)
228 D3DXVECTOR4 minor
, v1
, v2
, v3
;
233 v1
.x
= pm
->u
.m
[0][0]; v1
.y
= pm
->u
.m
[1][0]; v1
.z
= pm
->u
.m
[2][0]; v1
.w
= pm
->u
.m
[3][0];
234 v2
.x
= pm
->u
.m
[0][1]; v2
.y
= pm
->u
.m
[1][1]; v2
.z
= pm
->u
.m
[2][1]; v2
.w
= pm
->u
.m
[3][1];
235 v3
.x
= pm
->u
.m
[0][2]; v3
.y
= pm
->u
.m
[1][2]; v3
.z
= pm
->u
.m
[2][2]; v3
.w
= pm
->u
.m
[3][2];
236 D3DXVec4Cross(&minor
, &v1
, &v2
, &v3
);
237 det
= - (pm
->u
.m
[0][3] * minor
.x
+ pm
->u
.m
[1][3] * minor
.y
+ pm
->u
.m
[2][3] * minor
.z
+ pm
->u
.m
[3][3] * minor
.w
);
241 D3DXMATRIX
* WINAPI
D3DXMatrixInverse(D3DXMATRIX
*pout
, FLOAT
*pdeterminant
, CONST D3DXMATRIX
*pm
)
245 D3DXVECTOR4 v
, vec
[3];
248 TRACE("(%p, %p, %p)\n", pout
, pdeterminant
, pm
);
250 det
= D3DXMatrixDeterminant(pm
);
251 if ( !det
) return NULL
;
252 if ( pdeterminant
) *pdeterminant
= det
;
260 if ( j
> i
) a
= a
-1;
261 vec
[a
].x
= pm
->u
.m
[j
][0];
262 vec
[a
].y
= pm
->u
.m
[j
][1];
263 vec
[a
].z
= pm
->u
.m
[j
][2];
264 vec
[a
].w
= pm
->u
.m
[j
][3];
267 D3DXVec4Cross(&v
, &vec
[0], &vec
[1], &vec
[2]);
268 out
.u
.m
[0][i
] = pow(-1.0f
, i
) * v
.x
/ det
;
269 out
.u
.m
[1][i
] = pow(-1.0f
, i
) * v
.y
/ det
;
270 out
.u
.m
[2][i
] = pow(-1.0f
, i
) * v
.z
/ det
;
271 out
.u
.m
[3][i
] = pow(-1.0f
, i
) * v
.w
/ det
;
278 D3DXMATRIX
* WINAPI
D3DXMatrixLookAtLH(D3DXMATRIX
*pout
, CONST D3DXVECTOR3
*peye
, CONST D3DXVECTOR3
*pat
, CONST D3DXVECTOR3
*pup
)
280 D3DXVECTOR3 right
, rightn
, up
, upn
, vec
, vec2
;
282 TRACE("(%p, %p, %p, %p)\n", pout
, peye
, pat
, pup
);
284 D3DXVec3Subtract(&vec2
, pat
, peye
);
285 D3DXVec3Normalize(&vec
, &vec2
);
286 D3DXVec3Cross(&right
, pup
, &vec
);
287 D3DXVec3Cross(&up
, &vec
, &right
);
288 D3DXVec3Normalize(&rightn
, &right
);
289 D3DXVec3Normalize(&upn
, &up
);
290 pout
->u
.m
[0][0] = rightn
.x
;
291 pout
->u
.m
[1][0] = rightn
.y
;
292 pout
->u
.m
[2][0] = rightn
.z
;
293 pout
->u
.m
[3][0] = -D3DXVec3Dot(&rightn
,peye
);
294 pout
->u
.m
[0][1] = upn
.x
;
295 pout
->u
.m
[1][1] = upn
.y
;
296 pout
->u
.m
[2][1] = upn
.z
;
297 pout
->u
.m
[3][1] = -D3DXVec3Dot(&upn
, peye
);
298 pout
->u
.m
[0][2] = vec
.x
;
299 pout
->u
.m
[1][2] = vec
.y
;
300 pout
->u
.m
[2][2] = vec
.z
;
301 pout
->u
.m
[3][2] = -D3DXVec3Dot(&vec
, peye
);
302 pout
->u
.m
[0][3] = 0.0f
;
303 pout
->u
.m
[1][3] = 0.0f
;
304 pout
->u
.m
[2][3] = 0.0f
;
305 pout
->u
.m
[3][3] = 1.0f
;
309 D3DXMATRIX
* WINAPI
D3DXMatrixLookAtRH(D3DXMATRIX
*pout
, CONST D3DXVECTOR3
*peye
, CONST D3DXVECTOR3
*pat
, CONST D3DXVECTOR3
*pup
)
311 D3DXVECTOR3 right
, rightn
, up
, upn
, vec
, vec2
;
313 TRACE("(%p, %p, %p, %p)\n", pout
, peye
, pat
, pup
);
315 D3DXVec3Subtract(&vec2
, pat
, peye
);
316 D3DXVec3Normalize(&vec
, &vec2
);
317 D3DXVec3Cross(&right
, pup
, &vec
);
318 D3DXVec3Cross(&up
, &vec
, &right
);
319 D3DXVec3Normalize(&rightn
, &right
);
320 D3DXVec3Normalize(&upn
, &up
);
321 pout
->u
.m
[0][0] = -rightn
.x
;
322 pout
->u
.m
[1][0] = -rightn
.y
;
323 pout
->u
.m
[2][0] = -rightn
.z
;
324 pout
->u
.m
[3][0] = D3DXVec3Dot(&rightn
,peye
);
325 pout
->u
.m
[0][1] = upn
.x
;
326 pout
->u
.m
[1][1] = upn
.y
;
327 pout
->u
.m
[2][1] = upn
.z
;
328 pout
->u
.m
[3][1] = -D3DXVec3Dot(&upn
, peye
);
329 pout
->u
.m
[0][2] = -vec
.x
;
330 pout
->u
.m
[1][2] = -vec
.y
;
331 pout
->u
.m
[2][2] = -vec
.z
;
332 pout
->u
.m
[3][2] = D3DXVec3Dot(&vec
, peye
);
333 pout
->u
.m
[0][3] = 0.0f
;
334 pout
->u
.m
[1][3] = 0.0f
;
335 pout
->u
.m
[2][3] = 0.0f
;
336 pout
->u
.m
[3][3] = 1.0f
;
340 D3DXMATRIX
* WINAPI
D3DXMatrixMultiply(D3DXMATRIX
*pout
, CONST D3DXMATRIX
*pm1
, CONST D3DXMATRIX
*pm2
)
345 TRACE("(%p, %p, %p)\n", pout
, pm1
, pm2
);
351 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
];
359 D3DXMATRIX
* WINAPI
D3DXMatrixMultiplyTranspose(D3DXMATRIX
*pout
, CONST D3DXMATRIX
*pm1
, CONST D3DXMATRIX
*pm2
)
361 TRACE("%p, %p, %p)\n", pout
, pm1
, pm2
);
363 D3DXMatrixMultiply(pout
, pm1
, pm2
);
364 D3DXMatrixTranspose(pout
, pout
);
368 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoLH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
370 TRACE("(%p, %f, %f, %f, %f)\n", pout
, w
, h
, zn
, zf
);
372 D3DXMatrixIdentity(pout
);
373 pout
->u
.m
[0][0] = 2.0f
/ w
;
374 pout
->u
.m
[1][1] = 2.0f
/ h
;
375 pout
->u
.m
[2][2] = 1.0f
/ (zf
- zn
);
376 pout
->u
.m
[3][2] = zn
/ (zn
- zf
);
380 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoOffCenterLH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
382 TRACE("(%p, %f, %f, %f, %f, %f, %f)\n", pout
, l
, r
, b
, t
, zn
, zf
);
384 D3DXMatrixIdentity(pout
);
385 pout
->u
.m
[0][0] = 2.0f
/ (r
- l
);
386 pout
->u
.m
[1][1] = 2.0f
/ (t
- b
);
387 pout
->u
.m
[2][2] = 1.0f
/ (zf
-zn
);
388 pout
->u
.m
[3][0] = -1.0f
-2.0f
*l
/ (r
- l
);
389 pout
->u
.m
[3][1] = 1.0f
+ 2.0f
* t
/ (b
- t
);
390 pout
->u
.m
[3][2] = zn
/ (zn
-zf
);
394 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoOffCenterRH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
396 TRACE("(%p, %f, %f, %f, %f, %f, %f)\n", pout
, l
, r
, b
, t
, zn
, zf
);
398 D3DXMatrixIdentity(pout
);
399 pout
->u
.m
[0][0] = 2.0f
/ (r
- l
);
400 pout
->u
.m
[1][1] = 2.0f
/ (t
- b
);
401 pout
->u
.m
[2][2] = 1.0f
/ (zn
-zf
);
402 pout
->u
.m
[3][0] = -1.0f
-2.0f
*l
/ (r
- l
);
403 pout
->u
.m
[3][1] = 1.0f
+ 2.0f
* t
/ (b
- t
);
404 pout
->u
.m
[3][2] = zn
/ (zn
-zf
);
408 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoRH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
410 TRACE("(%p, %f, %f, %f, %f)\n", pout
, w
, h
, zn
, zf
);
412 D3DXMatrixIdentity(pout
);
413 pout
->u
.m
[0][0] = 2.0f
/ w
;
414 pout
->u
.m
[1][1] = 2.0f
/ h
;
415 pout
->u
.m
[2][2] = 1.0f
/ (zn
- zf
);
416 pout
->u
.m
[3][2] = zn
/ (zn
- zf
);
420 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveFovLH(D3DXMATRIX
*pout
, FLOAT fovy
, FLOAT aspect
, FLOAT zn
, FLOAT zf
)
422 TRACE("(%p, %f, %f, %f, %f)\n", pout
, fovy
, aspect
, zn
, zf
);
424 D3DXMatrixIdentity(pout
);
425 pout
->u
.m
[0][0] = 1.0f
/ (aspect
* tan(fovy
/2.0f
));
426 pout
->u
.m
[1][1] = 1.0f
/ tan(fovy
/2.0f
);
427 pout
->u
.m
[2][2] = zf
/ (zf
- zn
);
428 pout
->u
.m
[2][3] = 1.0f
;
429 pout
->u
.m
[3][2] = (zf
* zn
) / (zn
- zf
);
430 pout
->u
.m
[3][3] = 0.0f
;
434 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveFovRH(D3DXMATRIX
*pout
, FLOAT fovy
, FLOAT aspect
, FLOAT zn
, FLOAT zf
)
436 TRACE("(%p, %f, %f, %f, %f)\n", pout
, fovy
, aspect
, zn
, zf
);
438 D3DXMatrixIdentity(pout
);
439 pout
->u
.m
[0][0] = 1.0f
/ (aspect
* tan(fovy
/2.0f
));
440 pout
->u
.m
[1][1] = 1.0f
/ tan(fovy
/2.0f
);
441 pout
->u
.m
[2][2] = zf
/ (zn
- zf
);
442 pout
->u
.m
[2][3] = -1.0f
;
443 pout
->u
.m
[3][2] = (zf
* zn
) / (zn
- zf
);
444 pout
->u
.m
[3][3] = 0.0f
;
448 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveLH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
450 TRACE("(%p, %f, %f, %f, %f)\n", pout
, w
, h
, zn
, zf
);
452 D3DXMatrixIdentity(pout
);
453 pout
->u
.m
[0][0] = 2.0f
* zn
/ w
;
454 pout
->u
.m
[1][1] = 2.0f
* zn
/ h
;
455 pout
->u
.m
[2][2] = zf
/ (zf
- zn
);
456 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
- zf
);
457 pout
->u
.m
[2][3] = 1.0f
;
458 pout
->u
.m
[3][3] = 0.0f
;
462 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveOffCenterLH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
464 TRACE("(%p, %f, %f, %f, %f, %f, %f)\n", pout
, l
, r
, b
, t
, zn
, zf
);
466 D3DXMatrixIdentity(pout
);
467 pout
->u
.m
[0][0] = 2.0f
* zn
/ (r
- l
);
468 pout
->u
.m
[1][1] = -2.0f
* zn
/ (b
- t
);
469 pout
->u
.m
[2][0] = -1.0f
- 2.0f
* l
/ (r
- l
);
470 pout
->u
.m
[2][1] = 1.0f
+ 2.0f
* t
/ (b
- t
);
471 pout
->u
.m
[2][2] = - zf
/ (zn
- zf
);
472 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
-zf
);
473 pout
->u
.m
[2][3] = 1.0f
;
474 pout
->u
.m
[3][3] = 0.0f
;
478 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveOffCenterRH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
480 TRACE("(%p, %f, %f, %f, %f, %f, %f)\n", pout
, l
, r
, b
, t
, zn
, zf
);
482 D3DXMatrixIdentity(pout
);
483 pout
->u
.m
[0][0] = 2.0f
* zn
/ (r
- l
);
484 pout
->u
.m
[1][1] = -2.0f
* zn
/ (b
- t
);
485 pout
->u
.m
[2][0] = 1.0f
+ 2.0f
* l
/ (r
- l
);
486 pout
->u
.m
[2][1] = -1.0f
-2.0f
* t
/ (b
- t
);
487 pout
->u
.m
[2][2] = zf
/ (zn
- zf
);
488 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
-zf
);
489 pout
->u
.m
[2][3] = -1.0f
;
490 pout
->u
.m
[3][3] = 0.0f
;
494 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveRH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
496 TRACE("(%p, %f, %f, %f, %f)\n", pout
, w
, h
, zn
, zf
);
498 D3DXMatrixIdentity(pout
);
499 pout
->u
.m
[0][0] = 2.0f
* zn
/ w
;
500 pout
->u
.m
[1][1] = 2.0f
* zn
/ h
;
501 pout
->u
.m
[2][2] = zf
/ (zn
- zf
);
502 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
- zf
);
503 pout
->u
.m
[2][3] = -1.0f
;
504 pout
->u
.m
[3][3] = 0.0f
;
508 D3DXMATRIX
* WINAPI
D3DXMatrixReflect(D3DXMATRIX
*pout
, CONST D3DXPLANE
*pplane
)
512 TRACE("(%p, %p)\n", pout
, pplane
);
514 D3DXPlaneNormalize(&Nplane
, pplane
);
515 D3DXMatrixIdentity(pout
);
516 pout
->u
.m
[0][0] = 1.0f
- 2.0f
* Nplane
.a
* Nplane
.a
;
517 pout
->u
.m
[0][1] = -2.0f
* Nplane
.a
* Nplane
.b
;
518 pout
->u
.m
[0][2] = -2.0f
* Nplane
.a
* Nplane
.c
;
519 pout
->u
.m
[1][0] = -2.0f
* Nplane
.a
* Nplane
.b
;
520 pout
->u
.m
[1][1] = 1.0f
- 2.0f
* Nplane
.b
* Nplane
.b
;
521 pout
->u
.m
[1][2] = -2.0f
* Nplane
.b
* Nplane
.c
;
522 pout
->u
.m
[2][0] = -2.0f
* Nplane
.c
* Nplane
.a
;
523 pout
->u
.m
[2][1] = -2.0f
* Nplane
.c
* Nplane
.b
;
524 pout
->u
.m
[2][2] = 1.0f
- 2.0f
* Nplane
.c
* Nplane
.c
;
525 pout
->u
.m
[3][0] = -2.0f
* Nplane
.d
* Nplane
.a
;
526 pout
->u
.m
[3][1] = -2.0f
* Nplane
.d
* Nplane
.b
;
527 pout
->u
.m
[3][2] = -2.0f
* Nplane
.d
* Nplane
.c
;
531 D3DXMATRIX
* WINAPI
D3DXMatrixRotationAxis(D3DXMATRIX
*pout
, CONST D3DXVECTOR3
*pv
, FLOAT angle
)
535 TRACE("(%p, %p, %f)\n", pout
, pv
, angle
);
537 D3DXVec3Normalize(&v
,pv
);
538 D3DXMatrixIdentity(pout
);
539 pout
->u
.m
[0][0] = (1.0f
- cos(angle
)) * v
.x
* v
.x
+ cos(angle
);
540 pout
->u
.m
[1][0] = (1.0f
- cos(angle
)) * v
.x
* v
.y
- sin(angle
) * v
.z
;
541 pout
->u
.m
[2][0] = (1.0f
- cos(angle
)) * v
.x
* v
.z
+ sin(angle
) * v
.y
;
542 pout
->u
.m
[0][1] = (1.0f
- cos(angle
)) * v
.y
* v
.x
+ sin(angle
) * v
.z
;
543 pout
->u
.m
[1][1] = (1.0f
- cos(angle
)) * v
.y
* v
.y
+ cos(angle
);
544 pout
->u
.m
[2][1] = (1.0f
- cos(angle
)) * v
.y
* v
.z
- sin(angle
) * v
.x
;
545 pout
->u
.m
[0][2] = (1.0f
- cos(angle
)) * v
.z
* v
.x
- sin(angle
) * v
.y
;
546 pout
->u
.m
[1][2] = (1.0f
- cos(angle
)) * v
.z
* v
.y
+ sin(angle
) * v
.x
;
547 pout
->u
.m
[2][2] = (1.0f
- cos(angle
)) * v
.z
* v
.z
+ cos(angle
);
551 D3DXMATRIX
* WINAPI
D3DXMatrixRotationQuaternion(D3DXMATRIX
*pout
, CONST D3DXQUATERNION
*pq
)
553 TRACE("(%p, %p)\n", pout
, pq
);
555 D3DXMatrixIdentity(pout
);
556 pout
->u
.m
[0][0] = 1.0f
- 2.0f
* (pq
->y
* pq
->y
+ pq
->z
* pq
->z
);
557 pout
->u
.m
[0][1] = 2.0f
* (pq
->x
*pq
->y
+ pq
->z
* pq
->w
);
558 pout
->u
.m
[0][2] = 2.0f
* (pq
->x
* pq
->z
- pq
->y
* pq
->w
);
559 pout
->u
.m
[1][0] = 2.0f
* (pq
->x
* pq
->y
- pq
->z
* pq
->w
);
560 pout
->u
.m
[1][1] = 1.0f
- 2.0f
* (pq
->x
* pq
->x
+ pq
->z
* pq
->z
);
561 pout
->u
.m
[1][2] = 2.0f
* (pq
->y
*pq
->z
+ pq
->x
*pq
->w
);
562 pout
->u
.m
[2][0] = 2.0f
* (pq
->x
* pq
->z
+ pq
->y
* pq
->w
);
563 pout
->u
.m
[2][1] = 2.0f
* (pq
->y
*pq
->z
- pq
->x
*pq
->w
);
564 pout
->u
.m
[2][2] = 1.0f
- 2.0f
* (pq
->x
* pq
->x
+ pq
->y
* pq
->y
);
568 D3DXMATRIX
* WINAPI
D3DXMatrixRotationX(D3DXMATRIX
*pout
, FLOAT angle
)
570 TRACE("(%p, %f)\n", pout
, angle
);
572 D3DXMatrixIdentity(pout
);
573 pout
->u
.m
[1][1] = cos(angle
);
574 pout
->u
.m
[2][2] = cos(angle
);
575 pout
->u
.m
[1][2] = sin(angle
);
576 pout
->u
.m
[2][1] = -sin(angle
);
580 D3DXMATRIX
* WINAPI
D3DXMatrixRotationY(D3DXMATRIX
*pout
, FLOAT angle
)
582 TRACE("(%p, %f)\n", pout
, angle
);
584 D3DXMatrixIdentity(pout
);
585 pout
->u
.m
[0][0] = cos(angle
);
586 pout
->u
.m
[2][2] = cos(angle
);
587 pout
->u
.m
[0][2] = -sin(angle
);
588 pout
->u
.m
[2][0] = sin(angle
);
592 D3DXMATRIX
* WINAPI
D3DXMatrixRotationYawPitchRoll(D3DXMATRIX
*pout
, FLOAT yaw
, FLOAT pitch
, FLOAT roll
)
596 TRACE("(%p, %f, %f, %f)\n", pout
, yaw
, pitch
, roll
);
598 D3DXMatrixIdentity(pout
);
599 D3DXMatrixRotationZ(&m
, roll
);
600 D3DXMatrixMultiply(pout
, pout
, &m
);
601 D3DXMatrixRotationX(&m
, pitch
);
602 D3DXMatrixMultiply(pout
, pout
, &m
);
603 D3DXMatrixRotationY(&m
, yaw
);
604 D3DXMatrixMultiply(pout
, pout
, &m
);
608 D3DXMATRIX
* WINAPI
D3DXMatrixRotationZ(D3DXMATRIX
*pout
, FLOAT angle
)
610 TRACE("(%p, %f)\n", pout
, angle
);
612 D3DXMatrixIdentity(pout
);
613 pout
->u
.m
[0][0] = cos(angle
);
614 pout
->u
.m
[1][1] = cos(angle
);
615 pout
->u
.m
[0][1] = sin(angle
);
616 pout
->u
.m
[1][0] = -sin(angle
);
620 D3DXMATRIX
* WINAPI
D3DXMatrixScaling(D3DXMATRIX
*pout
, FLOAT sx
, FLOAT sy
, FLOAT sz
)
622 TRACE("(%p, %f, %f, %f)\n", pout
, sx
, sy
, sz
);
624 D3DXMatrixIdentity(pout
);
625 pout
->u
.m
[0][0] = sx
;
626 pout
->u
.m
[1][1] = sy
;
627 pout
->u
.m
[2][2] = sz
;
631 D3DXMATRIX
* WINAPI
D3DXMatrixShadow(D3DXMATRIX
*pout
, CONST D3DXVECTOR4
*plight
, CONST D3DXPLANE
*pplane
)
636 TRACE("(%p, %p, %p)\n", pout
, plight
, pplane
);
638 D3DXPlaneNormalize(&Nplane
, pplane
);
639 dot
= D3DXPlaneDot(&Nplane
, plight
);
640 pout
->u
.m
[0][0] = dot
- Nplane
.a
* plight
->x
;
641 pout
->u
.m
[0][1] = -Nplane
.a
* plight
->y
;
642 pout
->u
.m
[0][2] = -Nplane
.a
* plight
->z
;
643 pout
->u
.m
[0][3] = -Nplane
.a
* plight
->w
;
644 pout
->u
.m
[1][0] = -Nplane
.b
* plight
->x
;
645 pout
->u
.m
[1][1] = dot
- Nplane
.b
* plight
->y
;
646 pout
->u
.m
[1][2] = -Nplane
.b
* plight
->z
;
647 pout
->u
.m
[1][3] = -Nplane
.b
* plight
->w
;
648 pout
->u
.m
[2][0] = -Nplane
.c
* plight
->x
;
649 pout
->u
.m
[2][1] = -Nplane
.c
* plight
->y
;
650 pout
->u
.m
[2][2] = dot
- Nplane
.c
* plight
->z
;
651 pout
->u
.m
[2][3] = -Nplane
.c
* plight
->w
;
652 pout
->u
.m
[3][0] = -Nplane
.d
* plight
->x
;
653 pout
->u
.m
[3][1] = -Nplane
.d
* plight
->y
;
654 pout
->u
.m
[3][2] = -Nplane
.d
* plight
->z
;
655 pout
->u
.m
[3][3] = dot
- Nplane
.d
* plight
->w
;
659 D3DXMATRIX
* WINAPI
D3DXMatrixTransformation(D3DXMATRIX
*pout
, CONST D3DXVECTOR3
*pscalingcenter
, CONST D3DXQUATERNION
*pscalingrotation
, CONST D3DXVECTOR3
*pscaling
, CONST D3DXVECTOR3
*protationcenter
, CONST D3DXQUATERNION
*protation
, CONST D3DXVECTOR3
*ptranslation
)
661 D3DXMATRIX m1
, m2
, m3
, m4
, m5
, m6
, m7
;
665 TRACE("(%p, %p, %p, %p, %p, %p, %p)\n", pout
, pscalingcenter
, pscalingrotation
, pscaling
, protationcenter
, protation
, ptranslation
);
667 if ( !pscalingcenter
)
675 psc
.x
= pscalingcenter
->x
;
676 psc
.y
= pscalingcenter
->y
;
677 psc
.z
= pscalingcenter
->z
;
680 if ( !protationcenter
)
688 prc
.x
= protationcenter
->x
;
689 prc
.y
= protationcenter
->y
;
690 prc
.z
= protationcenter
->z
;
701 pt
.x
= ptranslation
->x
;
702 pt
.y
= ptranslation
->y
;
703 pt
.z
= ptranslation
->z
;
706 D3DXMatrixTranslation(&m1
, -psc
.x
, -psc
.y
, -psc
.z
);
708 if ( !pscalingrotation
)
710 D3DXMatrixIdentity(&m2
);
711 D3DXMatrixIdentity(&m4
);
715 D3DXMatrixRotationQuaternion(&m4
, pscalingrotation
);
716 D3DXMatrixInverse(&m2
, NULL
, &m4
);
719 if ( !pscaling
) D3DXMatrixIdentity(&m3
);
720 else D3DXMatrixScaling(&m3
, pscaling
->x
, pscaling
->y
, pscaling
->z
);
722 if ( !protation
) D3DXMatrixIdentity(&m6
);
723 else D3DXMatrixRotationQuaternion(&m6
, protation
);
725 D3DXMatrixTranslation(&m5
, psc
.x
- prc
.x
, psc
.y
- prc
.y
, psc
.z
- prc
.z
);
726 D3DXMatrixTranslation(&m7
, prc
.x
+ pt
.x
, prc
.y
+ pt
.y
, prc
.z
+ pt
.z
);
727 D3DXMatrixMultiply(&m1
, &m1
, &m2
);
728 D3DXMatrixMultiply(&m1
, &m1
, &m3
);
729 D3DXMatrixMultiply(&m1
, &m1
, &m4
);
730 D3DXMatrixMultiply(&m1
, &m1
, &m5
);
731 D3DXMatrixMultiply(&m1
, &m1
, &m6
);
732 D3DXMatrixMultiply(pout
, &m1
, &m7
);
736 D3DXMATRIX
* WINAPI
D3DXMatrixTransformation2D(D3DXMATRIX
*pout
, CONST D3DXVECTOR2
*pscalingcenter
, FLOAT scalingrotation
, CONST D3DXVECTOR2
*pscaling
, CONST D3DXVECTOR2
*protationcenter
, FLOAT rotation
, CONST D3DXVECTOR2
*ptranslation
)
738 D3DXQUATERNION rot
, sca_rot
;
739 D3DXVECTOR3 rot_center
, sca
, sca_center
, trans
;
741 TRACE("(%p, %p, %f, %p, %p, %f, %p)\n", pout
, pscalingcenter
, scalingrotation
, pscaling
, protationcenter
, rotation
, ptranslation
);
743 if ( pscalingcenter
)
745 sca_center
.x
=pscalingcenter
->x
;
746 sca_center
.y
=pscalingcenter
->y
;
769 if ( protationcenter
)
771 rot_center
.x
=protationcenter
->x
;
772 rot_center
.y
=protationcenter
->y
;
784 trans
.x
=ptranslation
->x
;
785 trans
.y
=ptranslation
->y
;
795 rot
.w
=cos(rotation
/2.0f
);
798 rot
.z
=sin(rotation
/2.0f
);
800 sca_rot
.w
=cos(scalingrotation
/2.0f
);
803 sca_rot
.z
=sin(scalingrotation
/2.0f
);
805 D3DXMatrixTransformation(pout
, &sca_center
, &sca_rot
, &sca
, &rot_center
, &rot
, &trans
);
810 D3DXMATRIX
* WINAPI
D3DXMatrixTranslation(D3DXMATRIX
*pout
, FLOAT x
, FLOAT y
, FLOAT z
)
812 TRACE("(%p, %f, %f, %f)\n", pout
, x
, y
, z
);
814 D3DXMatrixIdentity(pout
);
821 D3DXMATRIX
* WINAPI
D3DXMatrixTranspose(D3DXMATRIX
*pout
, CONST D3DXMATRIX
*pm
)
823 CONST D3DXMATRIX m
= *pm
;
826 TRACE("(%p, %p)\n", pout
, pm
);
829 for (j
=0; j
<4; j
++) pout
->u
.m
[i
][j
] = m
.u
.m
[j
][i
];
834 /*_________________D3DXMatrixStack____________________*/
836 static const unsigned int INITIAL_STACK_SIZE
= 32;
838 HRESULT WINAPI
D3DXCreateMatrixStack(DWORD flags
, LPD3DXMATRIXSTACK
* ppstack
)
840 ID3DXMatrixStackImpl
* object
;
842 TRACE("flags %#x, ppstack %p\n", flags
, ppstack
);
844 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ID3DXMatrixStackImpl
));
845 if ( object
== NULL
)
848 return E_OUTOFMEMORY
;
850 object
->ID3DXMatrixStack_iface
.lpVtbl
= &ID3DXMatrixStack_Vtbl
;
853 object
->stack
= HeapAlloc(GetProcessHeap(), 0, INITIAL_STACK_SIZE
* sizeof(D3DXMATRIX
));
856 HeapFree(GetProcessHeap(), 0, object
);
858 return E_OUTOFMEMORY
;
862 object
->stack_size
= INITIAL_STACK_SIZE
;
863 D3DXMatrixIdentity(&object
->stack
[0]);
865 TRACE("Created matrix stack %p\n", object
);
867 *ppstack
= &object
->ID3DXMatrixStack_iface
;
871 static inline ID3DXMatrixStackImpl
*impl_from_ID3DXMatrixStack(ID3DXMatrixStack
*iface
)
873 return CONTAINING_RECORD(iface
, ID3DXMatrixStackImpl
, ID3DXMatrixStack_iface
);
876 static HRESULT WINAPI
ID3DXMatrixStackImpl_QueryInterface(ID3DXMatrixStack
*iface
, REFIID riid
, void **out
)
878 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
880 if (IsEqualGUID(riid
, &IID_ID3DXMatrixStack
)
881 || IsEqualGUID(riid
, &IID_IUnknown
))
883 ID3DXMatrixStack_AddRef(iface
);
888 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
891 return E_NOINTERFACE
;
894 static ULONG WINAPI
ID3DXMatrixStackImpl_AddRef(ID3DXMatrixStack
*iface
)
896 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
897 ULONG ref
= InterlockedIncrement(&This
->ref
);
898 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
902 static ULONG WINAPI
ID3DXMatrixStackImpl_Release(ID3DXMatrixStack
* iface
)
904 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
905 ULONG ref
= InterlockedDecrement(&This
->ref
);
908 HeapFree(GetProcessHeap(), 0, This
->stack
);
909 HeapFree(GetProcessHeap(), 0, This
);
911 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
915 static D3DXMATRIX
* WINAPI
ID3DXMatrixStackImpl_GetTop(ID3DXMatrixStack
*iface
)
917 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
919 TRACE("iface %p\n", iface
);
921 return &This
->stack
[This
->current
];
924 static HRESULT WINAPI
ID3DXMatrixStackImpl_LoadIdentity(ID3DXMatrixStack
*iface
)
926 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
928 TRACE("iface %p\n", iface
);
930 D3DXMatrixIdentity(&This
->stack
[This
->current
]);
935 static HRESULT WINAPI
ID3DXMatrixStackImpl_LoadMatrix(ID3DXMatrixStack
*iface
, CONST D3DXMATRIX
*pm
)
937 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
939 TRACE("iface %p\n", iface
);
941 This
->stack
[This
->current
] = *pm
;
946 static HRESULT WINAPI
ID3DXMatrixStackImpl_MultMatrix(ID3DXMatrixStack
*iface
, CONST D3DXMATRIX
*pm
)
948 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
950 TRACE("iface %p\n", iface
);
952 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], pm
);
957 static HRESULT WINAPI
ID3DXMatrixStackImpl_MultMatrixLocal(ID3DXMatrixStack
*iface
, CONST D3DXMATRIX
*pm
)
959 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
961 TRACE("iface %p\n", iface
);
963 D3DXMatrixMultiply(&This
->stack
[This
->current
], pm
, &This
->stack
[This
->current
]);
968 static HRESULT WINAPI
ID3DXMatrixStackImpl_Pop(ID3DXMatrixStack
*iface
)
970 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
972 TRACE("iface %p\n", iface
);
974 /* Popping the last element on the stack returns D3D_OK, but does nothing. */
975 if (!This
->current
) return D3D_OK
;
977 if (This
->current
<= This
->stack_size
/ 4 && This
->stack_size
>= INITIAL_STACK_SIZE
* 2)
979 unsigned int new_size
;
980 D3DXMATRIX
*new_stack
;
982 new_size
= This
->stack_size
/ 2;
983 new_stack
= HeapReAlloc(GetProcessHeap(), 0, This
->stack
, new_size
* sizeof(D3DXMATRIX
));
986 This
->stack_size
= new_size
;
987 This
->stack
= new_stack
;
996 static HRESULT WINAPI
ID3DXMatrixStackImpl_Push(ID3DXMatrixStack
*iface
)
998 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1000 TRACE("iface %p\n", iface
);
1002 if (This
->current
== This
->stack_size
- 1)
1004 unsigned int new_size
;
1005 D3DXMATRIX
*new_stack
;
1007 if (This
->stack_size
> UINT_MAX
/ 2) return E_OUTOFMEMORY
;
1009 new_size
= This
->stack_size
* 2;
1010 new_stack
= HeapReAlloc(GetProcessHeap(), 0, This
->stack
, new_size
* sizeof(D3DXMATRIX
));
1011 if (!new_stack
) return E_OUTOFMEMORY
;
1013 This
->stack_size
= new_size
;
1014 This
->stack
= new_stack
;
1018 This
->stack
[This
->current
] = This
->stack
[This
->current
- 1];
1023 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateAxis(ID3DXMatrixStack
*iface
, CONST D3DXVECTOR3
*pv
, FLOAT angle
)
1026 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1028 TRACE("iface %p\n", iface
);
1030 D3DXMatrixRotationAxis(&temp
, pv
, angle
);
1031 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
1036 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateAxisLocal(ID3DXMatrixStack
*iface
, CONST D3DXVECTOR3
*pv
, FLOAT angle
)
1039 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1041 TRACE("iface %p\n", iface
);
1043 D3DXMatrixRotationAxis(&temp
, pv
, angle
);
1044 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
, &This
->stack
[This
->current
]);
1049 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateYawPitchRoll(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1052 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1054 TRACE("iface %p\n", iface
);
1056 D3DXMatrixRotationYawPitchRoll(&temp
, x
, y
, z
);
1057 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
1062 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateYawPitchRollLocal(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1065 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1067 TRACE("iface %p\n", iface
);
1069 D3DXMatrixRotationYawPitchRoll(&temp
, x
, y
, z
);
1070 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
, &This
->stack
[This
->current
]);
1075 static HRESULT WINAPI
ID3DXMatrixStackImpl_Scale(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1078 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1080 TRACE("iface %p\n", iface
);
1082 D3DXMatrixScaling(&temp
, x
, y
, z
);
1083 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
1088 static HRESULT WINAPI
ID3DXMatrixStackImpl_ScaleLocal(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1091 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1093 TRACE("iface %p\n", iface
);
1095 D3DXMatrixScaling(&temp
, x
, y
, z
);
1096 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
, &This
->stack
[This
->current
]);
1101 static HRESULT WINAPI
ID3DXMatrixStackImpl_Translate(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1104 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1106 TRACE("iface %p\n", iface
);
1108 D3DXMatrixTranslation(&temp
, x
, y
, z
);
1109 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
1114 static HRESULT WINAPI
ID3DXMatrixStackImpl_TranslateLocal(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
1117 ID3DXMatrixStackImpl
*This
= impl_from_ID3DXMatrixStack(iface
);
1119 TRACE("iface %p\n", iface
);
1121 D3DXMatrixTranslation(&temp
, x
, y
, z
);
1122 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
,&This
->stack
[This
->current
]);
1127 static const ID3DXMatrixStackVtbl ID3DXMatrixStack_Vtbl
=
1129 ID3DXMatrixStackImpl_QueryInterface
,
1130 ID3DXMatrixStackImpl_AddRef
,
1131 ID3DXMatrixStackImpl_Release
,
1132 ID3DXMatrixStackImpl_Pop
,
1133 ID3DXMatrixStackImpl_Push
,
1134 ID3DXMatrixStackImpl_LoadIdentity
,
1135 ID3DXMatrixStackImpl_LoadMatrix
,
1136 ID3DXMatrixStackImpl_MultMatrix
,
1137 ID3DXMatrixStackImpl_MultMatrixLocal
,
1138 ID3DXMatrixStackImpl_RotateAxis
,
1139 ID3DXMatrixStackImpl_RotateAxisLocal
,
1140 ID3DXMatrixStackImpl_RotateYawPitchRoll
,
1141 ID3DXMatrixStackImpl_RotateYawPitchRollLocal
,
1142 ID3DXMatrixStackImpl_Scale
,
1143 ID3DXMatrixStackImpl_ScaleLocal
,
1144 ID3DXMatrixStackImpl_Translate
,
1145 ID3DXMatrixStackImpl_TranslateLocal
,
1146 ID3DXMatrixStackImpl_GetTop
1149 /*_________________D3DXPLANE________________*/
1151 D3DXPLANE
* WINAPI
D3DXPlaneFromPointNormal(D3DXPLANE
*pout
, CONST D3DXVECTOR3
*pvpoint
, CONST D3DXVECTOR3
*pvnormal
)
1153 TRACE("(%p, %p, %p)\n", pout
, pvpoint
, pvnormal
);
1155 pout
->a
= pvnormal
->x
;
1156 pout
->b
= pvnormal
->y
;
1157 pout
->c
= pvnormal
->z
;
1158 pout
->d
= -D3DXVec3Dot(pvpoint
, pvnormal
);
1162 D3DXPLANE
* WINAPI
D3DXPlaneFromPoints(D3DXPLANE
*pout
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pv3
)
1164 D3DXVECTOR3 edge1
, edge2
, normal
, Nnormal
;
1166 TRACE("(%p, %p, %p, %p)\n", pout
, pv1
, pv2
, pv3
);
1168 edge1
.x
= 0.0f
; edge1
.y
= 0.0f
; edge1
.z
= 0.0f
;
1169 edge2
.x
= 0.0f
; edge2
.y
= 0.0f
; edge2
.z
= 0.0f
;
1170 D3DXVec3Subtract(&edge1
, pv2
, pv1
);
1171 D3DXVec3Subtract(&edge2
, pv3
, pv1
);
1172 D3DXVec3Cross(&normal
, &edge1
, &edge2
);
1173 D3DXVec3Normalize(&Nnormal
, &normal
);
1174 D3DXPlaneFromPointNormal(pout
, pv1
, &Nnormal
);
1178 D3DXVECTOR3
* WINAPI
D3DXPlaneIntersectLine(D3DXVECTOR3
*pout
, CONST D3DXPLANE
*pp
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
)
1180 D3DXVECTOR3 direction
, normal
;
1183 TRACE("(%p, %p, %p, %p)\n", pout
, pp
, pv1
, pv2
);
1188 direction
.x
= pv2
->x
- pv1
->x
;
1189 direction
.y
= pv2
->y
- pv1
->y
;
1190 direction
.z
= pv2
->z
- pv1
->z
;
1191 dot
= D3DXVec3Dot(&normal
, &direction
);
1192 if ( !dot
) return NULL
;
1193 temp
= ( pp
->d
+ D3DXVec3Dot(&normal
, pv1
) ) / dot
;
1194 pout
->x
= pv1
->x
- temp
* direction
.x
;
1195 pout
->y
= pv1
->y
- temp
* direction
.y
;
1196 pout
->z
= pv1
->z
- temp
* direction
.z
;
1200 D3DXPLANE
* WINAPI
D3DXPlaneNormalize(D3DXPLANE
*pout
, CONST D3DXPLANE
*pp
)
1205 TRACE("(%p, %p)\n", pout
, pp
);
1207 norm
= sqrt(pp
->a
* pp
->a
+ pp
->b
* pp
->b
+ pp
->c
* pp
->c
);
1210 out
.a
= pp
->a
/ norm
;
1211 out
.b
= pp
->b
/ norm
;
1212 out
.c
= pp
->c
/ norm
;
1213 out
.d
= pp
->d
/ norm
;
1226 D3DXPLANE
* WINAPI
D3DXPlaneTransform(D3DXPLANE
*pout
, CONST D3DXPLANE
*pplane
, CONST D3DXMATRIX
*pm
)
1228 CONST D3DXPLANE plane
= *pplane
;
1230 TRACE("(%p, %p, %p)\n", pout
, pplane
, pm
);
1232 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
;
1233 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
;
1234 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
;
1235 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
;
1239 D3DXPLANE
* WINAPI
D3DXPlaneTransformArray(D3DXPLANE
* out
, UINT outstride
, CONST D3DXPLANE
* in
, UINT instride
, CONST D3DXMATRIX
* matrix
, UINT elements
)
1243 TRACE("(%p, %u, %p, %u, %p, %u)\n", out
, outstride
, in
, instride
, matrix
, elements
);
1245 for (i
= 0; i
< elements
; ++i
) {
1247 (D3DXPLANE
*)((char*)out
+ outstride
* i
),
1248 (CONST D3DXPLANE
*)((const char*)in
+ instride
* i
),
1254 /*_________________D3DXQUATERNION________________*/
1256 D3DXQUATERNION
* WINAPI
D3DXQuaternionBaryCentric(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq1
, CONST D3DXQUATERNION
*pq2
, CONST D3DXQUATERNION
*pq3
, FLOAT f
, FLOAT g
)
1258 D3DXQUATERNION temp1
, temp2
;
1260 TRACE("(%p, %p, %p, %p, %f, %f)\n", pout
, pq1
, pq2
, pq3
, f
, g
);
1262 D3DXQuaternionSlerp(pout
, D3DXQuaternionSlerp(&temp1
, pq1
, pq2
, f
+ g
), D3DXQuaternionSlerp(&temp2
, pq1
, pq3
, f
+g
), g
/ (f
+ g
));
1266 D3DXQUATERNION
* WINAPI
D3DXQuaternionExp(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq
)
1270 TRACE("(%p, %p)\n", pout
, pq
);
1272 norm
= sqrt(pq
->x
* pq
->x
+ pq
->y
* pq
->y
+ pq
->z
* pq
->z
);
1275 pout
->x
= sin(norm
) * pq
->x
/ norm
;
1276 pout
->y
= sin(norm
) * pq
->y
/ norm
;
1277 pout
->z
= sin(norm
) * pq
->z
/ norm
;
1278 pout
->w
= cos(norm
);
1290 D3DXQUATERNION
* WINAPI
D3DXQuaternionInverse(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq
)
1295 TRACE("(%p, %p)\n", pout
, pq
);
1297 norm
= D3DXQuaternionLengthSq(pq
);
1299 out
.x
= -pq
->x
/ norm
;
1300 out
.y
= -pq
->y
/ norm
;
1301 out
.z
= -pq
->z
/ norm
;
1302 out
.w
= pq
->w
/ norm
;
1308 D3DXQUATERNION
* WINAPI
D3DXQuaternionLn(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq
)
1312 TRACE("(%p, %p)\n", pout
, pq
);
1314 if ( (pq
->w
>= 1.0f
) || (pq
->w
== -1.0f
) )
1317 t
= acos( pq
->w
) / sqrt( 1.0f
- pq
->w
* pq
->w
);
1319 pout
->x
= t
* pq
->x
;
1320 pout
->y
= t
* pq
->y
;
1321 pout
->z
= t
* pq
->z
;
1327 D3DXQUATERNION
* WINAPI
D3DXQuaternionMultiply(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq1
, CONST D3DXQUATERNION
*pq2
)
1331 TRACE("(%p, %p, %p)\n", pout
, pq1
, pq2
);
1333 out
.x
= pq2
->w
* pq1
->x
+ pq2
->x
* pq1
->w
+ pq2
->y
* pq1
->z
- pq2
->z
* pq1
->y
;
1334 out
.y
= pq2
->w
* pq1
->y
- pq2
->x
* pq1
->z
+ pq2
->y
* pq1
->w
+ pq2
->z
* pq1
->x
;
1335 out
.z
= pq2
->w
* pq1
->z
+ pq2
->x
* pq1
->y
- pq2
->y
* pq1
->x
+ pq2
->z
* pq1
->w
;
1336 out
.w
= pq2
->w
* pq1
->w
- pq2
->x
* pq1
->x
- pq2
->y
* pq1
->y
- pq2
->z
* pq1
->z
;
1341 D3DXQUATERNION
* WINAPI
D3DXQuaternionNormalize(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq
)
1346 TRACE("(%p, %p)\n", pout
, pq
);
1348 norm
= D3DXQuaternionLength(pq
);
1350 out
.x
= pq
->x
/ norm
;
1351 out
.y
= pq
->y
/ norm
;
1352 out
.z
= pq
->z
/ norm
;
1353 out
.w
= pq
->w
/ norm
;
1360 D3DXQUATERNION
* WINAPI
D3DXQuaternionRotationAxis(D3DXQUATERNION
*pout
, CONST D3DXVECTOR3
*pv
, FLOAT angle
)
1364 TRACE("(%p, %p, %f)\n", pout
, pv
, angle
);
1366 D3DXVec3Normalize(&temp
, pv
);
1367 pout
->x
= sin( angle
/ 2.0f
) * temp
.x
;
1368 pout
->y
= sin( angle
/ 2.0f
) * temp
.y
;
1369 pout
->z
= sin( angle
/ 2.0f
) * temp
.z
;
1370 pout
->w
= cos( angle
/ 2.0f
);
1374 D3DXQUATERNION
* WINAPI
D3DXQuaternionRotationMatrix(D3DXQUATERNION
*pout
, CONST D3DXMATRIX
*pm
)
1377 FLOAT maxdiag
, S
, trace
;
1379 TRACE("(%p, %p)\n", pout
, pm
);
1381 trace
= pm
->u
.m
[0][0] + pm
->u
.m
[1][1] + pm
->u
.m
[2][2] + 1.0f
;
1384 pout
->x
= ( pm
->u
.m
[1][2] - pm
->u
.m
[2][1] ) / ( 2.0f
* sqrt(trace
) );
1385 pout
->y
= ( pm
->u
.m
[2][0] - pm
->u
.m
[0][2] ) / ( 2.0f
* sqrt(trace
) );
1386 pout
->z
= ( pm
->u
.m
[0][1] - pm
->u
.m
[1][0] ) / ( 2.0f
* sqrt(trace
) );
1387 pout
->w
= sqrt(trace
) / 2.0f
;
1391 maxdiag
= pm
->u
.m
[0][0];
1394 if ( pm
->u
.m
[i
][i
] > maxdiag
)
1397 maxdiag
= pm
->u
.m
[i
][i
];
1403 S
= 2.0f
* sqrt(1.0f
+ pm
->u
.m
[0][0] - pm
->u
.m
[1][1] - pm
->u
.m
[2][2]);
1404 pout
->x
= 0.25f
* S
;
1405 pout
->y
= ( pm
->u
.m
[0][1] + pm
->u
.m
[1][0] ) / S
;
1406 pout
->z
= ( pm
->u
.m
[0][2] + pm
->u
.m
[2][0] ) / S
;
1407 pout
->w
= ( pm
->u
.m
[1][2] - pm
->u
.m
[2][1] ) / S
;
1410 S
= 2.0f
* sqrt(1.0f
+ pm
->u
.m
[1][1] - pm
->u
.m
[0][0] - pm
->u
.m
[2][2]);
1411 pout
->x
= ( pm
->u
.m
[0][1] + pm
->u
.m
[1][0] ) / S
;
1412 pout
->y
= 0.25f
* S
;
1413 pout
->z
= ( pm
->u
.m
[1][2] + pm
->u
.m
[2][1] ) / S
;
1414 pout
->w
= ( pm
->u
.m
[2][0] - pm
->u
.m
[0][2] ) / S
;
1417 S
= 2.0f
* sqrt(1.0f
+ pm
->u
.m
[2][2] - pm
->u
.m
[0][0] - pm
->u
.m
[1][1]);
1418 pout
->x
= ( pm
->u
.m
[0][2] + pm
->u
.m
[2][0] ) / S
;
1419 pout
->y
= ( pm
->u
.m
[1][2] + pm
->u
.m
[2][1] ) / S
;
1420 pout
->z
= 0.25f
* S
;
1421 pout
->w
= ( pm
->u
.m
[0][1] - pm
->u
.m
[1][0] ) / S
;
1427 D3DXQUATERNION
* WINAPI
D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION
*pout
, FLOAT yaw
, FLOAT pitch
, FLOAT roll
)
1429 TRACE("(%p, %f, %f, %f)\n", pout
, yaw
, pitch
, roll
);
1431 pout
->x
= sin( yaw
/ 2.0f
) * cos(pitch
/ 2.0f
) * sin(roll
/ 2.0f
) + cos(yaw
/ 2.0f
) * sin(pitch
/ 2.0f
) * cos(roll
/ 2.0f
);
1432 pout
->y
= sin( yaw
/ 2.0f
) * cos(pitch
/ 2.0f
) * cos(roll
/ 2.0f
) - cos(yaw
/ 2.0f
) * sin(pitch
/ 2.0f
) * sin(roll
/ 2.0f
);
1433 pout
->z
= cos(yaw
/ 2.0f
) * cos(pitch
/ 2.0f
) * sin(roll
/ 2.0f
) - sin( yaw
/ 2.0f
) * sin(pitch
/ 2.0f
) * cos(roll
/ 2.0f
);
1434 pout
->w
= cos( yaw
/ 2.0f
) * cos(pitch
/ 2.0f
) * cos(roll
/ 2.0f
) + sin(yaw
/ 2.0f
) * sin(pitch
/ 2.0f
) * sin(roll
/ 2.0f
);
1438 D3DXQUATERNION
* WINAPI
D3DXQuaternionSlerp(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq1
, CONST D3DXQUATERNION
*pq2
, FLOAT t
)
1440 FLOAT dot
, epsilon
, temp
, theta
, u
;
1442 TRACE("(%p, %p, %p, %f)\n", pout
, pq1
, pq2
, t
);
1447 dot
= D3DXQuaternionDot(pq1
, pq2
);
1453 if( 1.0f
- dot
> 0.001f
)
1456 temp
= sin(theta
* temp
) / sin(theta
);
1457 u
= sin(theta
* u
) / sin(theta
);
1459 pout
->x
= temp
* pq1
->x
+ epsilon
* u
* pq2
->x
;
1460 pout
->y
= temp
* pq1
->y
+ epsilon
* u
* pq2
->y
;
1461 pout
->z
= temp
* pq1
->z
+ epsilon
* u
* pq2
->z
;
1462 pout
->w
= temp
* pq1
->w
+ epsilon
* u
* pq2
->w
;
1466 D3DXQUATERNION
* WINAPI
D3DXQuaternionSquad(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq1
, CONST D3DXQUATERNION
*pq2
, CONST D3DXQUATERNION
*pq3
, CONST D3DXQUATERNION
*pq4
, FLOAT t
)
1468 D3DXQUATERNION temp1
, temp2
;
1470 TRACE("(%p, %p, %p, %p, %p, %f)\n", pout
, pq1
, pq2
, pq3
, pq4
, t
);
1472 D3DXQuaternionSlerp(pout
, D3DXQuaternionSlerp(&temp1
, pq1
, pq4
, t
), D3DXQuaternionSlerp(&temp2
, pq2
, pq3
, t
), 2.0f
* t
* (1.0f
- t
));
1476 static D3DXQUATERNION
add_diff(CONST D3DXQUATERNION
*q1
, CONST D3DXQUATERNION
*q2
, CONST FLOAT add
)
1478 D3DXQUATERNION temp
;
1480 temp
.x
= q1
->x
+ add
* q2
->x
;
1481 temp
.y
= q1
->y
+ add
* q2
->y
;
1482 temp
.z
= q1
->z
+ add
* q2
->z
;
1483 temp
.w
= q1
->w
+ add
* q2
->w
;
1488 void WINAPI
D3DXQuaternionSquadSetup(D3DXQUATERNION
*paout
, D3DXQUATERNION
*pbout
, D3DXQUATERNION
*pcout
, CONST D3DXQUATERNION
*pq0
, CONST D3DXQUATERNION
*pq1
, CONST D3DXQUATERNION
*pq2
, CONST D3DXQUATERNION
*pq3
)
1490 D3DXQUATERNION q
, temp1
, temp2
, temp3
, zero
;
1492 TRACE("(%p, %p, %p, %p, %p, %p, %p)\n", paout
, pbout
, pcout
, pq0
, pq1
, pq2
, pq3
);
1499 if ( D3DXQuaternionDot(pq0
, pq1
) < 0.0f
)
1500 temp2
= add_diff(&zero
, pq0
, -1.0f
);
1504 if ( D3DXQuaternionDot(pq1
, pq2
) < 0.0f
)
1505 *pcout
= add_diff(&zero
, pq2
, -1.0f
);
1509 if ( D3DXQuaternionDot(pcout
, pq3
) < 0.0f
)
1510 temp3
= add_diff(&zero
, pq3
, -1.0f
);
1514 D3DXQuaternionInverse(&temp1
, pq1
);
1515 D3DXQuaternionMultiply(&temp2
, &temp1
, &temp2
);
1516 D3DXQuaternionLn(&temp2
, &temp2
);
1517 D3DXQuaternionMultiply(&q
, &temp1
, pcout
);
1518 D3DXQuaternionLn(&q
, &q
);
1519 temp1
= add_diff(&temp2
, &q
, 1.0f
);
1524 D3DXQuaternionExp(&temp1
, &temp1
);
1525 D3DXQuaternionMultiply(paout
, pq1
, &temp1
);
1527 D3DXQuaternionInverse(&temp1
, pcout
);
1528 D3DXQuaternionMultiply(&temp2
, &temp1
, pq1
);
1529 D3DXQuaternionLn(&temp2
, &temp2
);
1530 D3DXQuaternionMultiply(&q
, &temp1
, &temp3
);
1531 D3DXQuaternionLn(&q
, &q
);
1532 temp1
= add_diff(&temp2
, &q
, 1.0f
);
1537 D3DXQuaternionExp(&temp1
, &temp1
);
1538 D3DXQuaternionMultiply(pbout
, pcout
, &temp1
);
1543 void WINAPI
D3DXQuaternionToAxisAngle(CONST D3DXQUATERNION
*pq
, D3DXVECTOR3
*paxis
, FLOAT
*pangle
)
1545 TRACE("(%p, %p, %p)\n", pq
, paxis
, pangle
);
1550 *pangle
= 2.0f
* acos(pq
->w
);
1553 /*_________________D3DXVec2_____________________*/
1555 D3DXVECTOR2
* WINAPI
D3DXVec2BaryCentric(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv1
, CONST D3DXVECTOR2
*pv2
, CONST D3DXVECTOR2
*pv3
, FLOAT f
, FLOAT g
)
1557 TRACE("(%p, %p, %p, %p, %f, %f)\n", pout
, pv1
, pv2
, pv3
, f
, g
);
1559 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
1560 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
1564 D3DXVECTOR2
* WINAPI
D3DXVec2CatmullRom(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv0
, CONST D3DXVECTOR2
*pv1
, CONST D3DXVECTOR2
*pv2
, CONST D3DXVECTOR2
*pv3
, FLOAT s
)
1566 TRACE("(%p, %p, %p, %p, %p, %f)\n", pout
, pv0
, pv1
, pv2
, pv3
, s
);
1568 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
);
1569 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
);
1573 D3DXVECTOR2
* WINAPI
D3DXVec2Hermite(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv1
, CONST D3DXVECTOR2
*pt1
, CONST D3DXVECTOR2
*pv2
, CONST D3DXVECTOR2
*pt2
, FLOAT s
)
1575 FLOAT h1
, h2
, h3
, h4
;
1577 TRACE("(%p, %p, %p, %p, %p, %f)\n", pout
, pv1
, pt1
, pv2
, pt2
, s
);
1579 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
1580 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
1581 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
1582 h4
= s
* s
* s
- s
* s
;
1584 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
1585 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
1589 D3DXVECTOR2
* WINAPI
D3DXVec2Normalize(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv
)
1594 TRACE("(%p, %p)\n", pout
, pv
);
1596 norm
= D3DXVec2Length(pv
);
1604 out
.x
= pv
->x
/ norm
;
1605 out
.y
= pv
->y
/ norm
;
1611 D3DXVECTOR4
* WINAPI
D3DXVec2Transform(D3DXVECTOR4
*pout
, CONST D3DXVECTOR2
*pv
, CONST D3DXMATRIX
*pm
)
1613 TRACE("(%p, %p, %p)\n", pout
, pv
, pm
);
1615 pout
->x
= pm
->u
.m
[0][0] * pv
->x
+ pm
->u
.m
[1][0] * pv
->y
+ pm
->u
.m
[3][0];
1616 pout
->y
= pm
->u
.m
[0][1] * pv
->x
+ pm
->u
.m
[1][1] * pv
->y
+ pm
->u
.m
[3][1];
1617 pout
->z
= pm
->u
.m
[0][2] * pv
->x
+ pm
->u
.m
[1][2] * pv
->y
+ pm
->u
.m
[3][2];
1618 pout
->w
= pm
->u
.m
[0][3] * pv
->x
+ pm
->u
.m
[1][3] * pv
->y
+ pm
->u
.m
[3][3];
1622 D3DXVECTOR4
* WINAPI
D3DXVec2TransformArray(D3DXVECTOR4
* out
, UINT outstride
, CONST D3DXVECTOR2
* in
, UINT instride
, CONST D3DXMATRIX
* matrix
, UINT elements
)
1626 TRACE("(%p, %u, %p, %u, %p, %u)\n", out
, outstride
, in
, instride
, matrix
, elements
);
1628 for (i
= 0; i
< elements
; ++i
) {
1630 (D3DXVECTOR4
*)((char*)out
+ outstride
* i
),
1631 (CONST D3DXVECTOR2
*)((const char*)in
+ instride
* i
),
1637 D3DXVECTOR2
* WINAPI
D3DXVec2TransformCoord(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv
, CONST D3DXMATRIX
*pm
)
1642 TRACE("(%p, %p, %p)\n", pout
, pv
, pm
);
1645 norm
= pm
->u
.m
[0][3] * pv
->x
+ pm
->u
.m
[1][3] * pv
->y
+ pm
->u
.m
[3][3];
1647 pout
->x
= (pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
+ pm
->u
.m
[3][0]) / norm
;
1648 pout
->y
= (pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
+ pm
->u
.m
[3][1]) / norm
;
1653 D3DXVECTOR2
* WINAPI
D3DXVec2TransformCoordArray(D3DXVECTOR2
* out
, UINT outstride
, CONST D3DXVECTOR2
* in
, UINT instride
, CONST D3DXMATRIX
* matrix
, UINT elements
)
1657 TRACE("(%p, %u, %p, %u, %p, %u)\n", out
, outstride
, in
, instride
, matrix
, elements
);
1659 for (i
= 0; i
< elements
; ++i
) {
1660 D3DXVec2TransformCoord(
1661 (D3DXVECTOR2
*)((char*)out
+ outstride
* i
),
1662 (CONST D3DXVECTOR2
*)((const char*)in
+ instride
* i
),
1668 D3DXVECTOR2
* WINAPI
D3DXVec2TransformNormal(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv
, CONST D3DXMATRIX
*pm
)
1670 CONST D3DXVECTOR2 v
= *pv
;
1671 pout
->x
= pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
;
1672 pout
->y
= pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
;
1676 D3DXVECTOR2
* WINAPI
D3DXVec2TransformNormalArray(D3DXVECTOR2
* out
, UINT outstride
, CONST D3DXVECTOR2
*in
, UINT instride
, CONST D3DXMATRIX
*matrix
, UINT elements
)
1680 TRACE("(%p, %u, %p, %u, %p, %u)\n", out
, outstride
, in
, instride
, matrix
, elements
);
1682 for (i
= 0; i
< elements
; ++i
) {
1683 D3DXVec2TransformNormal(
1684 (D3DXVECTOR2
*)((char*)out
+ outstride
* i
),
1685 (CONST D3DXVECTOR2
*)((const char*)in
+ instride
* i
),
1691 /*_________________D3DXVec3_____________________*/
1693 D3DXVECTOR3
* WINAPI
D3DXVec3BaryCentric(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pv3
, FLOAT f
, FLOAT g
)
1695 TRACE("(%p, %p, %p, %p, %f, %f)\n", pout
, pv1
, pv2
, pv3
, f
, g
);
1697 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
1698 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
1699 pout
->z
= (1.0f
-f
-g
) * (pv1
->z
) + f
* (pv2
->z
) + g
* (pv3
->z
);
1703 D3DXVECTOR3
* WINAPI
D3DXVec3CatmullRom( D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv0
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pv3
, FLOAT s
)
1705 TRACE("(%p, %p, %p, %p, %p, %f)\n", pout
, pv0
, pv1
, pv2
, pv3
, s
);
1707 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
);
1708 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
);
1709 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
);
1713 D3DXVECTOR3
* WINAPI
D3DXVec3Hermite(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pt1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pt2
, FLOAT s
)
1715 FLOAT h1
, h2
, h3
, h4
;
1717 TRACE("(%p, %p, %p, %p, %p, %f)\n", pout
, pv1
, pt1
, pv2
, pt2
, s
);
1719 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
1720 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
1721 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
1722 h4
= s
* s
* s
- s
* s
;
1724 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
1725 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
1726 pout
->z
= h1
* (pv1
->z
) + h2
* (pt1
->z
) + h3
* (pv2
->z
) + h4
* (pt2
->z
);
1730 D3DXVECTOR3
* WINAPI
D3DXVec3Normalize(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
)
1735 TRACE("(%p, %p)\n", pout
, pv
);
1737 norm
= D3DXVec3Length(pv
);
1746 out
.x
= pv
->x
/ norm
;
1747 out
.y
= pv
->y
/ norm
;
1748 out
.z
= pv
->z
/ norm
;
1754 D3DXVECTOR3
* WINAPI
D3DXVec3Project(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DVIEWPORT9
*pviewport
, CONST D3DXMATRIX
*pprojection
, CONST D3DXMATRIX
*pview
, CONST D3DXMATRIX
*pworld
)
1759 TRACE("(%p, %p, %p, %p, %p, %p)\n", pout
, pv
, pviewport
, pprojection
, pview
, pworld
);
1761 D3DXMatrixMultiply(&m
, pworld
, pview
);
1762 D3DXMatrixMultiply(&m
, &m
, pprojection
);
1763 D3DXVec3TransformCoord(&out
, pv
, &m
);
1764 out
.x
= pviewport
->X
+ ( 1.0f
+ out
.x
) * pviewport
->Width
/ 2.0f
;
1765 out
.y
= pviewport
->Y
+ ( 1.0f
- out
.y
) * pviewport
->Height
/ 2.0f
;
1766 out
.z
= pviewport
->MinZ
+ out
.z
* ( pviewport
->MaxZ
- pviewport
->MinZ
);
1771 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
)
1775 TRACE("(%p, %u, %p, %u, %p, %p, %p, %p, %u)\n", out
, outstride
, in
, instride
, viewport
, projection
, view
, world
, elements
);
1777 for (i
= 0; i
< elements
; ++i
) {
1779 (D3DXVECTOR3
*)((char*)out
+ outstride
* i
),
1780 (CONST D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
1781 viewport
, projection
, view
, world
);
1786 D3DXVECTOR4
* WINAPI
D3DXVec3Transform(D3DXVECTOR4
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DXMATRIX
*pm
)
1788 TRACE("(%p, %p, %p)\n", pout
, pv
, pm
);
1790 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];
1791 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];
1792 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];
1793 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];
1797 D3DXVECTOR4
* WINAPI
D3DXVec3TransformArray(D3DXVECTOR4
* out
, UINT outstride
, CONST D3DXVECTOR3
* in
, UINT instride
, CONST D3DXMATRIX
* matrix
, UINT elements
)
1801 TRACE("(%p, %u, %p, %u, %p, %u)\n", out
, outstride
, in
, instride
, matrix
, elements
);
1803 for (i
= 0; i
< elements
; ++i
) {
1805 (D3DXVECTOR4
*)((char*)out
+ outstride
* i
),
1806 (CONST D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
1812 D3DXVECTOR3
* WINAPI
D3DXVec3TransformCoord(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DXMATRIX
*pm
)
1817 TRACE("(%p, %p, %p)\n", pout
, pv
, pm
);
1819 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];
1821 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
;
1822 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
;
1823 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
;
1830 D3DXVECTOR3
* WINAPI
D3DXVec3TransformCoordArray(D3DXVECTOR3
* out
, UINT outstride
, CONST D3DXVECTOR3
* in
, UINT instride
, CONST D3DXMATRIX
* matrix
, UINT elements
)
1834 TRACE("(%p, %u, %p, %u, %p, %u)\n", out
, outstride
, in
, instride
, matrix
, elements
);
1836 for (i
= 0; i
< elements
; ++i
) {
1837 D3DXVec3TransformCoord(
1838 (D3DXVECTOR3
*)((char*)out
+ outstride
* i
),
1839 (CONST D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
1845 D3DXVECTOR3
* WINAPI
D3DXVec3TransformNormal(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DXMATRIX
*pm
)
1847 CONST D3DXVECTOR3 v
= *pv
;
1849 TRACE("(%p, %p, %p)\n", pout
, pv
, pm
);
1851 pout
->x
= pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
+ pm
->u
.m
[2][0] * v
.z
;
1852 pout
->y
= pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
+ pm
->u
.m
[2][1] * v
.z
;
1853 pout
->z
= pm
->u
.m
[0][2] * v
.x
+ pm
->u
.m
[1][2] * v
.y
+ pm
->u
.m
[2][2] * v
.z
;
1858 D3DXVECTOR3
* WINAPI
D3DXVec3TransformNormalArray(D3DXVECTOR3
* out
, UINT outstride
, CONST D3DXVECTOR3
* in
, UINT instride
, CONST D3DXMATRIX
* matrix
, UINT elements
)
1862 TRACE("(%p, %u, %p, %u, %p, %u)\n", out
, outstride
, in
, instride
, matrix
, elements
);
1864 for (i
= 0; i
< elements
; ++i
) {
1865 D3DXVec3TransformNormal(
1866 (D3DXVECTOR3
*)((char*)out
+ outstride
* i
),
1867 (CONST D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
1873 D3DXVECTOR3
* WINAPI
D3DXVec3Unproject(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DVIEWPORT9
*pviewport
, CONST D3DXMATRIX
*pprojection
, CONST D3DXMATRIX
*pview
, CONST D3DXMATRIX
*pworld
)
1878 TRACE("(%p, %p, %p, %p, %p, %p)\n", pout
, pv
, pviewport
, pprojection
, pview
, pworld
);
1881 D3DXMatrixMultiply(&m
, pworld
, pview
);
1882 D3DXMatrixMultiply(&m
, &m
, pprojection
);
1884 D3DXMatrixMultiply(&m
, pview
, pprojection
);
1886 D3DXMatrixInverse(&m
, NULL
, &m
);
1887 out
.x
= 2.0f
* ( pv
->x
- pviewport
->X
) / pviewport
->Width
- 1.0f
;
1888 out
.y
= 1.0f
- 2.0f
* ( pv
->y
- pviewport
->Y
) / pviewport
->Height
;
1889 out
.z
= ( pv
->z
- pviewport
->MinZ
) / ( pviewport
->MaxZ
- pviewport
->MinZ
);
1890 D3DXVec3TransformCoord(&out
, &out
, &m
);
1895 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
)
1899 TRACE("(%p, %u, %p, %u, %p, %p, %p, %p, %u)\n", out
, outstride
, in
, instride
, viewport
, projection
, view
, world
, elements
);
1901 for (i
= 0; i
< elements
; ++i
) {
1903 (D3DXVECTOR3
*)((char*)out
+ outstride
* i
),
1904 (CONST D3DXVECTOR3
*)((const char*)in
+ instride
* i
),
1905 viewport
, projection
, view
, world
);
1910 /*_________________D3DXVec4_____________________*/
1912 D3DXVECTOR4
* WINAPI
D3DXVec4BaryCentric(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pv3
, FLOAT f
, FLOAT g
)
1914 TRACE("(%p, %p, %p, %p, %f, %f)\n", pout
, pv1
, pv2
, pv3
, f
, g
);
1916 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
1917 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
1918 pout
->z
= (1.0f
-f
-g
) * (pv1
->z
) + f
* (pv2
->z
) + g
* (pv3
->z
);
1919 pout
->w
= (1.0f
-f
-g
) * (pv1
->w
) + f
* (pv2
->w
) + g
* (pv3
->w
);
1923 D3DXVECTOR4
* WINAPI
D3DXVec4CatmullRom(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv0
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pv3
, FLOAT s
)
1925 TRACE("(%p, %p, %p, %p, %p, %f)\n", pout
, pv0
, pv1
, pv2
, pv3
, s
);
1927 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
);
1928 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
);
1929 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
);
1930 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
);
1934 D3DXVECTOR4
* WINAPI
D3DXVec4Cross(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pv3
)
1938 TRACE("(%p, %p, %p, %p)\n", pout
, pv1
, pv2
, pv3
);
1940 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
);
1941 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
));
1942 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
);
1943 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
));
1948 D3DXVECTOR4
* WINAPI
D3DXVec4Hermite(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pt1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pt2
, FLOAT s
)
1950 FLOAT h1
, h2
, h3
, h4
;
1952 TRACE("(%p, %p, %p, %p, %p, %f)\n", pout
, pv1
, pt1
, pv2
, pt2
, s
);
1954 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
1955 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
1956 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
1957 h4
= s
* s
* s
- s
* s
;
1959 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
1960 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
1961 pout
->z
= h1
* (pv1
->z
) + h2
* (pt1
->z
) + h3
* (pv2
->z
) + h4
* (pt2
->z
);
1962 pout
->w
= h1
* (pv1
->w
) + h2
* (pt1
->w
) + h3
* (pv2
->w
) + h4
* (pt2
->w
);
1966 D3DXVECTOR4
* WINAPI
D3DXVec4Normalize(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv
)
1971 TRACE("(%p, %p)\n", pout
, pv
);
1973 norm
= D3DXVec4Length(pv
);
1975 out
.x
= pv
->x
/ norm
;
1976 out
.y
= pv
->y
/ norm
;
1977 out
.z
= pv
->z
/ norm
;
1978 out
.w
= pv
->w
/ norm
;
1984 D3DXVECTOR4
* WINAPI
D3DXVec4Transform(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv
, CONST D3DXMATRIX
*pm
)
1988 TRACE("(%p, %p, %p)\n", pout
, pv
, pm
);
1990 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
;
1991 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
;
1992 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
;
1993 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
;
1998 D3DXVECTOR4
* WINAPI
D3DXVec4TransformArray(D3DXVECTOR4
* out
, UINT outstride
, CONST D3DXVECTOR4
* in
, UINT instride
, CONST D3DXMATRIX
* matrix
, UINT elements
)
2002 TRACE("(%p, %u, %p, %u, %p, %u)\n", out
, outstride
, in
, instride
, matrix
, elements
);
2004 for (i
= 0; i
< elements
; ++i
) {
2006 (D3DXVECTOR4
*)((char*)out
+ outstride
* i
),
2007 (CONST D3DXVECTOR4
*)((const char*)in
+ instride
* i
),
2013 static inline unsigned short float_32_to_16(const float in
)
2015 int exp
= 0, origexp
;
2016 float tmp
= fabs(in
);
2017 int sign
= (copysignf(1, in
) < 0);
2018 unsigned int mantissa
;
2021 /* Deal with special numbers */
2022 if (isinf(in
)) return (sign
? 0xffff : 0x7fff);
2023 if (isnan(in
)) return (sign
? 0xffff : 0x7fff);
2024 if (in
== 0.0f
) return (sign
? 0x8000 : 0x0000);
2026 if (tmp
< powf(2, 10))
2032 } while (tmp
< powf(2, 10));
2034 else if (tmp
>= powf(2, 11))
2040 } while (tmp
>= powf(2, 11));
2043 exp
+= 10; /* Normalize the mantissa */
2044 exp
+= 15; /* Exponent is encoded with excess 15 */
2048 mantissa
= (unsigned int) tmp
;
2049 if ((tmp
- mantissa
== 0.5f
&& mantissa
% 2 == 1) || /* round half to even */
2050 (tmp
- mantissa
> 0.5f
))
2052 mantissa
++; /* round to nearest, away from zero */
2054 if (mantissa
== 2048)
2063 ret
= 0x7fff; /* INF */
2067 unsigned int rounding
= 0;
2069 /* Denormalized half float */
2071 /* return 0x0000 (=0.0) for numbers too small to represent in half floats */
2073 return (sign
? 0x8000 : 0x0000);
2077 /* the 13 extra bits from single precision are used for rounding */
2078 mantissa
= (unsigned int)(tmp
* powf(2, 13));
2079 mantissa
>>= 1 - exp
; /* denormalize */
2081 mantissa
-= ~(mantissa
>> 13) & 1; /* round half to even */
2082 /* remove 13 least significant bits to get half float precision */
2084 rounding
= mantissa
& 1;
2087 ret
= mantissa
+ rounding
;
2091 ret
= (exp
<< 10) | (mantissa
& 0x3ff);
2094 ret
|= ((sign
? 1 : 0) << 15); /* Add the sign */
2098 D3DXFLOAT16
*WINAPI
D3DXFloat32To16Array(D3DXFLOAT16
*pout
, CONST FLOAT
*pin
, UINT n
)
2102 TRACE("(%p, %p, %u)\n", pout
, pin
, n
);
2104 for (i
= 0; i
< n
; ++i
)
2106 pout
[i
].value
= float_32_to_16(pin
[i
]);
2112 /* Native d3dx9's D3DXFloat16to32Array lacks support for NaN and Inf. Specifically, e = 16 is treated as a
2113 * regular number - e.g., 0x7fff is converted to 131008.0 and 0xffff to -131008.0. */
2114 static inline float float_16_to_32(const unsigned short in
)
2116 const unsigned short s
= (in
& 0x8000);
2117 const unsigned short e
= (in
& 0x7C00) >> 10;
2118 const unsigned short m
= in
& 0x3FF;
2119 const float sgn
= (s
? -1.0f
: 1.0f
);
2123 if (m
== 0) return sgn
* 0.0f
; /* +0.0 or -0.0 */
2124 else return sgn
* powf(2, -14.0f
) * (m
/ 1024.0f
);
2128 return sgn
* powf(2, e
- 15.0f
) * (1.0f
+ (m
/ 1024.0f
));
2132 FLOAT
*WINAPI
D3DXFloat16To32Array(FLOAT
*pout
, CONST D3DXFLOAT16
*pin
, UINT n
)
2136 TRACE("(%p, %p, %u)\n", pout
, pin
, n
);
2138 for (i
= 0; i
< n
; ++i
)
2140 pout
[i
] = float_16_to_32(pin
[i
].value
);
2146 /*_________________D3DXSH________________*/
2148 FLOAT
* WINAPI
D3DXSHAdd(FLOAT
*out
, UINT order
, const FLOAT
*a
, const FLOAT
*b
)
2152 TRACE("out %p, order %u, a %p, b %p\n", out
, order
, a
, b
);
2154 for (i
= 0; i
< order
* order
; i
++)
2155 out
[i
] = a
[i
] + b
[i
];
2160 FLOAT WINAPI
D3DXSHDot(UINT order
, CONST FLOAT
*a
, CONST FLOAT
*b
)
2165 TRACE("order %u, a %p, b %p\n", order
, a
, b
);
2168 for (i
= 1; i
< order
* order
; i
++)
2174 FLOAT
* WINAPI
D3DXSHEvalDirection(FLOAT
*out
, UINT order
, CONST D3DXVECTOR3
*dir
)
2177 TRACE("(%p, %u, %p)\n", out
, order
, dir
);
2179 if ( (order
< D3DXSH_MINORDER
) || (order
> D3DXSH_MAXORDER
) )
2182 out
[0] = 0.5f
/ sqrt(D3DX_PI
);
2183 out
[1] = -0.5f
/ sqrt(D3DX_PI
/ 3.0f
) * dir
->y
;
2184 out
[2] = 0.5f
/ sqrt(D3DX_PI
/ 3.0f
) * dir
->z
;
2185 out
[3] = -0.5f
/ sqrt(D3DX_PI
/ 3.0f
) * dir
->x
;
2189 out
[4] = 0.5f
/ sqrt(D3DX_PI
/ 15.0f
) * dir
->x
* dir
->y
;
2190 out
[5] = -0.5f
/ sqrt(D3DX_PI
/ 15.0f
) * dir
->y
* dir
->z
;
2191 out
[6] = 0.25f
/ sqrt(D3DX_PI
/ 5.0f
) * ( 3.0f
* dir
->z
* dir
->z
- 1.0f
);
2192 out
[7] = -0.5f
/ sqrt(D3DX_PI
/ 15.0f
) * dir
->x
* dir
->z
;
2193 out
[8] = 0.25f
/ sqrt(D3DX_PI
/ 15.0f
) * ( dir
->x
* dir
->x
- dir
->y
* dir
->y
);
2197 out
[9] = -sqrt(70.0f
/ D3DX_PI
) / 8.0f
* dir
->y
* (3.0f
* dir
->x
* dir
->x
- dir
->y
* dir
->y
);
2198 out
[10] = sqrt(105.0f
/ D3DX_PI
) / 2.0f
* dir
->x
* dir
->y
* dir
->z
;
2199 out
[11] = -sqrt(42.0 / D3DX_PI
) / 8.0f
* dir
->y
* ( -1.0f
+ 5.0f
* dir
->z
* dir
->z
);
2200 out
[12] = sqrt(7.0f
/ D3DX_PI
) / 4.0f
* dir
->z
* ( 5.0f
* dir
->z
* dir
->z
- 3.0f
);
2201 out
[13] = sqrt(42.0 / D3DX_PI
) / 8.0f
* dir
->x
* ( 1.0f
- 5.0f
* dir
->z
* dir
->z
);
2202 out
[14] = sqrt(105.0f
/ D3DX_PI
) / 4.0f
* dir
->z
* ( dir
->x
* dir
->x
- dir
->y
* dir
->y
);
2203 out
[15] = -sqrt(70.0f
/ D3DX_PI
) / 8.0f
* dir
->x
* ( dir
->x
* dir
->x
- 3.0f
* dir
->y
* dir
->y
);
2207 out
[16] = 0.75f
* sqrt(35.0f
/ D3DX_PI
) * dir
->x
* dir
->y
* (dir
->x
* dir
->x
- dir
->y
* dir
->y
);
2208 out
[17] = 3.0f
* dir
->z
* out
[9];
2209 out
[18] = 0.75f
* sqrt(5.0f
/ D3DX_PI
) * dir
->x
* dir
->y
* ( 7.0f
* dir
->z
* dir
->z
- 1.0f
);
2210 out
[19] = 0.375f
* sqrt(10.0f
/ D3DX_PI
) * dir
->y
* dir
->z
* ( 3.0f
- 7.0f
* dir
->z
* dir
->z
);
2211 out
[20] = 3.0f
/ ( 16.0f
* sqrt(D3DX_PI
) ) * ( 35.0f
* dir
->z
* dir
->z
* dir
->z
* dir
->z
- 30.f
* dir
->z
* dir
->z
+ 3.0f
);
2212 out
[21] = 0.375f
* sqrt(10.0f
/ D3DX_PI
) * dir
->x
* dir
->z
* ( 3.0f
- 7.0f
* dir
->z
* dir
->z
);
2213 out
[22] = 0.375f
* sqrt(5.0f
/ D3DX_PI
) * ( dir
->x
* dir
->x
- dir
->y
* dir
->y
) * ( 7.0f
* dir
->z
* dir
->z
- 1.0f
);
2214 out
[23] = 3.0 * dir
->z
* out
[15];
2215 out
[24] = 3.0f
/ 16.0f
* sqrt(35.0f
/ D3DX_PI
) * ( dir
->x
* dir
->x
* dir
->x
* dir
->x
- 6.0f
* dir
->x
* dir
->x
* dir
->y
* dir
->y
+ dir
->y
* dir
->y
* dir
->y
* dir
->y
);
2219 out
[25] = -3.0f
/ 32.0f
* sqrt(154.0f
/ D3DX_PI
) * dir
->y
* ( 5.0f
* dir
->x
* dir
->x
* dir
->x
* dir
->x
- 10.0f
* dir
->x
* dir
->x
* dir
->y
* dir
->y
+ dir
->y
* dir
->y
* dir
->y
* dir
->y
);
2220 out
[26] = 0.75f
* sqrt(385.0f
/ D3DX_PI
) * dir
->x
* dir
->y
* dir
->z
* ( dir
->x
* dir
->x
- dir
->y
* dir
->y
);
2221 out
[27] = sqrt(770.0f
/ D3DX_PI
) / 32.0f
* dir
->y
* ( 3.0f
* dir
->x
* dir
->x
- dir
->y
* dir
->y
) * ( 1.0f
- 9.0f
* dir
->z
* dir
->z
);
2222 out
[28] = sqrt(1155.0f
/ D3DX_PI
) / 4.0f
* dir
->x
* dir
->y
* dir
->z
* ( 3.0f
* dir
->z
* dir
->z
- 1.0f
);
2223 out
[29] = sqrt(165.0f
/ D3DX_PI
) / 16.0f
* dir
->y
* ( 14.0f
* dir
->z
* dir
->z
- 21.0f
* dir
->z
* dir
->z
* dir
->z
* dir
->z
- 1.0f
);
2224 out
[30] = sqrt(11.0f
/ D3DX_PI
) / 16.0f
* dir
->z
* ( 63.0f
* dir
->z
* dir
->z
* dir
->z
* dir
->z
- 70.0f
* dir
->z
* dir
->z
+ 15.0f
);
2225 out
[31] = sqrt(165.0f
/ D3DX_PI
) / 16.0f
* dir
->x
* ( 14.0f
* dir
->z
* dir
->z
- 21.0f
* dir
->z
* dir
->z
* dir
->z
* dir
->z
- 1.0f
);
2226 out
[32] = sqrt(1155.0f
/ D3DX_PI
) / 8.0f
* dir
->z
* ( dir
->x
* dir
->x
- dir
->y
* dir
->y
) * ( 3.0f
* dir
->z
* dir
->z
- 1.0f
);
2227 out
[33] = sqrt(770.0f
/ D3DX_PI
) / 32.0f
* dir
->x
* ( dir
->x
* dir
->x
- 3.0f
* dir
->y
* dir
->y
) * ( 1.0f
- 9.0f
* dir
->z
* dir
->z
);
2228 out
[34] = 3.0f
/ 16.0f
* sqrt(385.0f
/ D3DX_PI
) * dir
->z
* ( dir
->x
* dir
->x
* dir
->x
* dir
->x
- 6.0 * dir
->x
* dir
->x
* dir
->y
* dir
->y
+ dir
->y
* dir
->y
* dir
->y
* dir
->y
);
2229 out
[35] = -3.0f
/ 32.0f
* sqrt(154.0f
/ D3DX_PI
) * dir
->x
* ( dir
->x
* dir
->x
* dir
->x
* dir
->x
- 10.0f
* dir
->x
* dir
->x
* dir
->y
* dir
->y
+ 5.0f
* dir
->y
* dir
->y
* dir
->y
* dir
->y
);
2234 FLOAT
* WINAPI
D3DXSHMultiply2(FLOAT
*out
, CONST FLOAT
*a
, CONST FLOAT
*b
)
2238 TRACE("(%p, %p, %p)\n", out
, a
, b
);
2240 ta
= 0.28209479f
* a
[0];
2241 tb
= 0.28209479f
* b
[0];
2243 out
[0]= 0.28209479f
* D3DXSHDot(2, a
, b
);
2244 out
[1] = ta
* b
[1] + tb
* a
[1];
2245 out
[2] = ta
* b
[2] + tb
* a
[2];
2246 out
[3] = ta
* b
[3] + tb
* a
[3];
2251 FLOAT
* WINAPI
D3DXSHMultiply3(FLOAT
*out
, CONST FLOAT
*a
, CONST FLOAT
*b
)
2255 TRACE("(%p, %p, %p)\n", out
, a
, b
);
2257 out
[0]= 0.28209479f
* a
[0] * b
[0];
2259 ta
= 0.28209479f
* a
[0] - 0.12615662f
* a
[6] - 0.21850968f
* a
[8];
2260 tb
= 0.28209479f
* b
[0] - 0.12615662f
* b
[6] - 0.21850968f
* b
[8];
2261 out
[1] = ta
* b
[1] + tb
* a
[1];
2263 out
[0] += 0.28209479f
* t
;
2264 out
[6] = -0.12615662f
* t
;
2265 out
[8] = -0.21850968f
* t
;
2267 ta
= 0.21850968f
* a
[5];
2268 tb
= 0.21850968f
* b
[5];
2269 out
[1] += ta
* b
[2] + tb
* a
[2];
2270 out
[2] = ta
* b
[1] + tb
* a
[1];
2271 t
= a
[1] * b
[2] +a
[2] * b
[1];
2272 out
[5] = 0.21850968f
* t
;
2274 ta
= 0.21850968f
* a
[4];
2275 tb
= 0.21850968f
* b
[4];
2276 out
[1] += ta
* b
[3] + tb
* a
[3];
2277 out
[3] = ta
* b
[1] + tb
* a
[1];
2278 t
= a
[1] * b
[3] + a
[3] * b
[1];
2279 out
[4] = 0.21850968f
* t
;
2281 ta
= 0.28209480f
* a
[0] + 0.25231326f
* a
[6];
2282 tb
= 0.28209480f
* b
[0] + 0.25231326f
* b
[6];
2283 out
[2] += ta
* b
[2] + tb
* a
[2];
2285 out
[0] += 0.28209480f
* t
;
2286 out
[6] += 0.25231326f
* t
;
2288 ta
= 0.21850969f
* a
[7];
2289 tb
= 0.21850969f
* b
[7];
2290 out
[2] += ta
* b
[3] + tb
* a
[3];
2291 out
[3] += ta
* b
[2] + tb
* a
[2];
2292 t
= a
[2] * b
[3] + a
[3] * b
[2];
2293 out
[7] = 0.21850969f
* t
;
2295 ta
= 0.28209479f
* a
[0] - 0.12615663f
* a
[6] + 0.21850969f
* a
[8];
2296 tb
= 0.28209479f
* b
[0] - 0.12615663f
* b
[6] + 0.21850969f
* b
[8];
2297 out
[3] += ta
* b
[3] + tb
* a
[3];
2299 out
[0] += 0.28209479f
* t
;
2300 out
[6] -= 0.12615663f
* t
;
2301 out
[8] += 0.21850969f
* t
;
2303 ta
= 0.28209479f
* a
[0] - 0.18022375f
* a
[6];
2304 tb
= 0.28209479f
* b
[0] - 0.18022375f
* b
[6];
2305 out
[4] += ta
* b
[4] + tb
* a
[4];
2307 out
[0] += 0.28209479f
* t
;
2308 out
[6] -= 0.18022375f
* t
;
2310 ta
= 0.15607835f
* a
[7];
2311 tb
= 0.15607835f
* b
[7];
2312 out
[4] += ta
* b
[5] + tb
* a
[5];
2313 out
[5] += ta
* b
[4] + tb
* a
[4];
2314 t
= a
[4] * b
[5] + a
[5] * b
[4];
2315 out
[7] += 0.15607834f
* t
;
2317 ta
= 0.28209479f
* a
[0] + 0.09011186 * a
[6] - 0.15607835f
* a
[8];
2318 tb
= 0.28209479f
* b
[0] + 0.09011186 * b
[6] - 0.15607835f
* b
[8];
2319 out
[5] += ta
* b
[5] + tb
* a
[5];
2321 out
[0] += 0.28209479f
* t
;
2322 out
[6] += 0.09011186f
* t
;
2323 out
[8] -= 0.15607835f
* t
;
2325 ta
= 0.28209480f
* a
[0];
2326 tb
= 0.28209480f
* b
[0];
2327 out
[6] += ta
* b
[6] + tb
* a
[6];
2329 out
[0] += 0.28209480f
* t
;
2330 out
[6] += 0.18022376f
* t
;
2332 ta
= 0.28209479f
* a
[0] + 0.09011186 * a
[6] + 0.15607835f
* a
[8];
2333 tb
= 0.28209479f
* b
[0] + 0.09011186 * b
[6] + 0.15607835f
* b
[8];
2334 out
[7] += ta
* b
[7] + tb
* a
[7];
2336 out
[0] += 0.28209479f
* t
;
2337 out
[6] += 0.09011186f
* t
;
2338 out
[8] += 0.15607835f
* t
;
2340 ta
= 0.28209479f
* a
[0] - 0.18022375f
* a
[6];
2341 tb
= 0.28209479f
* b
[0] - 0.18022375f
* b
[6];
2342 out
[8] += ta
* b
[8] + tb
* a
[8];
2344 out
[0] += 0.28209479f
* t
;
2345 out
[6] -= 0.18022375f
* t
;
2350 FLOAT
* WINAPI
D3DXSHRotateZ(FLOAT
*out
, UINT order
, FLOAT angle
, CONST FLOAT
*in
)
2352 FLOAT c1a
, c2a
, c3a
, c4a
, c5a
, s1a
, s2a
, s3a
, s4a
, s5a
;
2354 TRACE("%p, %u, %f, %p)\n", out
, order
, angle
, in
);
2357 c2a
= cos( 2.0f
* angle
);
2358 c3a
= cos( 3.0f
* angle
);
2359 c4a
= cos( 4.0f
* angle
);
2360 c5a
= cos( 5.0f
* angle
);
2362 s2a
= sin( 2.0f
* angle
);
2363 s3a
= sin( 3.0f
* angle
);
2364 s4a
= sin( 4.0f
* angle
);
2365 s5a
= sin( 5.0f
* angle
);
2368 out
[1] = c1a
* in
[1] + s1a
* in
[3];
2370 out
[3] = c1a
* in
[3] - s1a
* in
[1];
2371 if ( order
<= D3DXSH_MINORDER
)
2374 out
[4] = c2a
* in
[4] + s2a
* in
[8];
2375 out
[5] = c1a
* in
[5] + s1a
* in
[7];
2377 out
[7] = c1a
* in
[7] - s1a
* in
[5];
2378 out
[8] = c2a
* in
[8] - s2a
* in
[4];
2382 out
[9] = c3a
* in
[9] + s3a
* in
[15];
2383 out
[10] = c2a
* in
[10] + s2a
* in
[14];
2384 out
[11] = c1a
* in
[11] + s1a
* in
[13];
2386 out
[13] = c1a
* in
[13] - s1a
* in
[11];
2387 out
[14] = c2a
* in
[14] - s2a
* in
[10];
2388 out
[15] = c3a
* in
[15] - s3a
* in
[9];
2392 out
[16] = c4a
* in
[16] + s4a
* in
[24];
2393 out
[17] = c3a
* in
[17] + s3a
* in
[23];
2394 out
[18] = c2a
* in
[18] + s2a
* in
[22];
2395 out
[19] = c1a
* in
[19] + s1a
* in
[21];
2397 out
[21] = c1a
* in
[21] - s1a
* in
[19];
2398 out
[22] = c2a
* in
[22] - s2a
* in
[18];
2399 out
[23] = c3a
* in
[23] - s3a
* in
[17];
2400 out
[24] = c4a
* in
[24] - s4a
* in
[16];
2404 out
[25] = c5a
* in
[25] + s5a
* in
[35];
2405 out
[26] = c4a
* in
[26] + s4a
* in
[34];
2406 out
[27] = c3a
* in
[27] + s3a
* in
[33];
2407 out
[28] = c2a
* in
[28] + s2a
* in
[32];
2408 out
[29] = c1a
* in
[29] + s1a
* in
[31];
2410 out
[31] = c1a
* in
[31] - s1a
* in
[29];
2411 out
[32] = c2a
* in
[32] - s2a
* in
[28];
2412 out
[33] = c3a
* in
[33] - s3a
* in
[27];
2413 out
[34] = c4a
* in
[34] - s4a
* in
[26];
2414 out
[35] = c5a
* in
[35] - s5a
* in
[25];
2419 FLOAT
* WINAPI
D3DXSHScale(FLOAT
*out
, UINT order
, CONST FLOAT
*a
, CONST FLOAT scale
)
2423 TRACE("out %p, order %u, a %p, scale %f\n", out
, order
, a
, scale
);
2425 for (i
= 0; i
< order
* order
; i
++)
2426 out
[i
] = a
[i
] * scale
;