d3drm: Implement D3DRMVectorReflect.
[wine/dibdrv.git] / dlls / d3drm / tests / vector.c
blob88fbaf777a76ee95eba375d398b85c2d552ae2b1
1 /*
2 * Copyright 2007 Vijay Kiran Kamuju
3 * Copyright 2007 David Adam
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
20 #include <assert.h>
21 #include "wine/test.h"
22 #include "d3drmdef.h"
23 #include <math.h>
25 #define PI (4*atan(1.0))
26 #define admit_error 0.000001
28 #define expect_vec(expectedvec,gotvec) \
29 ok( ((fabs(expectedvec.x-gotvec.x)<admit_error)&&(fabs(expectedvec.y-gotvec.y)<admit_error)&&(fabs(expectedvec.z-gotvec.z)<admit_error)), \
30 "Expected Vector= (%f, %f, %f)\n , Got Vector= (%f, %f, %f)\n", \
31 expectedvec.x,expectedvec.y,expectedvec.z, gotvec.x, gotvec.y, gotvec.z);
33 void VectorTest(void)
35 D3DVALUE mod,par;
36 D3DVECTOR e,r,u,v,casnul,norm,ray;
38 u.x=2.0;u.y=2.0;u.z=1.0;
39 v.x=4.0;v.y=4.0;v.z=0.0;
41 /*______________________VectorAdd_________________________________*/
42 D3DRMVectorAdd(&r,&u,&v);
43 e.x=6.0;e.y=6.0;e.z=1.0;
44 expect_vec(e,r);
46 /*_______________________VectorSubtract__________________________*/
47 D3DRMVectorSubtract(&r,&u,&v);
48 e.x=-2.0;e.y=-2.0;e.z=1.0;
49 expect_vec(e,r);
51 /*_______________________VectorCrossProduct_______________________*/
52 D3DRMVectorCrossProduct(&r,&u,&v);
53 e.x=-4.0;e.y=4.0;e.z=0.0;
54 expect_vec(e,r);
56 /*_______________________VectorDotProduct__________________________*/
57 mod=D3DRMVectorDotProduct(&u,&v);
58 ok((mod == 16.0), "Expected 16.0, Got %f",mod);
60 /*_______________________VectorModulus_____________________________*/
61 mod=D3DRMVectorModulus(&u);
62 ok((mod == 3.0), "Expected 3.0, Got %f",mod);
64 /*_______________________VectorNormalize___________________________*/
65 D3DRMVectorNormalize(&u);
66 e.x=2.0/3.0;e.y=2.0/3.0;e.z=1.0/3.0;
67 expect_vec(e,u);
69 /* If u is the NULL vector, MSDN says that the return vector is NULL. In fact, the returned vector is (1,0,0). The following test case prove it. */
71 casnul.x=0.0; casnul.y=0.0; casnul.z=0.0;
72 D3DRMVectorNormalize(&casnul);
73 e.x=1.0; e.y=0.0; e.z=0.0;
74 expect_vec(e,casnul);
76 /*____________________VectorReflect_________________________________*/
77 ray.x=3.0; ray.y=-4.0; ray.z=5.0;
78 norm.x=1.0; norm.y=-2.0; norm.z=6.0;
79 e.x=79.0; e.y=-160.0; e.z=487.0;
80 D3DRMVectorReflect(&r,&ray,&norm);
81 expect_vec(e,r);
83 /*_______________________VectorScale__________________________*/
84 par=2.5;
85 D3DRMVectorScale(&r,&v,par);
86 e.x=10.0; e.y=10.0; e.z=0.0;
87 expect_vec(e,r);
90 START_TEST(vector)
92 VectorTest();