jscript: Added Number function implementation.
[wine/multimedia.git] / dlls / d3dx9_36 / math.c
blobcbfac84fb9604fcc09ff2bc09c368364ca208c03
1 /*
2 * Mathematical operations specific to D3DX9.
4 * Copyright (C) 2008 Philip Nilsson
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
23 #include "config.h"
24 #include "windef.h"
25 #include "wingdi.h"
26 #include "wine/debug.h"
27 #include "d3dx9.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
31 /*************************************************************************
32 * D3DXMatrixDecompose
34 HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutrotation, D3DXVECTOR3 *pouttranslation, D3DXMATRIX *pm)
36 D3DXMATRIX normalized;
37 D3DXVECTOR3 vec;
39 if (!pm)
41 return D3DERR_INVALIDCALL;
44 /*Compute the scaling part.*/
45 vec.x=pm->u.m[0][0];
46 vec.y=pm->u.m[0][1];
47 vec.z=pm->u.m[0][2];
48 poutscale->x=D3DXVec3Length(&vec);
50 vec.x=pm->u.m[1][0];
51 vec.y=pm->u.m[1][1];
52 vec.z=pm->u.m[1][2];
53 poutscale->y=D3DXVec3Length(&vec);
55 vec.x=pm->u.m[2][0];
56 vec.y=pm->u.m[2][1];
57 vec.z=pm->u.m[2][2];
58 poutscale->z=D3DXVec3Length(&vec);
60 /*Compute the translation part.*/
61 pouttranslation->x=pm->u.m[3][0];
62 pouttranslation->y=pm->u.m[3][1];
63 pouttranslation->z=pm->u.m[3][2];
65 /*Let's calculate the rotation now*/
66 if ( (poutscale->x == 0.0f) || (poutscale->y == 0.0f) || (poutscale->z == 0.0f) )
68 return D3DERR_INVALIDCALL;
71 normalized.u.m[0][0]=pm->u.m[0][0]/poutscale->x;
72 normalized.u.m[0][1]=pm->u.m[0][1]/poutscale->x;
73 normalized.u.m[0][2]=pm->u.m[0][2]/poutscale->x;
74 normalized.u.m[1][0]=pm->u.m[1][0]/poutscale->y;
75 normalized.u.m[1][1]=pm->u.m[1][1]/poutscale->y;
76 normalized.u.m[1][2]=pm->u.m[1][2]/poutscale->y;
77 normalized.u.m[2][0]=pm->u.m[2][0]/poutscale->z;
78 normalized.u.m[2][1]=pm->u.m[2][1]/poutscale->z;
79 normalized.u.m[2][2]=pm->u.m[2][2]/poutscale->z;
81 D3DXQuaternionRotationMatrix(poutrotation,&normalized);
82 return S_OK;
85 /*************************************************************************
86 * D3DXPlaneTransformArray
88 D3DXPLANE* WINAPI D3DXPlaneTransformArray(
89 D3DXPLANE* out, UINT outstride, CONST D3DXPLANE* in, UINT instride,
90 CONST D3DXMATRIX* matrix, UINT elements)
92 UINT i;
93 TRACE("\n");
94 for (i = 0; i < elements; ++i) {
95 D3DXPlaneTransform(
96 (D3DXPLANE*)((char*)out + outstride * i),
97 (CONST D3DXPLANE*)((const char*)in + instride * i),
98 matrix);
100 return out;
103 /*************************************************************************
104 * D3DXVec2TransformArray
106 * Transform an array of vectors by a matrix.
108 D3DXVECTOR4* WINAPI D3DXVec2TransformArray(
109 D3DXVECTOR4* out, UINT outstride, CONST D3DXVECTOR2* in, UINT instride,
110 CONST D3DXMATRIX* matrix, UINT elements)
112 UINT i;
113 TRACE("\n");
114 for (i = 0; i < elements; ++i) {
115 D3DXVec2Transform(
116 (D3DXVECTOR4*)((char*)out + outstride * i),
117 (CONST D3DXVECTOR2*)((const char*)in + instride * i),
118 matrix);
120 return out;
123 /*************************************************************************
124 * D3DXVec2TransformCoordArray
126 D3DXVECTOR2* WINAPI D3DXVec2TransformCoordArray(
127 D3DXVECTOR2* out, UINT outstride, CONST D3DXVECTOR2* in, UINT instride,
128 CONST D3DXMATRIX* matrix, UINT elements)
130 UINT i;
131 TRACE("\n");
132 for (i = 0; i < elements; ++i) {
133 D3DXVec2TransformCoord(
134 (D3DXVECTOR2*)((char*)out + outstride * i),
135 (CONST D3DXVECTOR2*)((const char*)in + instride * i),
136 matrix);
138 return out;
141 /*************************************************************************
142 * D3DXVec2TransformNormalArray
144 D3DXVECTOR2* WINAPI D3DXVec2TransformNormalArray(
145 D3DXVECTOR2* out, UINT outstride, CONST D3DXVECTOR2 *in, UINT instride,
146 CONST D3DXMATRIX *matrix, UINT elements)
148 UINT i;
149 TRACE("\n");
150 for (i = 0; i < elements; ++i) {
151 D3DXVec2TransformNormal(
152 (D3DXVECTOR2*)((char*)out + outstride * i),
153 (CONST D3DXVECTOR2*)((const char*)in + instride * i),
154 matrix);
156 return out;
159 /*************************************************************************
160 * D3DXVec3ProjectArray
162 * Projects an array of vectors to the screen.
164 D3DXVECTOR3* WINAPI D3DXVec3ProjectArray(
165 D3DXVECTOR3* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
166 CONST D3DVIEWPORT9* viewport, CONST D3DXMATRIX* projection,
167 CONST D3DXMATRIX* view, CONST D3DXMATRIX* world, UINT elements)
169 UINT i;
170 TRACE("\n");
171 for (i = 0; i < elements; ++i) {
172 D3DXVec3Project(
173 (D3DXVECTOR3*)((char*)out + outstride * i),
174 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
175 viewport, projection, view, world);
177 return out;
180 /*************************************************************************
181 * D3DXVec3TransformArray
183 D3DXVECTOR4* WINAPI D3DXVec3TransformArray(
184 D3DXVECTOR4* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
185 CONST D3DXMATRIX* matrix, UINT elements)
187 UINT i;
188 TRACE("\n");
189 for (i = 0; i < elements; ++i) {
190 D3DXVec3Transform(
191 (D3DXVECTOR4*)((char*)out + outstride * i),
192 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
193 matrix);
195 return out;
198 /*************************************************************************
199 * D3DXVec3TransformCoordArray
201 D3DXVECTOR3* WINAPI D3DXVec3TransformCoordArray(
202 D3DXVECTOR3* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
203 CONST D3DXMATRIX* matrix, UINT elements)
205 UINT i;
206 TRACE("\n");
207 for (i = 0; i < elements; ++i) {
208 D3DXVec3TransformCoord(
209 (D3DXVECTOR3*)((char*)out + outstride * i),
210 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
211 matrix);
213 return out;
216 /*************************************************************************
217 * D3DXVec3TransformNormalArray
219 D3DXVECTOR3* WINAPI D3DXVec3TransformNormalArray(
220 D3DXVECTOR3* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
221 CONST D3DXMATRIX* matrix, UINT elements)
223 UINT i;
224 TRACE("\n");
225 for (i = 0; i < elements; ++i) {
226 D3DXVec3TransformNormal(
227 (D3DXVECTOR3*)((char*)out + outstride * i),
228 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
229 matrix);
231 return out;
234 /*************************************************************************
235 * D3DXVec3UnprojectArray
237 D3DXVECTOR3* WINAPI D3DXVec3UnprojectArray(
238 D3DXVECTOR3* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
239 CONST D3DVIEWPORT9* viewport, CONST D3DXMATRIX* projection,
240 CONST D3DXMATRIX* view, CONST D3DXMATRIX* world, UINT elements)
242 UINT i;
243 TRACE("\n");
244 for (i = 0; i < elements; ++i) {
245 D3DXVec3Unproject(
246 (D3DXVECTOR3*)((char*)out + outstride * i),
247 (CONST D3DXVECTOR3*)((const char*)in + instride * i),
248 viewport, projection, view, world);
250 return out;
253 /*************************************************************************
254 * D3DXVec4TransformArray
256 D3DXVECTOR4* WINAPI D3DXVec4TransformArray(
257 D3DXVECTOR4* out, UINT outstride, CONST D3DXVECTOR4* in, UINT instride,
258 CONST D3DXMATRIX* matrix, UINT elements)
260 UINT i;
261 TRACE("\n");
262 for (i = 0; i < elements; ++i) {
263 D3DXVec4Transform(
264 (D3DXVECTOR4*)((char*)out + outstride * i),
265 (CONST D3DXVECTOR4*)((const char*)in + instride * i),
266 matrix);
268 return out;