2 * Copyright 2007 David Adam
3 * Copyright 2008 Jérôme Gardou
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
30 #include "d3dx8_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(d3dx8
);
36 static const ID3DXMatrixStackVtbl ID3DXMatrixStack_Vtbl
;
38 /*_________________D3DXColor____________________*/
40 D3DXCOLOR
* WINAPI
D3DXColorAdjustContrast(D3DXCOLOR
*pout
, CONST D3DXCOLOR
*pc
, FLOAT s
)
42 pout
->r
= 0.5f
+ s
* (pc
->r
- 0.5f
);
43 pout
->g
= 0.5f
+ s
* (pc
->g
- 0.5f
);
44 pout
->b
= 0.5f
+ s
* (pc
->b
- 0.5f
);
49 D3DXCOLOR
* WINAPI
D3DXColorAdjustSaturation(D3DXCOLOR
*pout
, CONST D3DXCOLOR
*pc
, FLOAT s
)
53 grey
= pc
->r
* 0.2125f
+ pc
->g
* 0.7154f
+ pc
->b
* 0.0721f
;
54 pout
->r
= grey
+ s
* (pc
->r
- grey
);
55 pout
->g
= grey
+ s
* (pc
->g
- grey
);
56 pout
->b
= grey
+ s
* (pc
->b
- grey
);
61 /*_________________D3DXMatrix____________________*/
63 D3DXMATRIX
* WINAPI
D3DXMatrixAffineTransformation(D3DXMATRIX
*pout
, FLOAT scaling
, CONST D3DXVECTOR3
*rotationcenter
, CONST D3DXQUATERNION
*rotation
, CONST D3DXVECTOR3
*translation
)
65 D3DXMATRIX m1
, m2
, m3
, m4
, m5
;
67 D3DXMatrixScaling(&m1
, scaling
, scaling
, scaling
);
68 if ( !rotationcenter
)
70 D3DXMatrixIdentity(&m2
);
71 D3DXMatrixIdentity(&m4
);
75 D3DXMatrixTranslation(&m2
, -rotationcenter
->x
, -rotationcenter
->y
, -rotationcenter
->z
);
76 D3DXMatrixTranslation(&m4
, rotationcenter
->x
, rotationcenter
->y
, rotationcenter
->z
);
80 D3DXMatrixIdentity(&m3
);
84 D3DXMatrixRotationQuaternion(&m3
, rotation
);
88 D3DXMatrixIdentity(&m5
);
92 D3DXMatrixTranslation(&m5
, translation
->x
, translation
->y
, translation
->z
);
94 D3DXMatrixMultiply(&m1
, &m1
, &m2
);
95 D3DXMatrixMultiply(&m1
, &m1
, &m3
);
96 D3DXMatrixMultiply(&m1
, &m1
, &m4
);
97 D3DXMatrixMultiply(pout
, &m1
, &m5
);
101 FLOAT WINAPI
D3DXMatrixfDeterminant(CONST D3DXMATRIX
*pm
)
103 D3DXVECTOR4 minor
, v1
, v2
, v3
;
106 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];
107 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];
108 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];
109 D3DXVec4Cross(&minor
, &v1
, &v2
, &v3
);
110 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
);
114 D3DXMATRIX
* WINAPI
D3DXMatrixInverse(D3DXMATRIX
*pout
, FLOAT
*pdeterminant
, CONST D3DXMATRIX
*pm
)
117 D3DXVECTOR4 v
, vec
[3];
120 det
= D3DXMatrixfDeterminant(pm
);
121 if ( !det
) return NULL
;
122 if ( pdeterminant
) *pdeterminant
= det
;
130 if ( j
> i
) a
= a
-1;
131 vec
[a
].x
= pm
->u
.m
[j
][0];
132 vec
[a
].y
= pm
->u
.m
[j
][1];
133 vec
[a
].z
= pm
->u
.m
[j
][2];
134 vec
[a
].w
= pm
->u
.m
[j
][3];
137 D3DXVec4Cross(&v
, &vec
[0], &vec
[1], &vec
[2]);
138 pout
->u
.m
[0][i
] = pow(-1.0f
, i
) * v
.x
/ det
;
139 pout
->u
.m
[1][i
] = pow(-1.0f
, i
) * v
.y
/ det
;
140 pout
->u
.m
[2][i
] = pow(-1.0f
, i
) * v
.z
/ det
;
141 pout
->u
.m
[3][i
] = pow(-1.0f
, i
) * v
.w
/ det
;
146 D3DXMATRIX
* WINAPI
D3DXMatrixLookAtLH(D3DXMATRIX
*pout
, CONST D3DXVECTOR3
*peye
, CONST D3DXVECTOR3
*pat
, CONST D3DXVECTOR3
*pup
)
148 D3DXVECTOR3 right
, rightn
, up
, upn
, vec
, vec2
;
150 D3DXVec3Subtract(&vec2
, pat
, peye
);
151 D3DXVec3Normalize(&vec
, &vec2
);
152 D3DXVec3Cross(&right
, pup
, &vec
);
153 D3DXVec3Cross(&up
, &vec
, &right
);
154 D3DXVec3Normalize(&rightn
, &right
);
155 D3DXVec3Normalize(&upn
, &up
);
156 pout
->u
.m
[0][0] = rightn
.x
;
157 pout
->u
.m
[1][0] = rightn
.y
;
158 pout
->u
.m
[2][0] = rightn
.z
;
159 pout
->u
.m
[3][0] = -D3DXVec3Dot(&rightn
,peye
);
160 pout
->u
.m
[0][1] = upn
.x
;
161 pout
->u
.m
[1][1] = upn
.y
;
162 pout
->u
.m
[2][1] = upn
.z
;
163 pout
->u
.m
[3][1] = -D3DXVec3Dot(&upn
, peye
);
164 pout
->u
.m
[0][2] = vec
.x
;
165 pout
->u
.m
[1][2] = vec
.y
;
166 pout
->u
.m
[2][2] = vec
.z
;
167 pout
->u
.m
[3][2] = -D3DXVec3Dot(&vec
, peye
);
168 pout
->u
.m
[0][3] = 0.0f
;
169 pout
->u
.m
[1][3] = 0.0f
;
170 pout
->u
.m
[2][3] = 0.0f
;
171 pout
->u
.m
[3][3] = 1.0f
;
175 D3DXMATRIX
* WINAPI
D3DXMatrixLookAtRH(D3DXMATRIX
*pout
, CONST D3DXVECTOR3
*peye
, CONST D3DXVECTOR3
*pat
, CONST D3DXVECTOR3
*pup
)
177 D3DXVECTOR3 right
, rightn
, up
, upn
, vec
, vec2
;
179 D3DXVec3Subtract(&vec2
, pat
, peye
);
180 D3DXVec3Normalize(&vec
, &vec2
);
181 D3DXVec3Cross(&right
, pup
, &vec
);
182 D3DXVec3Cross(&up
, &vec
, &right
);
183 D3DXVec3Normalize(&rightn
, &right
);
184 D3DXVec3Normalize(&upn
, &up
);
185 pout
->u
.m
[0][0] = -rightn
.x
;
186 pout
->u
.m
[1][0] = -rightn
.y
;
187 pout
->u
.m
[2][0] = -rightn
.z
;
188 pout
->u
.m
[3][0] = D3DXVec3Dot(&rightn
,peye
);
189 pout
->u
.m
[0][1] = upn
.x
;
190 pout
->u
.m
[1][1] = upn
.y
;
191 pout
->u
.m
[2][1] = upn
.z
;
192 pout
->u
.m
[3][1] = -D3DXVec3Dot(&upn
, peye
);
193 pout
->u
.m
[0][2] = -vec
.x
;
194 pout
->u
.m
[1][2] = -vec
.y
;
195 pout
->u
.m
[2][2] = -vec
.z
;
196 pout
->u
.m
[3][2] = D3DXVec3Dot(&vec
, peye
);
197 pout
->u
.m
[0][3] = 0.0f
;
198 pout
->u
.m
[1][3] = 0.0f
;
199 pout
->u
.m
[2][3] = 0.0f
;
200 pout
->u
.m
[3][3] = 1.0f
;
204 D3DXMATRIX
* WINAPI
D3DXMatrixMultiply(D3DXMATRIX
*pout
, CONST D3DXMATRIX
*pm1
, CONST D3DXMATRIX
*pm2
)
213 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
];
220 D3DXMATRIX
* WINAPI
D3DXMatrixMultiplyTranspose(D3DXMATRIX
*pout
, CONST D3DXMATRIX
*pm1
, CONST D3DXMATRIX
*pm2
)
222 D3DXMatrixMultiply(pout
, pm1
, pm2
);
223 D3DXMatrixTranspose(pout
, pout
);
227 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoLH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
229 D3DXMatrixIdentity(pout
);
230 pout
->u
.m
[0][0] = 2.0f
/ w
;
231 pout
->u
.m
[1][1] = 2.0f
/ h
;
232 pout
->u
.m
[2][2] = 1.0f
/ (zf
- zn
);
233 pout
->u
.m
[3][2] = zn
/ (zn
- zf
);
237 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoOffCenterLH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
239 D3DXMatrixIdentity(pout
);
240 pout
->u
.m
[0][0] = 2.0f
/ (r
- l
);
241 pout
->u
.m
[1][1] = 2.0f
/ (t
- b
);
242 pout
->u
.m
[2][2] = 1.0f
/ (zf
-zn
);
243 pout
->u
.m
[3][0] = -1.0f
-2.0f
*l
/ (r
- l
);
244 pout
->u
.m
[3][1] = 1.0f
+ 2.0f
* t
/ (b
- t
);
245 pout
->u
.m
[3][2] = zn
/ (zn
-zf
);
249 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoOffCenterRH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
251 D3DXMatrixIdentity(pout
);
252 pout
->u
.m
[0][0] = 2.0f
/ (r
- l
);
253 pout
->u
.m
[1][1] = 2.0f
/ (t
- b
);
254 pout
->u
.m
[2][2] = 1.0f
/ (zn
-zf
);
255 pout
->u
.m
[3][0] = -1.0f
-2.0f
*l
/ (r
- l
);
256 pout
->u
.m
[3][1] = 1.0f
+ 2.0f
* t
/ (b
- t
);
257 pout
->u
.m
[3][2] = zn
/ (zn
-zf
);
261 D3DXMATRIX
* WINAPI
D3DXMatrixOrthoRH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
263 D3DXMatrixIdentity(pout
);
264 pout
->u
.m
[0][0] = 2.0f
/ w
;
265 pout
->u
.m
[1][1] = 2.0f
/ h
;
266 pout
->u
.m
[2][2] = 1.0f
/ (zn
- zf
);
267 pout
->u
.m
[3][2] = zn
/ (zn
- zf
);
271 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveFovLH(D3DXMATRIX
*pout
, FLOAT fovy
, FLOAT aspect
, FLOAT zn
, FLOAT zf
)
273 D3DXMatrixIdentity(pout
);
274 pout
->u
.m
[0][0] = 1.0f
/ (aspect
* tan(fovy
/2.0f
));
275 pout
->u
.m
[1][1] = 1.0f
/ tan(fovy
/2.0f
);
276 pout
->u
.m
[2][2] = zf
/ (zf
- zn
);
277 pout
->u
.m
[2][3] = 1.0f
;
278 pout
->u
.m
[3][2] = (zf
* zn
) / (zn
- zf
);
279 pout
->u
.m
[3][3] = 0.0f
;
283 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveFovRH(D3DXMATRIX
*pout
, FLOAT fovy
, FLOAT aspect
, FLOAT zn
, FLOAT zf
)
285 D3DXMatrixIdentity(pout
);
286 pout
->u
.m
[0][0] = 1.0f
/ (aspect
* tan(fovy
/2.0f
));
287 pout
->u
.m
[1][1] = 1.0f
/ tan(fovy
/2.0f
);
288 pout
->u
.m
[2][2] = zf
/ (zn
- zf
);
289 pout
->u
.m
[2][3] = -1.0f
;
290 pout
->u
.m
[3][2] = (zf
* zn
) / (zn
- zf
);
291 pout
->u
.m
[3][3] = 0.0f
;
295 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveLH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
297 D3DXMatrixIdentity(pout
);
298 pout
->u
.m
[0][0] = 2.0f
* zn
/ w
;
299 pout
->u
.m
[1][1] = 2.0f
* zn
/ h
;
300 pout
->u
.m
[2][2] = zf
/ (zf
- zn
);
301 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
- zf
);
302 pout
->u
.m
[2][3] = 1.0f
;
303 pout
->u
.m
[3][3] = 0.0f
;
307 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveOffCenterLH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
309 D3DXMatrixIdentity(pout
);
310 pout
->u
.m
[0][0] = 2.0f
* zn
/ (r
- l
);
311 pout
->u
.m
[1][1] = -2.0f
* zn
/ (b
- t
);
312 pout
->u
.m
[2][0] = -1.0f
- 2.0f
* l
/ (r
- l
);
313 pout
->u
.m
[2][1] = 1.0f
+ 2.0f
* t
/ (b
- t
);
314 pout
->u
.m
[2][2] = - zf
/ (zn
- zf
);
315 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
-zf
);
316 pout
->u
.m
[2][3] = 1.0f
;
317 pout
->u
.m
[3][3] = 0.0f
;
321 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveOffCenterRH(D3DXMATRIX
*pout
, FLOAT l
, FLOAT r
, FLOAT b
, FLOAT t
, FLOAT zn
, FLOAT zf
)
323 D3DXMatrixIdentity(pout
);
324 pout
->u
.m
[0][0] = 2.0f
* zn
/ (r
- l
);
325 pout
->u
.m
[1][1] = -2.0f
* zn
/ (b
- t
);
326 pout
->u
.m
[2][0] = 1.0f
+ 2.0f
* l
/ (r
- l
);
327 pout
->u
.m
[2][1] = -1.0f
-2.0f
* t
/ (b
- t
);
328 pout
->u
.m
[2][2] = zf
/ (zn
- zf
);
329 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
-zf
);
330 pout
->u
.m
[2][3] = -1.0f
;
331 pout
->u
.m
[3][3] = 0.0f
;
335 D3DXMATRIX
* WINAPI
D3DXMatrixPerspectiveRH(D3DXMATRIX
*pout
, FLOAT w
, FLOAT h
, FLOAT zn
, FLOAT zf
)
337 D3DXMatrixIdentity(pout
);
338 pout
->u
.m
[0][0] = 2.0f
* zn
/ w
;
339 pout
->u
.m
[1][1] = 2.0f
* zn
/ h
;
340 pout
->u
.m
[2][2] = zf
/ (zn
- zf
);
341 pout
->u
.m
[3][2] = (zn
* zf
) / (zn
- zf
);
342 pout
->u
.m
[2][3] = -1.0f
;
343 pout
->u
.m
[3][3] = 0.0f
;
347 D3DXMATRIX
* WINAPI
D3DXMatrixReflect(D3DXMATRIX
*pout
, CONST D3DXPLANE
*pplane
)
351 D3DXPlaneNormalize(&Nplane
, pplane
);
352 D3DXMatrixIdentity(pout
);
353 pout
->u
.m
[0][0] = 1.0f
- 2.0f
* Nplane
.a
* Nplane
.a
;
354 pout
->u
.m
[0][1] = -2.0f
* Nplane
.a
* Nplane
.b
;
355 pout
->u
.m
[0][2] = -2.0f
* Nplane
.a
* Nplane
.c
;
356 pout
->u
.m
[1][0] = -2.0f
* Nplane
.a
* Nplane
.b
;
357 pout
->u
.m
[1][1] = 1.0f
- 2.0f
* Nplane
.b
* Nplane
.b
;
358 pout
->u
.m
[1][2] = -2.0f
* Nplane
.b
* Nplane
.c
;
359 pout
->u
.m
[2][0] = -2.0f
* Nplane
.c
* Nplane
.a
;
360 pout
->u
.m
[2][1] = -2.0f
* Nplane
.c
* Nplane
.b
;
361 pout
->u
.m
[2][2] = 1.0f
- 2.0f
* Nplane
.c
* Nplane
.c
;
362 pout
->u
.m
[3][0] = -2.0f
* Nplane
.d
* Nplane
.a
;
363 pout
->u
.m
[3][1] = -2.0f
* Nplane
.d
* Nplane
.b
;
364 pout
->u
.m
[3][2] = -2.0f
* Nplane
.d
* Nplane
.c
;
368 D3DXMATRIX
* WINAPI
D3DXMatrixRotationAxis(D3DXMATRIX
*pout
, CONST D3DXVECTOR3
*pv
, FLOAT angle
)
372 D3DXVec3Normalize(&v
,pv
);
373 D3DXMatrixIdentity(pout
);
374 pout
->u
.m
[0][0] = (1.0f
- cos(angle
)) * v
.x
* v
.x
+ cos(angle
);
375 pout
->u
.m
[1][0] = (1.0f
- cos(angle
)) * v
.x
* v
.y
- sin(angle
) * v
.z
;
376 pout
->u
.m
[2][0] = (1.0f
- cos(angle
)) * v
.x
* v
.z
+ sin(angle
) * v
.y
;
377 pout
->u
.m
[0][1] = (1.0f
- cos(angle
)) * v
.y
* v
.x
+ sin(angle
) * v
.z
;
378 pout
->u
.m
[1][1] = (1.0f
- cos(angle
)) * v
.y
* v
.y
+ cos(angle
);
379 pout
->u
.m
[2][1] = (1.0f
- cos(angle
)) * v
.y
* v
.z
- sin(angle
) * v
.x
;
380 pout
->u
.m
[0][2] = (1.0f
- cos(angle
)) * v
.z
* v
.x
- sin(angle
) * v
.y
;
381 pout
->u
.m
[1][2] = (1.0f
- cos(angle
)) * v
.z
* v
.y
+ sin(angle
) * v
.x
;
382 pout
->u
.m
[2][2] = (1.0f
- cos(angle
)) * v
.z
* v
.z
+ cos(angle
);
386 D3DXMATRIX
* WINAPI
D3DXMatrixRotationQuaternion(D3DXMATRIX
*pout
, CONST D3DXQUATERNION
*pq
)
388 D3DXMatrixIdentity(pout
);
389 pout
->u
.m
[0][0] = 1.0f
- 2.0f
* (pq
->y
* pq
->y
+ pq
->z
* pq
->z
);
390 pout
->u
.m
[0][1] = 2.0f
* (pq
->x
*pq
->y
+ pq
->z
* pq
->w
);
391 pout
->u
.m
[0][2] = 2.0f
* (pq
->x
* pq
->z
- pq
->y
* pq
->w
);
392 pout
->u
.m
[1][0] = 2.0f
* (pq
->x
* pq
->y
- pq
->z
* pq
->w
);
393 pout
->u
.m
[1][1] = 1.0f
- 2.0f
* (pq
->x
* pq
->x
+ pq
->z
* pq
->z
);
394 pout
->u
.m
[1][2] = 2.0f
* (pq
->y
*pq
->z
+ pq
->x
*pq
->w
);
395 pout
->u
.m
[2][0] = 2.0f
* (pq
->x
* pq
->z
+ pq
->y
* pq
->w
);
396 pout
->u
.m
[2][1] = 2.0f
* (pq
->y
*pq
->z
- pq
->x
*pq
->w
);
397 pout
->u
.m
[2][2] = 1.0f
- 2.0f
* (pq
->x
* pq
->x
+ pq
->y
* pq
->y
);
401 D3DXMATRIX
* WINAPI
D3DXMatrixRotationX(D3DXMATRIX
*pout
, FLOAT angle
)
403 D3DXMatrixIdentity(pout
);
404 pout
->u
.m
[1][1] = cos(angle
);
405 pout
->u
.m
[2][2] = cos(angle
);
406 pout
->u
.m
[1][2] = sin(angle
);
407 pout
->u
.m
[2][1] = -sin(angle
);
411 D3DXMATRIX
* WINAPI
D3DXMatrixRotationY(D3DXMATRIX
*pout
, FLOAT angle
)
413 D3DXMatrixIdentity(pout
);
414 pout
->u
.m
[0][0] = cos(angle
);
415 pout
->u
.m
[2][2] = cos(angle
);
416 pout
->u
.m
[0][2] = -sin(angle
);
417 pout
->u
.m
[2][0] = sin(angle
);
421 D3DXMATRIX
* WINAPI
D3DXMatrixRotationYawPitchRoll(D3DXMATRIX
*pout
, FLOAT yaw
, FLOAT pitch
, FLOAT roll
)
425 D3DXMatrixIdentity(pout
);
426 D3DXMatrixRotationZ(&m
, roll
);
427 D3DXMatrixMultiply(pout
, pout
, &m
);
428 D3DXMatrixRotationX(&m
, pitch
);
429 D3DXMatrixMultiply(pout
, pout
, &m
);
430 D3DXMatrixRotationY(&m
, yaw
);
431 D3DXMatrixMultiply(pout
, pout
, &m
);
434 D3DXMATRIX
* WINAPI
D3DXMatrixRotationZ(D3DXMATRIX
*pout
, FLOAT angle
)
436 D3DXMatrixIdentity(pout
);
437 pout
->u
.m
[0][0] = cos(angle
);
438 pout
->u
.m
[1][1] = cos(angle
);
439 pout
->u
.m
[0][1] = sin(angle
);
440 pout
->u
.m
[1][0] = -sin(angle
);
444 D3DXMATRIX
* WINAPI
D3DXMatrixScaling(D3DXMATRIX
*pout
, FLOAT sx
, FLOAT sy
, FLOAT sz
)
446 D3DXMatrixIdentity(pout
);
447 pout
->u
.m
[0][0] = sx
;
448 pout
->u
.m
[1][1] = sy
;
449 pout
->u
.m
[2][2] = sz
;
453 D3DXMATRIX
* WINAPI
D3DXMatrixShadow(D3DXMATRIX
*pout
, CONST D3DXVECTOR4
*plight
, CONST D3DXPLANE
*pplane
)
458 D3DXPlaneNormalize(&Nplane
, pplane
);
459 dot
= D3DXPlaneDot(&Nplane
, plight
);
460 pout
->u
.m
[0][0] = dot
- Nplane
.a
* plight
->x
;
461 pout
->u
.m
[0][1] = -Nplane
.a
* plight
->y
;
462 pout
->u
.m
[0][2] = -Nplane
.a
* plight
->z
;
463 pout
->u
.m
[0][3] = -Nplane
.a
* plight
->w
;
464 pout
->u
.m
[1][0] = -Nplane
.b
* plight
->x
;
465 pout
->u
.m
[1][1] = dot
- Nplane
.b
* plight
->y
;
466 pout
->u
.m
[1][2] = -Nplane
.b
* plight
->z
;
467 pout
->u
.m
[1][3] = -Nplane
.b
* plight
->w
;
468 pout
->u
.m
[2][0] = -Nplane
.c
* plight
->x
;
469 pout
->u
.m
[2][1] = -Nplane
.c
* plight
->y
;
470 pout
->u
.m
[2][2] = dot
- Nplane
.c
* plight
->z
;
471 pout
->u
.m
[2][3] = -Nplane
.c
* plight
->w
;
472 pout
->u
.m
[3][0] = -Nplane
.d
* plight
->x
;
473 pout
->u
.m
[3][1] = -Nplane
.d
* plight
->y
;
474 pout
->u
.m
[3][2] = -Nplane
.d
* plight
->z
;
475 pout
->u
.m
[3][3] = dot
- Nplane
.d
* plight
->w
;
479 D3DXMATRIX
* WINAPI
D3DXMatrixTransformation(D3DXMATRIX
*pout
, CONST D3DXVECTOR3
*pscalingcenter
, CONST D3DXQUATERNION
*pscalingrotation
, CONST D3DXVECTOR3
*pscaling
, CONST D3DXVECTOR3
*protationcenter
, CONST D3DXQUATERNION
*protation
, CONST D3DXVECTOR3
*ptranslation
)
481 D3DXMATRIX m1
, m2
, m3
, m4
, m5
, m6
, m7
;
485 if ( !pscalingcenter
)
493 psc
.x
= pscalingcenter
->x
;
494 psc
.y
= pscalingcenter
->y
;
495 psc
.z
= pscalingcenter
->z
;
497 if ( !protationcenter
)
505 prc
.x
= protationcenter
->x
;
506 prc
.y
= protationcenter
->y
;
507 prc
.z
= protationcenter
->z
;
517 pt
.x
= ptranslation
->x
;
518 pt
.y
= ptranslation
->y
;
519 pt
.z
= ptranslation
->z
;
521 D3DXMatrixTranslation(&m1
, -psc
.x
, -psc
.y
, -psc
.z
);
522 if ( !pscalingrotation
)
524 D3DXMatrixIdentity(&m2
);
525 D3DXMatrixIdentity(&m4
);
529 D3DXMatrixRotationQuaternion(&m4
, pscalingrotation
);
530 D3DXMatrixInverse(&m2
, NULL
, &m4
);
534 D3DXMatrixIdentity(&m3
);
538 D3DXMatrixScaling(&m3
, pscaling
->x
, pscaling
->y
, pscaling
->z
);
542 D3DXMatrixIdentity(&m6
);
546 D3DXMatrixRotationQuaternion(&m6
, protation
);
548 D3DXMatrixTranslation(&m5
, psc
.x
- prc
.x
, psc
.y
- prc
.y
, psc
.z
- prc
.z
);
549 D3DXMatrixTranslation(&m7
, prc
.x
+ pt
.x
, prc
.y
+ pt
.y
, prc
.z
+ pt
.z
);
550 D3DXMatrixMultiply(&m1
, &m1
, &m2
);
551 D3DXMatrixMultiply(&m1
, &m1
, &m3
);
552 D3DXMatrixMultiply(&m1
, &m1
, &m4
);
553 D3DXMatrixMultiply(&m1
, &m1
, &m5
);
554 D3DXMatrixMultiply(&m1
, &m1
, &m6
);
555 D3DXMatrixMultiply(pout
, &m1
, &m7
);
559 D3DXMATRIX
* WINAPI
D3DXMatrixTranslation(D3DXMATRIX
*pout
, FLOAT x
, FLOAT y
, FLOAT z
)
561 D3DXMatrixIdentity(pout
);
568 D3DXMATRIX
* WINAPI
D3DXMatrixTranspose(D3DXMATRIX
*pout
, CONST D3DXMATRIX
*pm
)
570 CONST D3DXMATRIX m
= *pm
;
577 pout
->u
.m
[i
][j
] = m
.u
.m
[j
][i
];
583 /*_________________D3DXMatrixStack____________________*/
585 static const unsigned int INITIAL_STACK_SIZE
= 32;
587 HRESULT WINAPI
D3DXCreateMatrixStack(DWORD flags
, LPD3DXMATRIXSTACK
* ppstack
)
589 ID3DXMatrixStackImpl
* object
;
591 TRACE("flags %#x, ppstack %p\n", flags
, ppstack
);
593 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ID3DXMatrixStackImpl
));
594 if ( object
== NULL
)
597 return E_OUTOFMEMORY
;
599 object
->lpVtbl
= &ID3DXMatrixStack_Vtbl
;
602 object
->stack
= HeapAlloc(GetProcessHeap(), 0, INITIAL_STACK_SIZE
* sizeof(D3DXMATRIX
));
605 HeapFree(GetProcessHeap(), 0, object
);
607 return E_OUTOFMEMORY
;
611 object
->stack_size
= INITIAL_STACK_SIZE
;
612 D3DXMatrixIdentity(&object
->stack
[0]);
614 TRACE("Created matrix stack %p\n", object
);
616 *ppstack
= (LPD3DXMATRIXSTACK
)object
;
620 static HRESULT WINAPI
ID3DXMatrixStackImpl_QueryInterface(ID3DXMatrixStack
*iface
, REFIID riid
, void **ppobj
)
622 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
623 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ID3DXMatrixStack
))
625 ID3DXMatrixStack_AddRef(iface
);
630 ERR("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
631 return E_NOINTERFACE
;
634 static ULONG WINAPI
ID3DXMatrixStackImpl_AddRef(ID3DXMatrixStack
*iface
)
636 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
637 ULONG ref
= InterlockedIncrement(&This
->ref
);
638 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
642 static ULONG WINAPI
ID3DXMatrixStackImpl_Release(ID3DXMatrixStack
* iface
)
644 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
645 ULONG ref
= InterlockedDecrement(&This
->ref
);
648 HeapFree(GetProcessHeap(), 0, This
->stack
);
649 HeapFree(GetProcessHeap(), 0, This
);
651 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
655 static D3DXMATRIX
* WINAPI
ID3DXMatrixStackImpl_GetTop(ID3DXMatrixStack
*iface
)
657 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
659 TRACE("iface %p\n", iface
);
661 return &This
->stack
[This
->current
];
664 static HRESULT WINAPI
ID3DXMatrixStackImpl_LoadIdentity(ID3DXMatrixStack
*iface
)
666 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
668 TRACE("iface %p\n", iface
);
670 D3DXMatrixIdentity(&This
->stack
[This
->current
]);
675 static HRESULT WINAPI
ID3DXMatrixStackImpl_LoadMatrix(ID3DXMatrixStack
*iface
, CONST D3DXMATRIX
*pm
)
677 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
679 TRACE("iface %p\n", iface
);
681 if (!pm
) return D3DERR_INVALIDCALL
;
682 This
->stack
[This
->current
] = *pm
;
687 static HRESULT WINAPI
ID3DXMatrixStackImpl_MultMatrix(ID3DXMatrixStack
*iface
, CONST D3DXMATRIX
*pm
)
689 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
691 TRACE("iface %p\n", iface
);
693 if (!pm
) return D3DERR_INVALIDCALL
;
694 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], pm
);
699 static HRESULT WINAPI
ID3DXMatrixStackImpl_MultMatrixLocal(ID3DXMatrixStack
*iface
, CONST D3DXMATRIX
*pm
)
701 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
703 TRACE("iface %p\n", iface
);
705 if (!pm
) return D3DERR_INVALIDCALL
;
706 D3DXMatrixMultiply(&This
->stack
[This
->current
], pm
, &This
->stack
[This
->current
]);
711 static HRESULT WINAPI
ID3DXMatrixStackImpl_Pop(ID3DXMatrixStack
*iface
)
713 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
715 TRACE("iface %p\n", iface
);
717 /* Popping the last element on the stack returns D3D_OK, but does nothing. */
718 if (!This
->current
) return D3D_OK
;
720 if (This
->current
<= This
->stack_size
/ 4 && This
->stack_size
>= INITIAL_STACK_SIZE
* 2)
722 unsigned int new_size
;
723 D3DXMATRIX
*new_stack
;
725 new_size
= This
->stack_size
/ 2;
726 new_stack
= HeapReAlloc(GetProcessHeap(), 0, This
->stack
, new_size
* sizeof(D3DXMATRIX
));
729 This
->stack_size
= new_size
;
730 This
->stack
= new_stack
;
739 static HRESULT WINAPI
ID3DXMatrixStackImpl_Push(ID3DXMatrixStack
*iface
)
741 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
743 TRACE("iface %p\n", iface
);
745 if (This
->current
== This
->stack_size
- 1)
747 unsigned int new_size
;
748 D3DXMATRIX
*new_stack
;
750 if (This
->stack_size
> UINT_MAX
/ 2) return E_OUTOFMEMORY
;
752 new_size
= This
->stack_size
* 2;
753 new_stack
= HeapReAlloc(GetProcessHeap(), 0, This
->stack
, new_size
* sizeof(D3DXMATRIX
));
754 if (!new_stack
) return E_OUTOFMEMORY
;
756 This
->stack_size
= new_size
;
757 This
->stack
= new_stack
;
761 This
->stack
[This
->current
] = This
->stack
[This
->current
- 1];
766 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateAxis(ID3DXMatrixStack
*iface
, CONST D3DXVECTOR3
*pv
, FLOAT angle
)
769 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
771 TRACE("iface %p\n", iface
);
773 if (!pv
) return D3DERR_INVALIDCALL
;
774 D3DXMatrixRotationAxis(&temp
, pv
, angle
);
775 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
780 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateAxisLocal(ID3DXMatrixStack
*iface
, CONST D3DXVECTOR3
*pv
, FLOAT angle
)
783 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
785 TRACE("iface %p\n", iface
);
787 if (!pv
) return D3DERR_INVALIDCALL
;
788 D3DXMatrixRotationAxis(&temp
, pv
, angle
);
789 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
, &This
->stack
[This
->current
]);
794 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateYawPitchRoll(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
797 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
799 TRACE("iface %p\n", iface
);
801 D3DXMatrixRotationYawPitchRoll(&temp
, x
, y
, z
);
802 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
807 static HRESULT WINAPI
ID3DXMatrixStackImpl_RotateYawPitchRollLocal(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
810 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
812 TRACE("iface %p\n", iface
);
814 D3DXMatrixRotationYawPitchRoll(&temp
, x
, y
, z
);
815 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
, &This
->stack
[This
->current
]);
820 static HRESULT WINAPI
ID3DXMatrixStackImpl_Scale(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
823 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
825 TRACE("iface %p\n", iface
);
827 D3DXMatrixScaling(&temp
, x
, y
, z
);
828 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
833 static HRESULT WINAPI
ID3DXMatrixStackImpl_ScaleLocal(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
836 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
838 TRACE("iface %p\n", iface
);
840 D3DXMatrixScaling(&temp
, x
, y
, z
);
841 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
, &This
->stack
[This
->current
]);
846 static HRESULT WINAPI
ID3DXMatrixStackImpl_Translate(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
849 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
851 TRACE("iface %p\n", iface
);
853 D3DXMatrixTranslation(&temp
, x
, y
, z
);
854 D3DXMatrixMultiply(&This
->stack
[This
->current
], &This
->stack
[This
->current
], &temp
);
859 static HRESULT WINAPI
ID3DXMatrixStackImpl_TranslateLocal(ID3DXMatrixStack
*iface
, FLOAT x
, FLOAT y
, FLOAT z
)
862 ID3DXMatrixStackImpl
*This
= (ID3DXMatrixStackImpl
*)iface
;
864 TRACE("iface %p\n", iface
);
866 D3DXMatrixTranslation(&temp
, x
, y
, z
);
867 D3DXMatrixMultiply(&This
->stack
[This
->current
], &temp
,&This
->stack
[This
->current
]);
872 static const ID3DXMatrixStackVtbl ID3DXMatrixStack_Vtbl
=
874 ID3DXMatrixStackImpl_QueryInterface
,
875 ID3DXMatrixStackImpl_AddRef
,
876 ID3DXMatrixStackImpl_Release
,
877 ID3DXMatrixStackImpl_Pop
,
878 ID3DXMatrixStackImpl_Push
,
879 ID3DXMatrixStackImpl_LoadIdentity
,
880 ID3DXMatrixStackImpl_LoadMatrix
,
881 ID3DXMatrixStackImpl_MultMatrix
,
882 ID3DXMatrixStackImpl_MultMatrixLocal
,
883 ID3DXMatrixStackImpl_RotateAxis
,
884 ID3DXMatrixStackImpl_RotateAxisLocal
,
885 ID3DXMatrixStackImpl_RotateYawPitchRoll
,
886 ID3DXMatrixStackImpl_RotateYawPitchRollLocal
,
887 ID3DXMatrixStackImpl_Scale
,
888 ID3DXMatrixStackImpl_ScaleLocal
,
889 ID3DXMatrixStackImpl_Translate
,
890 ID3DXMatrixStackImpl_TranslateLocal
,
891 ID3DXMatrixStackImpl_GetTop
894 /*_________________D3DXPLANE________________*/
896 D3DXPLANE
* WINAPI
D3DXPlaneFromPointNormal(D3DXPLANE
*pout
, CONST D3DXVECTOR3
*pvpoint
, CONST D3DXVECTOR3
*pvnormal
)
898 pout
->a
= pvnormal
->x
;
899 pout
->b
= pvnormal
->y
;
900 pout
->c
= pvnormal
->z
;
901 pout
->d
= -D3DXVec3Dot(pvpoint
, pvnormal
);
905 D3DXPLANE
* WINAPI
D3DXPlaneFromPoints(D3DXPLANE
*pout
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pv3
)
907 D3DXVECTOR3 edge1
, edge2
, normal
, Nnormal
;
909 edge1
.x
= 0.0f
; edge1
.y
= 0.0f
; edge1
.z
= 0.0f
;
910 edge2
.x
= 0.0f
; edge2
.y
= 0.0f
; edge2
.z
= 0.0f
;
911 D3DXVec3Subtract(&edge1
, pv2
, pv1
);
912 D3DXVec3Subtract(&edge2
, pv3
, pv1
);
913 D3DXVec3Cross(&normal
, &edge1
, &edge2
);
914 D3DXVec3Normalize(&Nnormal
, &normal
);
915 D3DXPlaneFromPointNormal(pout
, pv1
, &Nnormal
);
919 D3DXVECTOR3
* WINAPI
D3DXPlaneIntersectLine(D3DXVECTOR3
*pout
, CONST D3DXPLANE
*pp
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
)
921 D3DXVECTOR3 direction
, normal
;
927 direction
.x
= pv2
->x
- pv1
->x
;
928 direction
.y
= pv2
->y
- pv1
->y
;
929 direction
.z
= pv2
->z
- pv1
->z
;
930 dot
= D3DXVec3Dot(&normal
, &direction
);
931 if ( !dot
) return NULL
;
932 temp
= ( pp
->d
+ D3DXVec3Dot(&normal
, pv1
) ) / dot
;
933 pout
->x
= pv1
->x
- temp
* direction
.x
;
934 pout
->y
= pv1
->y
- temp
* direction
.y
;
935 pout
->z
= pv1
->z
- temp
* direction
.z
;
939 D3DXPLANE
* WINAPI
D3DXPlaneNormalize(D3DXPLANE
*pout
, CONST D3DXPLANE
*pp
)
943 norm
= sqrt(pp
->a
* pp
->a
+ pp
->b
* pp
->b
+ pp
->c
* pp
->c
);
946 pout
->a
= pp
->a
/ norm
;
947 pout
->b
= pp
->b
/ norm
;
948 pout
->c
= pp
->c
/ norm
;
949 pout
->d
= pp
->d
/ norm
;
961 D3DXPLANE
* WINAPI
D3DXPlaneTransform(D3DXPLANE
*pout
, CONST D3DXPLANE
*pplane
, CONST D3DXMATRIX
*pm
)
963 CONST D3DXPLANE plane
= *pplane
;
964 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
;
965 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
;
966 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
;
967 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
;
971 /*_________________D3DXQUATERNION________________*/
973 D3DXQUATERNION
* WINAPI
D3DXQuaternionBaryCentric(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq1
, CONST D3DXQUATERNION
*pq2
, CONST D3DXQUATERNION
*pq3
, FLOAT f
, FLOAT g
)
975 D3DXQUATERNION temp1
, temp2
;
976 D3DXQuaternionSlerp(pout
, D3DXQuaternionSlerp(&temp1
, pq1
, pq2
, f
+ g
), D3DXQuaternionSlerp(&temp2
, pq1
, pq3
, f
+g
), g
/ (f
+ g
));
980 D3DXQUATERNION
* WINAPI
D3DXQuaternionExp(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq
)
984 norm
= sqrt(pq
->x
* pq
->x
+ pq
->y
* pq
->y
+ pq
->z
* pq
->z
);
987 pout
->x
= sin(norm
) * pq
->x
/ norm
;
988 pout
->y
= sin(norm
) * pq
->y
/ norm
;
989 pout
->z
= sin(norm
) * pq
->z
/ norm
;
1002 D3DXQUATERNION
* WINAPI
D3DXQuaternionInverse(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq
)
1006 norm
= D3DXQuaternionLengthSq(pq
);
1016 pout
->x
= -pq
->x
/ norm
;
1017 pout
->y
= -pq
->y
/ norm
;
1018 pout
->z
= -pq
->z
/ norm
;
1019 pout
->w
= pq
->w
/ norm
;
1024 D3DXQUATERNION
* WINAPI
D3DXQuaternionLn(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq
)
1026 FLOAT norm
, normvec
, theta
;
1028 norm
= D3DXQuaternionLengthSq(pq
);
1029 if ( norm
> 1.0001f
)
1036 else if( norm
> 0.99999f
)
1038 normvec
= sqrt( pq
->x
* pq
->x
+ pq
->y
* pq
->y
+ pq
->z
* pq
->z
);
1039 theta
= atan2(normvec
, pq
->w
) / normvec
;
1040 pout
->x
= theta
* pq
->x
;
1041 pout
->y
= theta
* pq
->y
;
1042 pout
->z
= theta
* pq
->z
;
1047 FIXME("The quaternion (%f, %f, %f, %f) has a norm <1. This should not happen. Windows returns a result anyway. This case is not implemented yet.\n", pq
->x
, pq
->y
, pq
->z
, pq
->w
);
1052 D3DXQUATERNION
* WINAPI
D3DXQuaternionMultiply(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq1
, CONST D3DXQUATERNION
*pq2
)
1055 out
.x
= pq2
->w
* pq1
->x
+ pq2
->x
* pq1
->w
+ pq2
->y
* pq1
->z
- pq2
->z
* pq1
->y
;
1056 out
.y
= pq2
->w
* pq1
->y
- pq2
->x
* pq1
->z
+ pq2
->y
* pq1
->w
+ pq2
->z
* pq1
->x
;
1057 out
.z
= pq2
->w
* pq1
->z
+ pq2
->x
* pq1
->y
- pq2
->y
* pq1
->x
+ pq2
->z
* pq1
->w
;
1058 out
.w
= pq2
->w
* pq1
->w
- pq2
->x
* pq1
->x
- pq2
->y
* pq1
->y
- pq2
->z
* pq1
->z
;
1063 D3DXQUATERNION
* WINAPI
D3DXQuaternionNormalize(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq
)
1067 norm
= D3DXQuaternionLength(pq
);
1077 pout
->x
= pq
->x
/ norm
;
1078 pout
->y
= pq
->y
/ norm
;
1079 pout
->z
= pq
->z
/ norm
;
1080 pout
->w
= pq
->w
/ norm
;
1085 D3DXQUATERNION
* WINAPI
D3DXQuaternionRotationAxis(D3DXQUATERNION
*pout
, CONST D3DXVECTOR3
*pv
, FLOAT angle
)
1089 D3DXVec3Normalize(&temp
, pv
);
1090 pout
->x
= sin( angle
/ 2.0f
) * temp
.x
;
1091 pout
->y
= sin( angle
/ 2.0f
) * temp
.y
;
1092 pout
->z
= sin( angle
/ 2.0f
) * temp
.z
;
1093 pout
->w
= cos( angle
/ 2.0f
);
1097 D3DXQUATERNION
* WINAPI
D3DXQuaternionRotationMatrix(D3DXQUATERNION
*pout
, CONST D3DXMATRIX
*pm
)
1100 FLOAT maxdiag
, S
, trace
;
1102 trace
= pm
->u
.m
[0][0] + pm
->u
.m
[1][1] + pm
->u
.m
[2][2] + 1.0f
;
1105 pout
->x
= ( pm
->u
.m
[1][2] - pm
->u
.m
[2][1] ) / ( 2.0f
* sqrt(trace
) );
1106 pout
->y
= ( pm
->u
.m
[2][0] - pm
->u
.m
[0][2] ) / ( 2.0f
* sqrt(trace
) );
1107 pout
->z
= ( pm
->u
.m
[0][1] - pm
->u
.m
[1][0] ) / ( 2.0f
* sqrt(trace
) );
1108 pout
->w
= sqrt(trace
) / 2.0f
;
1112 maxdiag
= pm
->u
.m
[0][0];
1115 if ( pm
->u
.m
[i
][i
] > maxdiag
)
1118 maxdiag
= pm
->u
.m
[i
][i
];
1124 S
= 2.0f
* sqrt(1.0f
+ pm
->u
.m
[0][0] - pm
->u
.m
[1][1] - pm
->u
.m
[2][2]);
1125 pout
->x
= 0.25f
* S
;
1126 pout
->y
= ( pm
->u
.m
[0][1] + pm
->u
.m
[1][0] ) / S
;
1127 pout
->z
= ( pm
->u
.m
[0][2] + pm
->u
.m
[2][0] ) / S
;
1128 pout
->w
= ( pm
->u
.m
[1][2] - pm
->u
.m
[2][1] ) / S
;
1131 S
= 2.0f
* sqrt(1.0f
+ pm
->u
.m
[1][1] - pm
->u
.m
[0][0] - pm
->u
.m
[2][2]);
1132 pout
->x
= ( pm
->u
.m
[0][1] + pm
->u
.m
[1][0] ) / S
;
1133 pout
->y
= 0.25f
* S
;
1134 pout
->z
= ( pm
->u
.m
[1][2] + pm
->u
.m
[2][1] ) / S
;
1135 pout
->w
= ( pm
->u
.m
[2][0] - pm
->u
.m
[0][2] ) / S
;
1138 S
= 2.0f
* sqrt(1.0f
+ pm
->u
.m
[2][2] - pm
->u
.m
[0][0] - pm
->u
.m
[1][1]);
1139 pout
->x
= ( pm
->u
.m
[0][2] + pm
->u
.m
[2][0] ) / S
;
1140 pout
->y
= ( pm
->u
.m
[1][2] + pm
->u
.m
[2][1] ) / S
;
1141 pout
->z
= 0.25f
* S
;
1142 pout
->w
= ( pm
->u
.m
[0][1] - pm
->u
.m
[1][0] ) / S
;
1148 D3DXQUATERNION
* WINAPI
D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION
*pout
, FLOAT yaw
, FLOAT pitch
, FLOAT roll
)
1150 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
);
1151 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
);
1152 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
);
1153 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
);
1157 D3DXQUATERNION
* WINAPI
D3DXQuaternionSlerp(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq1
, CONST D3DXQUATERNION
*pq2
, FLOAT t
)
1162 dot
= D3DXQuaternionDot(pq1
, pq2
);
1163 if ( dot
< 0.0f
) epsilon
= -1.0f
;
1164 pout
->x
= (1.0f
- t
) * pq1
->x
+ epsilon
* t
* pq2
->x
;
1165 pout
->y
= (1.0f
- t
) * pq1
->y
+ epsilon
* t
* pq2
->y
;
1166 pout
->z
= (1.0f
- t
) * pq1
->z
+ epsilon
* t
* pq2
->z
;
1167 pout
->w
= (1.0f
- t
) * pq1
->w
+ epsilon
* t
* pq2
->w
;
1171 D3DXQUATERNION
* WINAPI
D3DXQuaternionSquad(D3DXQUATERNION
*pout
, CONST D3DXQUATERNION
*pq1
, CONST D3DXQUATERNION
*pq2
, CONST D3DXQUATERNION
*pq3
, CONST D3DXQUATERNION
*pq4
, FLOAT t
)
1173 D3DXQUATERNION temp1
, temp2
;
1175 D3DXQuaternionSlerp(pout
, D3DXQuaternionSlerp(&temp1
, pq1
, pq4
, t
), D3DXQuaternionSlerp(&temp2
, pq2
, pq3
, t
), 2.0f
* t
* (1.0f
- t
));
1179 void WINAPI
D3DXQuaternionToAxisAngle(CONST D3DXQUATERNION
*pq
, D3DXVECTOR3
*paxis
, FLOAT
*pangle
)
1184 norm
= D3DXQuaternionLength(pq
);
1187 paxis
->x
= pq
->x
/ norm
;
1188 paxis
->y
= pq
->y
/ norm
;
1189 paxis
->z
= pq
->z
/ norm
;
1190 if ( fabs( pq
->w
) <= 1.0f
) *pangle
= 2.0f
* acos(pq
->w
);
1200 /*_________________D3DXVec2_____________________*/
1202 D3DXVECTOR2
* WINAPI
D3DXVec2BaryCentric(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv1
, CONST D3DXVECTOR2
*pv2
, CONST D3DXVECTOR2
*pv3
, FLOAT f
, FLOAT g
)
1204 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
1205 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
1209 D3DXVECTOR2
* WINAPI
D3DXVec2CatmullRom(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv0
, CONST D3DXVECTOR2
*pv1
, CONST D3DXVECTOR2
*pv2
, CONST D3DXVECTOR2
*pv3
, FLOAT s
)
1211 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
);
1212 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
);
1216 D3DXVECTOR2
* WINAPI
D3DXVec2Hermite(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv1
, CONST D3DXVECTOR2
*pt1
, CONST D3DXVECTOR2
*pv2
, CONST D3DXVECTOR2
*pt2
, FLOAT s
)
1218 FLOAT h1
, h2
, h3
, h4
;
1220 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
1221 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
1222 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
1223 h4
= s
* s
* s
- s
* s
;
1225 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
1226 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
1230 D3DXVECTOR2
* WINAPI
D3DXVec2Normalize(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv
)
1234 norm
= D3DXVec2Length(pv
);
1242 pout
->x
= pv
->x
/ norm
;
1243 pout
->y
= pv
->y
/ norm
;
1248 D3DXVECTOR4
* WINAPI
D3DXVec2Transform(D3DXVECTOR4
*pout
, CONST D3DXVECTOR2
*pv
, CONST D3DXMATRIX
*pm
)
1250 pout
->x
= pm
->u
.m
[0][0] * pv
->x
+ pm
->u
.m
[1][0] * pv
->y
+ pm
->u
.m
[3][0];
1251 pout
->y
= pm
->u
.m
[0][1] * pv
->x
+ pm
->u
.m
[1][1] * pv
->y
+ pm
->u
.m
[3][1];
1252 pout
->z
= pm
->u
.m
[0][2] * pv
->x
+ pm
->u
.m
[1][2] * pv
->y
+ pm
->u
.m
[3][2];
1253 pout
->w
= pm
->u
.m
[0][3] * pv
->x
+ pm
->u
.m
[1][3] * pv
->y
+ pm
->u
.m
[3][3];
1257 D3DXVECTOR2
* WINAPI
D3DXVec2TransformCoord(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv
, CONST D3DXMATRIX
*pm
)
1261 norm
= pm
->u
.m
[0][3] * pv
->x
+ pm
->u
.m
[1][3] * pv
->y
+ pm
->u
.m
[3][3];
1264 CONST D3DXVECTOR2 v
= *pv
;
1265 pout
->x
= (pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
+ pm
->u
.m
[3][0]) / norm
;
1266 pout
->y
= (pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
+ pm
->u
.m
[3][1]) / norm
;
1276 D3DXVECTOR2
* WINAPI
D3DXVec2TransformNormal(D3DXVECTOR2
*pout
, CONST D3DXVECTOR2
*pv
, CONST D3DXMATRIX
*pm
)
1278 CONST D3DXVECTOR2 v
= *pv
;
1279 pout
->x
= pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
;
1280 pout
->y
= pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
;
1284 /*_________________D3DXVec3_____________________*/
1286 D3DXVECTOR3
* WINAPI
D3DXVec3BaryCentric(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pv3
, FLOAT f
, FLOAT g
)
1288 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
1289 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
1290 pout
->z
= (1.0f
-f
-g
) * (pv1
->z
) + f
* (pv2
->z
) + g
* (pv3
->z
);
1294 D3DXVECTOR3
* WINAPI
D3DXVec3CatmullRom( D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv0
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pv3
, FLOAT s
)
1296 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
);
1297 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
);
1298 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
);
1302 D3DXVECTOR3
* WINAPI
D3DXVec3Hermite(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv1
, CONST D3DXVECTOR3
*pt1
, CONST D3DXVECTOR3
*pv2
, CONST D3DXVECTOR3
*pt2
, FLOAT s
)
1304 FLOAT h1
, h2
, h3
, h4
;
1306 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
1307 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
1308 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
1309 h4
= s
* s
* s
- s
* s
;
1311 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
1312 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
1313 pout
->z
= h1
* (pv1
->z
) + h2
* (pt1
->z
) + h3
* (pv2
->z
) + h4
* (pt2
->z
);
1317 D3DXVECTOR3
* WINAPI
D3DXVec3Normalize(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
)
1321 norm
= D3DXVec3Length(pv
);
1330 pout
->x
= pv
->x
/ norm
;
1331 pout
->y
= pv
->y
/ norm
;
1332 pout
->z
= pv
->z
/ norm
;
1337 D3DXVECTOR3
* WINAPI
D3DXVec3Project(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DVIEWPORT8
*pviewport
, CONST D3DXMATRIX
*pprojection
, CONST D3DXMATRIX
*pview
, CONST D3DXMATRIX
*pworld
)
1342 D3DXMatrixMultiply(&m1
, pworld
, pview
);
1343 D3DXMatrixMultiply(&m2
, &m1
, pprojection
);
1344 D3DXVec3TransformCoord(&vec
, pv
, &m2
);
1345 pout
->x
= pviewport
->X
+ ( 1.0f
+ vec
.x
) * pviewport
->Width
/ 2.0f
;
1346 pout
->y
= pviewport
->Y
+ ( 1.0f
- vec
.y
) * pviewport
->Height
/ 2.0f
;
1347 pout
->z
= pviewport
->MinZ
+ vec
.z
* ( pviewport
->MaxZ
- pviewport
->MinZ
);
1351 D3DXVECTOR4
* WINAPI
D3DXVec3Transform(D3DXVECTOR4
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DXMATRIX
*pm
)
1353 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];
1354 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];
1355 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];
1356 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];
1360 D3DXVECTOR3
* WINAPI
D3DXVec3TransformCoord(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DXMATRIX
*pm
)
1364 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];
1368 CONST D3DXVECTOR3 v
= *pv
;
1369 pout
->x
= (pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
+ pm
->u
.m
[2][0] * v
.z
+ pm
->u
.m
[3][0]) / norm
;
1370 pout
->y
= (pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
+ pm
->u
.m
[2][1] * v
.z
+ pm
->u
.m
[3][1]) / norm
;
1371 pout
->z
= (pm
->u
.m
[0][2] * v
.x
+ pm
->u
.m
[1][2] * v
.y
+ pm
->u
.m
[2][2] * v
.z
+ pm
->u
.m
[3][2]) / norm
;
1382 D3DXVECTOR3
* WINAPI
D3DXVec3TransformNormal(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DXMATRIX
*pm
)
1384 CONST D3DXVECTOR3 v
= *pv
;
1385 pout
->x
= pm
->u
.m
[0][0] * v
.x
+ pm
->u
.m
[1][0] * v
.y
+ pm
->u
.m
[2][0] * v
.z
;
1386 pout
->y
= pm
->u
.m
[0][1] * v
.x
+ pm
->u
.m
[1][1] * v
.y
+ pm
->u
.m
[2][1] * v
.z
;
1387 pout
->z
= pm
->u
.m
[0][2] * v
.x
+ pm
->u
.m
[1][2] * v
.y
+ pm
->u
.m
[2][2] * v
.z
;
1392 D3DXVECTOR3
* WINAPI
D3DXVec3Unproject(D3DXVECTOR3
*pout
, CONST D3DXVECTOR3
*pv
, CONST D3DVIEWPORT8
*pviewport
, CONST D3DXMATRIX
*pprojection
, CONST D3DXMATRIX
*pview
, CONST D3DXMATRIX
*pworld
)
1394 D3DXMATRIX m1
, m2
, m3
;
1397 D3DXMatrixMultiply(&m1
, pworld
, pview
);
1398 D3DXMatrixMultiply(&m2
, &m1
, pprojection
);
1399 D3DXMatrixInverse(&m3
, NULL
, &m2
);
1400 vec
.x
= 2.0f
* ( pv
->x
- pviewport
->X
) / pviewport
->Width
- 1.0f
;
1401 vec
.y
= 1.0f
- 2.0f
* ( pv
->y
- pviewport
->Y
) / pviewport
->Height
;
1402 vec
.z
= ( pv
->z
- pviewport
->MinZ
) / ( pviewport
->MaxZ
- pviewport
->MinZ
);
1403 D3DXVec3TransformCoord(pout
, &vec
, &m3
);
1407 /*_________________D3DXVec4_____________________*/
1409 D3DXVECTOR4
* WINAPI
D3DXVec4BaryCentric(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pv3
, FLOAT f
, FLOAT g
)
1411 pout
->x
= (1.0f
-f
-g
) * (pv1
->x
) + f
* (pv2
->x
) + g
* (pv3
->x
);
1412 pout
->y
= (1.0f
-f
-g
) * (pv1
->y
) + f
* (pv2
->y
) + g
* (pv3
->y
);
1413 pout
->z
= (1.0f
-f
-g
) * (pv1
->z
) + f
* (pv2
->z
) + g
* (pv3
->z
);
1414 pout
->w
= (1.0f
-f
-g
) * (pv1
->w
) + f
* (pv2
->w
) + g
* (pv3
->w
);
1418 D3DXVECTOR4
* WINAPI
D3DXVec4CatmullRom(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv0
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pv3
, FLOAT s
)
1420 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
);
1421 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
);
1422 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
);
1423 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
);
1427 D3DXVECTOR4
* WINAPI
D3DXVec4Cross(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pv3
)
1430 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
);
1431 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
));
1432 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
);
1433 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
));
1438 D3DXVECTOR4
* WINAPI
D3DXVec4Hermite(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv1
, CONST D3DXVECTOR4
*pt1
, CONST D3DXVECTOR4
*pv2
, CONST D3DXVECTOR4
*pt2
, FLOAT s
)
1440 FLOAT h1
, h2
, h3
, h4
;
1442 h1
= 2.0f
* s
* s
* s
- 3.0f
* s
* s
+ 1.0f
;
1443 h2
= s
* s
* s
- 2.0f
* s
* s
+ s
;
1444 h3
= -2.0f
* s
* s
* s
+ 3.0f
* s
* s
;
1445 h4
= s
* s
* s
- s
* s
;
1447 pout
->x
= h1
* (pv1
->x
) + h2
* (pt1
->x
) + h3
* (pv2
->x
) + h4
* (pt2
->x
);
1448 pout
->y
= h1
* (pv1
->y
) + h2
* (pt1
->y
) + h3
* (pv2
->y
) + h4
* (pt2
->y
);
1449 pout
->z
= h1
* (pv1
->z
) + h2
* (pt1
->z
) + h3
* (pv2
->z
) + h4
* (pt2
->z
);
1450 pout
->w
= h1
* (pv1
->w
) + h2
* (pt1
->w
) + h3
* (pv2
->w
) + h4
* (pt2
->w
);
1454 D3DXVECTOR4
* WINAPI
D3DXVec4Normalize(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv
)
1458 norm
= D3DXVec4Length(pv
);
1468 pout
->x
= pv
->x
/ norm
;
1469 pout
->y
= pv
->y
/ norm
;
1470 pout
->z
= pv
->z
/ norm
;
1471 pout
->w
= pv
->w
/ norm
;
1476 D3DXVECTOR4
* WINAPI
D3DXVec4Transform(D3DXVECTOR4
*pout
, CONST D3DXVECTOR4
*pv
, CONST D3DXMATRIX
*pm
)
1479 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
;
1480 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
;
1481 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
;
1482 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
;