2 * Copyright 2007 David Adam
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "d3dx8math.h"
21 #include "d3dx8math.inl"
23 #include "wine/test.h"
25 #define admitted_error 0.00001f
27 #define expect_vec(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error),"Expected Vector= (%f, %f)\n , Got Vector= (%f, %f)\n", expectedvec.x, expectedvec.y, gotvec.x, gotvec.y);
29 #define expect_vec3(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(expectedvec.z-gotvec.z)<admitted_error),"Expected Vector= (%f, %f,%f)\n , Got Vector= (%f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, gotvec.x, gotvec.y, gotvec.z);
31 #define expect_vec4(expectedvec,gotvec) ok((fabs(expectedvec.x-gotvec.x)<admitted_error)&&(fabs(expectedvec.y-gotvec.y)<admitted_error)&&(fabs(expectedvec.z-gotvec.z)<admitted_error)&&(fabs(expectedvec.w-gotvec.w)<admitted_error),"Expected Vector= (%f, %f, %f, %f)\n , Got Vector= (%f, %f, %f, %f)\n", expectedvec.x, expectedvec.y, expectedvec.z, expectedvec.w, gotvec.x, gotvec.y, gotvec.z, gotvec.w);
33 static void D3X8QuaternionTest(void)
38 q
.x
= 1.0f
, q
.y
= 2.0f
; q
.z
= 4.0f
; q
.w
= 10.0f
;
39 r
.x
= -3.0f
; r
.y
= 4.0f
; r
.z
= -5.0f
; r
.w
= 7.0;
41 /*_______________D3DXQuaternionDot______________________*/
43 got
= D3DXQuaternionDot(&q
,&r
);
44 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
45 /* Tests the case NULL */
47 got
= D3DXQuaternionDot(NULL
,&r
);
48 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
50 got
= D3DXQuaternionDot(NULL
,NULL
);
51 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
53 /*_______________D3DXQuaternionLength__________________________*/
55 got
= D3DXQuaternionLength(&q
);
56 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
57 /* Tests the case NULL */
59 got
= D3DXQuaternionLength(NULL
);
60 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
62 /*_______________D3DXQuaternionLengthSq________________________*/
64 got
= D3DXQuaternionLengthSq(&q
);
65 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
66 /* Tests the case NULL */
68 got
= D3DXQuaternionLengthSq(NULL
);
69 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
72 static void D3X8Vector2Test(void)
74 D3DXVECTOR2 expectedvec
, gotvec
, u
, v
;
75 LPD3DXVECTOR2 funcpointer
;
76 FLOAT expected
, got
, scale
;
82 /*_______________D3DXVec2Add__________________________*/
83 expectedvec
.x
= -4.0f
; expectedvec
.y
= 13.0f
;
84 D3DXVec2Add(&gotvec
,&u
,&v
);
85 expect_vec(expectedvec
,gotvec
);
86 /* Tests the case NULL */
87 funcpointer
= D3DXVec2Add(&gotvec
,NULL
,&v
);
88 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
89 funcpointer
= D3DXVec2Add(NULL
,NULL
,NULL
);
90 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
92 /*_______________D3DXVec2CCW__________________________*/
94 got
= D3DXVec2CCW(&u
,&v
);
95 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
96 /* Tests the case NULL */
98 got
= D3DXVec2CCW(NULL
,&v
);
99 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
101 got
= D3DXVec2CCW(NULL
,NULL
);
102 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
104 /*_______________D3DXVec2Dot__________________________*/
106 got
= D3DXVec2Dot(&u
,&v
);
107 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
108 /* Tests the case NULL */
110 got
= D3DXVec2Dot(NULL
,&v
);
111 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
113 got
= D3DXVec2Dot(NULL
,NULL
);
114 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
116 /*_______________D3DXVec2Length__________________________*/
118 got
= D3DXVec2Length(&u
);
119 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
120 /* Tests the case NULL */
122 got
= D3DXVec2Length(NULL
);
123 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
125 /*_______________D3DXVec2LengthSq________________________*/
127 got
= D3DXVec2LengthSq(&u
);
128 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
129 /* Tests the case NULL */
131 got
= D3DXVec2LengthSq(NULL
);
132 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
134 /*_______________D3DXVec2Lerp__________________________*/
135 expectedvec
.x
= 68.0f
; expectedvec
.y
= -28.5f
;
136 D3DXVec2Lerp(&gotvec
,&u
,&v
,scale
);
137 expect_vec(expectedvec
,gotvec
);
138 /* Tests the case NULL */
139 funcpointer
= D3DXVec2Lerp(&gotvec
,NULL
,&v
,scale
);
140 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
141 funcpointer
= D3DXVec2Lerp(NULL
,NULL
,NULL
,scale
);
142 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
144 /*_______________D3DXVec2Maximize__________________________*/
145 expectedvec
.x
= 3.0f
; expectedvec
.y
= 9.0f
;
146 D3DXVec2Maximize(&gotvec
,&u
,&v
);
147 expect_vec(expectedvec
,gotvec
);
148 /* Tests the case NULL */
149 funcpointer
= D3DXVec2Maximize(&gotvec
,NULL
,&v
);
150 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
151 funcpointer
= D3DXVec2Maximize(NULL
,NULL
,NULL
);
152 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
154 /*_______________D3DXVec2Minimize__________________________*/
155 expectedvec
.x
= -7.0f
; expectedvec
.y
= 4.0f
;
156 D3DXVec2Minimize(&gotvec
,&u
,&v
);
157 expect_vec(expectedvec
,gotvec
);
158 /* Tests the case NULL */
159 funcpointer
= D3DXVec2Minimize(&gotvec
,NULL
,&v
);
160 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
161 funcpointer
= D3DXVec2Minimize(NULL
,NULL
,NULL
);
162 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
164 /*_______________D3DXVec2Scale____________________________*/
165 expectedvec
.x
= -19.5f
; expectedvec
.y
= -26.0f
;
166 D3DXVec2Scale(&gotvec
,&u
,scale
);
167 expect_vec(expectedvec
,gotvec
);
168 /* Tests the case NULL */
169 funcpointer
= D3DXVec2Scale(&gotvec
,NULL
,scale
);
170 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
171 funcpointer
= D3DXVec2Scale(NULL
,NULL
,scale
);
172 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
174 /*_______________D3DXVec2Subtract__________________________*/
175 expectedvec
.x
= 10.0f
; expectedvec
.y
= -5.0f
;
176 D3DXVec2Subtract(&gotvec
,&u
,&v
);
177 expect_vec(expectedvec
,gotvec
);
178 /* Tests the case NULL */
179 funcpointer
= D3DXVec2Subtract(&gotvec
,NULL
,&v
);
180 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
181 funcpointer
= D3DXVec2Subtract(NULL
,NULL
,NULL
);
182 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
186 static void D3X8Vector3Test(void)
188 D3DXVECTOR3 expectedvec
, gotvec
, u
, v
;
189 LPD3DXVECTOR3 funcpointer
;
190 FLOAT expected
, got
, scale
;
192 u
.x
= 9.0f
; u
.y
= 6.0f
; u
.z
= 2.0f
;
193 v
.x
= 2.0f
; v
.y
= -3.0f
; v
.z
= -4.0;
196 /*_______________D3DXVec3Add__________________________*/
197 expectedvec
.x
= 11.0f
; expectedvec
.y
= 3.0f
; expectedvec
.z
= -2.0f
;
198 D3DXVec3Add(&gotvec
,&u
,&v
);
199 expect_vec3(expectedvec
,gotvec
);
200 /* Tests the case NULL */
201 funcpointer
= D3DXVec3Add(&gotvec
,NULL
,&v
);
202 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
203 funcpointer
= D3DXVec3Add(NULL
,NULL
,NULL
);
204 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
206 /*_______________D3DXVec3Cross________________________*/
207 expectedvec
.x
= -18.0f
; expectedvec
.y
= 40.0f
; expectedvec
.z
= -30.0f
;
208 D3DXVec3Cross(&gotvec
,&u
,&v
);
209 /* Tests the case NULL */
210 funcpointer
= D3DXVec3Cross(&gotvec
,NULL
,&v
);
211 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
212 funcpointer
= D3DXVec3Cross(NULL
,NULL
,NULL
);
213 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
215 /*_______________D3DXVec3Dot__________________________*/
217 got
= D3DXVec3Dot(&u
,&v
);
218 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
219 /* Tests the case NULL */
221 got
= D3DXVec3Dot(NULL
,&v
);
222 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
224 got
= D3DXVec3Dot(NULL
,NULL
);
225 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
227 /*_______________D3DXVec3Length__________________________*/
229 got
= D3DXVec3Length(&u
);
230 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
231 /* Tests the case NULL */
233 got
= D3DXVec3Length(NULL
);
234 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
236 /*_______________D3DXVec3LengthSq________________________*/
238 got
= D3DXVec3LengthSq(&u
);
239 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
240 /* Tests the case NULL */
242 got
= D3DXVec3LengthSq(NULL
);
243 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
245 /*_______________D3DXVec3Lerp__________________________*/
246 expectedvec
.x
= 54.5f
; expectedvec
.y
= 64.5f
, expectedvec
.z
= 41.0f
;
247 D3DXVec3Lerp(&gotvec
,&u
,&v
,scale
);
248 expect_vec3(expectedvec
,gotvec
);
249 /* Tests the case NULL */
250 funcpointer
= D3DXVec3Lerp(&gotvec
,NULL
,&v
,scale
);
251 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
252 funcpointer
= D3DXVec3Lerp(NULL
,NULL
,NULL
,scale
);
253 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
255 /*_______________D3DXVec3Maximize__________________________*/
256 expectedvec
.x
= 9.0f
; expectedvec
.y
= 6.0f
; expectedvec
.z
= 2.0f
;
257 D3DXVec3Maximize(&gotvec
,&u
,&v
);
258 expect_vec3(expectedvec
,gotvec
);
259 /* Tests the case NULL */
260 funcpointer
= D3DXVec3Maximize(&gotvec
,NULL
,&v
);
261 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
262 funcpointer
= D3DXVec3Maximize(NULL
,NULL
,NULL
);
263 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
265 /*_______________D3DXVec3Minimize__________________________*/
266 expectedvec
.x
= 2.0f
; expectedvec
.y
= -3.0f
; expectedvec
.z
= -4.0f
;
267 D3DXVec3Minimize(&gotvec
,&u
,&v
);
268 expect_vec3(expectedvec
,gotvec
);
269 /* Tests the case NULL */
270 funcpointer
= D3DXVec3Minimize(&gotvec
,NULL
,&v
);
271 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
272 funcpointer
= D3DXVec3Minimize(NULL
,NULL
,NULL
);
273 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
275 /*_______________D3DXVec3Scale____________________________*/
276 expectedvec
.x
= -58.5f
; expectedvec
.y
= -39.0f
; expectedvec
.z
= -13.0f
;
277 D3DXVec3Scale(&gotvec
,&u
,scale
);
278 expect_vec3(expectedvec
,gotvec
);
279 /* Tests the case NULL */
280 funcpointer
= D3DXVec3Scale(&gotvec
,NULL
,scale
);
281 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
282 funcpointer
= D3DXVec3Scale(NULL
,NULL
,scale
);
283 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
285 /*_______________D3DXVec3Subtract_______________________*/
286 expectedvec
.x
= 7.0f
; expectedvec
.y
= 9.0f
; expectedvec
.z
= 6.0f
;
287 D3DXVec3Subtract(&gotvec
,&u
,&v
);
288 expect_vec3(expectedvec
,gotvec
);
289 /* Tests the case NULL */
290 funcpointer
= D3DXVec3Subtract(&gotvec
,NULL
,&v
);
291 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
292 funcpointer
= D3DXVec3Subtract(NULL
,NULL
,NULL
);
293 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
297 static void D3X8Vector4Test(void)
299 D3DXVECTOR4 expectedvec
, gotvec
, u
, v
;
300 LPD3DXVECTOR4 funcpointer
;
301 FLOAT expected
, got
, scale
;
304 u
.x
= 1.0f
; u
.y
= 2.0f
; u
.z
= 4.0f
; u
.w
= 10.0;
305 v
.x
= -3.0f
; v
.y
= 4.0f
; v
.z
= -5.0f
; v
.w
= 7.0;
307 /*_______________D3DXVec4Add__________________________*/
308 expectedvec
.x
= -2.0f
; expectedvec
.y
= 6.0f
; expectedvec
.z
= -1.0f
; expectedvec
.w
= 17.0f
;
309 D3DXVec4Add(&gotvec
,&u
,&v
);
310 expect_vec4(expectedvec
,gotvec
);
311 /* Tests the case NULL */
312 funcpointer
= D3DXVec4Add(&gotvec
,NULL
,&v
);
313 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
314 funcpointer
= D3DXVec4Add(NULL
,NULL
,NULL
);
315 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
317 /*_______________D3DXVec4Dot__________________________*/
319 got
= D3DXVec4Dot(&u
,&v
);
320 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
321 /* Tests the case NULL */
323 got
= D3DXVec4Dot(NULL
,&v
);
324 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
326 got
= D3DXVec4Dot(NULL
,NULL
);
327 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
329 /*_______________D3DXVec4Length__________________________*/
331 got
= D3DXVec4Length(&u
);
332 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
333 /* Tests the case NULL */
335 got
= D3DXVec4Length(NULL
);
336 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
338 /*_______________D3DXVec4LengthSq________________________*/
340 got
= D3DXVec4LengthSq(&u
);
341 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
342 /* Tests the case NULL */
344 got
= D3DXVec4LengthSq(NULL
);
345 ok(fabs( got
- expected
) < admitted_error
, "Expected: %f, Got: %f\n", expected
, got
);
347 /*_______________D3DXVec4Lerp__________________________*/
348 expectedvec
.x
= 27.0f
; expectedvec
.y
= -11.0f
; expectedvec
.z
= 62.5; expectedvec
.w
= 29.5;
349 D3DXVec4Lerp(&gotvec
,&u
,&v
,scale
);
350 expect_vec4(expectedvec
,gotvec
);
351 /* Tests the case NULL */
352 funcpointer
= D3DXVec4Lerp(&gotvec
,NULL
,&v
,scale
);
353 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
354 funcpointer
= D3DXVec4Lerp(NULL
,NULL
,NULL
,scale
);
355 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
357 /*_______________D3DXVec4Maximize__________________________*/
358 expectedvec
.x
= 1.0f
; expectedvec
.y
= 4.0f
; expectedvec
.z
= 4.0f
; expectedvec
.w
= 10.0;
359 D3DXVec4Maximize(&gotvec
,&u
,&v
);
360 expect_vec4(expectedvec
,gotvec
);
361 /* Tests the case NULL */
362 funcpointer
= D3DXVec4Maximize(&gotvec
,NULL
,&v
);
363 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
364 funcpointer
= D3DXVec4Maximize(NULL
,NULL
,NULL
);
365 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
367 /*_______________D3DXVec4Minimize__________________________*/
368 expectedvec
.x
= -3.0f
; expectedvec
.y
= 2.0f
; expectedvec
.z
= -5.0f
; expectedvec
.w
= 7.0;
369 D3DXVec4Minimize(&gotvec
,&u
,&v
);
370 expect_vec4(expectedvec
,gotvec
);
371 /* Tests the case NULL */
372 funcpointer
= D3DXVec4Minimize(&gotvec
,NULL
,&v
);
373 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
374 funcpointer
= D3DXVec4Minimize(NULL
,NULL
,NULL
);
375 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
377 /*_______________D3DXVec4Scale____________________________*/
378 expectedvec
.x
= -6.5f
; expectedvec
.y
= -13.0f
; expectedvec
.z
= -26.0f
; expectedvec
.w
= -65.0f
;
379 D3DXVec4Scale(&gotvec
,&u
,scale
);
380 expect_vec4(expectedvec
,gotvec
);
381 /* Tests the case NULL */
382 funcpointer
= D3DXVec4Scale(&gotvec
,NULL
,scale
);
383 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
384 funcpointer
= D3DXVec4Scale(NULL
,NULL
,scale
);
385 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
387 /*_______________D3DXVec4Subtract__________________________*/
388 expectedvec
.x
= 4.0f
; expectedvec
.y
= -2.0f
; expectedvec
.z
= 9.0f
; expectedvec
.w
= 3.0f
;
389 D3DXVec4Subtract(&gotvec
,&u
,&v
);
390 expect_vec4(expectedvec
,gotvec
);
391 /* Tests the case NULL */
392 funcpointer
= D3DXVec4Subtract(&gotvec
,NULL
,&v
);
393 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
394 funcpointer
= D3DXVec4Subtract(NULL
,NULL
,NULL
);
395 ok(funcpointer
== NULL
, "Expected: %p, Got: %p\n", NULL
, funcpointer
);
400 D3X8QuaternionTest();