setupapi: Fix if condition in SetupEnumInfSectionsA/W.
[wine/testsucceed.git] / dlls / d3dx9_36 / math.c
blob542e408d007eaa3d46cfdf0dde312220cc6a1aa5
1 /*
2 * Mathematical operations specific to D3DX9.
4 * Copyright (C) 2008 David Adam
5 * Copyright (C) 2008 Philip Nilsson
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
24 #include "config.h"
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "wine/debug.h"
28 #include "d3dx9.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
32 /*************************************************************************
33 * D3DXMatrixAffineTransformation2D
35 D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation2D(
36 D3DXMATRIX *pout, FLOAT scaling,
37 CONST D3DXVECTOR2 *protationcenter, FLOAT rotation,
38 CONST D3DXVECTOR2 *ptranslation)
40 D3DXQUATERNION rot;
41 D3DXVECTOR3 rot_center, trans;
43 rot.w=cos(rotation/2.0f);
44 rot.x=0.0f;
45 rot.y=0.0f;
46 rot.z=sin(rotation/2.0f);
48 if ( protationcenter )
50 rot_center.x=protationcenter->x;
51 rot_center.y=protationcenter->y;
52 rot_center.z=0.0f;
54 else
56 rot_center.x=0.0f;
57 rot_center.y=0.0f;
58 rot_center.z=0.0f;
61 if ( ptranslation )
63 trans.x=ptranslation->x;
64 trans.y=ptranslation->y;
65 trans.z=0.0f;
67 else
69 trans.x=0.0f;
70 trans.y=0.0f;
71 trans.z=0.0f;
74 D3DXMatrixAffineTransformation(pout, scaling, &rot_center, &rot, &trans);
76 return pout;
79 /*************************************************************************
80 * D3DXMatrixDecompose
82 HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutrotation, D3DXVECTOR3 *pouttranslation, D3DXMATRIX *pm)
84 D3DXMATRIX normalized;
85 D3DXVECTOR3 vec;
87 /*Compute the scaling part.*/
88 vec.x=pm->u.m[0][0];
89 vec.y=pm->u.m[0][1];
90 vec.z=pm->u.m[0][2];
91 poutscale->x=D3DXVec3Length(&vec);
93 vec.x=pm->u.m[1][0];
94 vec.y=pm->u.m[1][1];
95 vec.z=pm->u.m[1][2];
96 poutscale->y=D3DXVec3Length(&vec);
98 vec.x=pm->u.m[2][0];
99 vec.y=pm->u.m[2][1];
100 vec.z=pm->u.m[2][2];
101 poutscale->z=D3DXVec3Length(&vec);
103 /*Compute the translation part.*/
104 pouttranslation->x=pm->u.m[3][0];
105 pouttranslation->y=pm->u.m[3][1];
106 pouttranslation->z=pm->u.m[3][2];
108 /*Let's calculate the rotation now*/
109 if ( (poutscale->x == 0.0f) || (poutscale->y == 0.0f) || (poutscale->z == 0.0f) )
111 return D3DERR_INVALIDCALL;
114 normalized.u.m[0][0]=pm->u.m[0][0]/poutscale->x;
115 normalized.u.m[0][1]=pm->u.m[0][1]/poutscale->x;
116 normalized.u.m[0][2]=pm->u.m[0][2]/poutscale->x;
117 normalized.u.m[1][0]=pm->u.m[1][0]/poutscale->y;
118 normalized.u.m[1][1]=pm->u.m[1][1]/poutscale->y;
119 normalized.u.m[1][2]=pm->u.m[1][2]/poutscale->y;
120 normalized.u.m[2][0]=pm->u.m[2][0]/poutscale->z;
121 normalized.u.m[2][1]=pm->u.m[2][1]/poutscale->z;
122 normalized.u.m[2][2]=pm->u.m[2][2]/poutscale->z;
124 D3DXQuaternionRotationMatrix(poutrotation,&normalized);
125 return S_OK;
128 /*************************************************************************
129 * D3DXMatrixTransformation2D
131 D3DXMATRIX* WINAPI D3DXMatrixTransformation2D(
132 D3DXMATRIX *pout, CONST D3DXVECTOR2 *pscalingcenter,
133 FLOAT scalingrotation, CONST D3DXVECTOR2 *pscaling,
134 CONST D3DXVECTOR2 *protationcenter, FLOAT rotation,
135 CONST D3DXVECTOR2 *ptranslation)
137 D3DXQUATERNION rot, sca_rot;
138 D3DXVECTOR3 rot_center, sca, sca_center, trans;
140 if ( pscalingcenter )
142 sca_center.x=pscalingcenter->x;
143 sca_center.y=pscalingcenter->y;
144 sca_center.z=0.0f;
146 else
148 sca_center.x=0.0f;
149 sca_center.y=0.0f;
150 sca_center.z=0.0f;
153 if ( pscaling )
155 sca.x=pscaling->x;
156 sca.y=pscaling->y;
157 sca.z=0.0f;
159 else
161 sca.x=0.0f;
162 sca.y=0.0f;
163 sca.z=0.0f;
166 if ( protationcenter )
168 rot_center.x=protationcenter->x;
169 rot_center.y=protationcenter->y;
170 rot_center.z=0.0f;
172 else
174 rot_center.x=0.0f;
175 rot_center.y=0.0f;
176 rot_center.z=0.0f;
179 if ( ptranslation )
181 trans.x=ptranslation->x;
182 trans.y=ptranslation->y;
183 trans.z=0.0f;
185 else
187 trans.x=0.0f;
188 trans.y=0.0f;
189 trans.z=0.0f;
192 rot.w=cos(rotation/2.0f);
193 rot.x=0.0f;
194 rot.y=0.0f;
195 rot.z=sin(rotation/2.0f);
197 sca_rot.w=cos(scalingrotation/2.0f);
198 sca_rot.x=0.0f;
199 sca_rot.y=0.0f;
200 sca_rot.z=sin(scalingrotation/2.0f);
202 D3DXMatrixTransformation(pout, &sca_center, &sca_rot, &sca, &rot_center, &rot, &trans);
204 return pout;
207 /*************************************************************************
208 * D3DXPlaneTransformArray
210 D3DXPLANE* WINAPI D3DXPlaneTransformArray(
211 D3DXPLANE* out, UINT outstride, CONST D3DXPLANE* in, UINT instride,
212 CONST D3DXMATRIX* matrix, UINT elements)
214 UINT i;
215 TRACE("\n");
216 for (i = 0; i < elements; ++i) {
217 D3DXPlaneTransform(
218 (D3DXPLANE*)((char*)out + outstride * i),
219 (CONST D3DXPLANE*)((const char*)in + instride * i),
220 matrix);
222 return out;
225 /*************************************************************************
226 * D3DXVec2TransformArray
228 * Transform an array of vectors by a matrix.
230 D3DXVECTOR4* WINAPI D3DXVec2TransformArray(
231 D3DXVECTOR4* out, UINT outstride, CONST D3DXVECTOR2* in, UINT instride,
232 CONST D3DXMATRIX* matrix, UINT elements)
234 UINT i;
235 TRACE("\n");
236 for (i = 0; i < elements; ++i) {
237 D3DXVec2Transform(
238 (D3DXVECTOR4*)((char*)out + outstride * i),
239 (CONST D3DXVECTOR2*)((const char*)in + instride * i),
240 matrix);
242 return out;
245 /*************************************************************************
246 * D3DXVec2TransformCoordArray
248 D3DXVECTOR2* WINAPI D3DXVec2TransformCoordArray(
249 D3DXVECTOR2* out, UINT outstride, CONST D3DXVECTOR2* in, UINT instride,
250 CONST D3DXMATRIX* matrix, UINT elements)
252 UINT i;
253 TRACE("\n");
254 for (i = 0; i < elements; ++i) {
255 D3DXVec2TransformCoord(
256 (D3DXVECTOR2*)((char*)out + outstride * i),
257 (CONST D3DXVECTOR2*)((const char*)in + instride * i),
258 matrix);
260 return out;
263 /*************************************************************************
264 * D3DXVec2TransformNormalArray
266 D3DXVECTOR2* WINAPI D3DXVec2TransformNormalArray(
267 D3DXVECTOR2* out, UINT outstride, CONST D3DXVECTOR2 *in, UINT instride,
268 CONST D3DXMATRIX *matrix, UINT elements)
270 UINT i;
271 TRACE("\n");
272 for (i = 0; i < elements; ++i) {
273 D3DXVec2TransformNormal(
274 (D3DXVECTOR2*)((char*)out + outstride * i),
275 (CONST D3DXVECTOR2*)((const char*)in + instride * i),
276 matrix);
278 return out;
281 /*************************************************************************
282 * D3DXVec3ProjectArray
284 * Projects an array of vectors to the screen.
286 D3DXVECTOR3* WINAPI D3DXVec3ProjectArray(
287 D3DXVECTOR3* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
288 CONST D3DVIEWPORT9* viewport, CONST D3DXMATRIX* projection,
289 CONST D3DXMATRIX* view, CONST D3DXMATRIX* world, UINT elements)
291 UINT i;
292 TRACE("\n");
293 for (i = 0; i < elements; ++i) {
294 D3DXVec3Project(
295 (D3DXVECTOR3*)((char*)out + outstride * i),
296 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
297 viewport, projection, view, world);
299 return out;
302 /*************************************************************************
303 * D3DXVec3TransformArray
305 D3DXVECTOR4* WINAPI D3DXVec3TransformArray(
306 D3DXVECTOR4* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
307 CONST D3DXMATRIX* matrix, UINT elements)
309 UINT i;
310 TRACE("\n");
311 for (i = 0; i < elements; ++i) {
312 D3DXVec3Transform(
313 (D3DXVECTOR4*)((char*)out + outstride * i),
314 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
315 matrix);
317 return out;
320 /*************************************************************************
321 * D3DXVec3TransformCoordArray
323 D3DXVECTOR3* WINAPI D3DXVec3TransformCoordArray(
324 D3DXVECTOR3* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
325 CONST D3DXMATRIX* matrix, UINT elements)
327 UINT i;
328 TRACE("\n");
329 for (i = 0; i < elements; ++i) {
330 D3DXVec3TransformCoord(
331 (D3DXVECTOR3*)((char*)out + outstride * i),
332 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
333 matrix);
335 return out;
338 /*************************************************************************
339 * D3DXVec3TransformNormalArray
341 D3DXVECTOR3* WINAPI D3DXVec3TransformNormalArray(
342 D3DXVECTOR3* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
343 CONST D3DXMATRIX* matrix, UINT elements)
345 UINT i;
346 TRACE("\n");
347 for (i = 0; i < elements; ++i) {
348 D3DXVec3TransformNormal(
349 (D3DXVECTOR3*)((char*)out + outstride * i),
350 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
351 matrix);
353 return out;
356 /*************************************************************************
357 * D3DXVec3UnprojectArray
359 D3DXVECTOR3* WINAPI D3DXVec3UnprojectArray(
360 D3DXVECTOR3* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
361 CONST D3DVIEWPORT9* viewport, CONST D3DXMATRIX* projection,
362 CONST D3DXMATRIX* view, CONST D3DXMATRIX* world, UINT elements)
364 UINT i;
365 TRACE("\n");
366 for (i = 0; i < elements; ++i) {
367 D3DXVec3Unproject(
368 (D3DXVECTOR3*)((char*)out + outstride * i),
369 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
370 viewport, projection, view, world);
372 return out;
375 /*************************************************************************
376 * D3DXVec4TransformArray
378 D3DXVECTOR4* WINAPI D3DXVec4TransformArray(
379 D3DXVECTOR4* out, UINT outstride, CONST D3DXVECTOR4* in, UINT instride,
380 CONST D3DXMATRIX* matrix, UINT elements)
382 UINT i;
383 TRACE("\n");
384 for (i = 0; i < elements; ++i) {
385 D3DXVec4Transform(
386 (D3DXVECTOR4*)((char*)out + outstride * i),
387 (CONST D3DXVECTOR4*)((const char*)in + instride * i),
388 matrix);
390 return out;