push 9758e6fe7ae8fbab538c98c718d6619029bb3457
[wine/hacks.git] / dlls / d3dx9_36 / tests / math.c
blob511fc3bc78212130d79fbe70a73a47702d0ed082
1 /*
2 * Copyright 2008 Philip Nilsson
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
19 #include "wine/test.h"
20 #include "d3dx9math.h"
22 #define ARRAY_SIZE 5
24 #define admitted_error 0.01f
25 #define relative_error(exp, out) ((exp == out) ? 0.0f : (fabs(out - exp) / fabs(exp)))
26 #define compare_vectors(exp, out) \
27 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
28 ok(relative_error(exp[i].x, out[i].x) < admitted_error && \
29 relative_error(exp[i].y, out[i].y) < admitted_error && \
30 relative_error(exp[i].z, out[i].z) < admitted_error && \
31 relative_error(exp[i].w, out[i].w) < admitted_error, \
32 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
33 out[i].x, out[i].y, out[i].z, out[i].w, \
34 exp[i].x, exp[i].y, exp[i].z, exp[i].w, \
35 i); \
37 #define compare_planes(exp, out) \
38 for (i = 0; i < ARRAY_SIZE + 2; ++i) { \
39 ok(relative_error(exp[i].a, out[i].a) < admitted_error && \
40 relative_error(exp[i].b, out[i].b) < admitted_error && \
41 relative_error(exp[i].c, out[i].c) < admitted_error && \
42 relative_error(exp[i].d, out[i].d) < admitted_error, \
43 "Got (%f, %f, %f, %f), expected (%f, %f, %f, %f) for index %d.\n", \
44 out[i].a, out[i].b, out[i].c, out[i].d, \
45 exp[i].a, exp[i].b, exp[i].c, exp[i].d, \
46 i); \
49 /* The mathematical properties are checked in the d3dx8 testsuite.
51 * These tests check:
52 * That the functions work.
53 * That the stride functionality works.
54 * That nothing is written where it should not be.
56 * These tests should check:
57 * That inp_vec is not modified.
58 * That the input and output arrays can be the same (MSDN
59 * says they can, and some testing with a native DLL
60 * says so too).
62 static void test_D3DXVec_Array(void)
64 unsigned int i;
65 D3DVIEWPORT9 viewport;
66 D3DXMATRIX mat, projection, view, world;
67 D3DXVECTOR4 inp_vec[ARRAY_SIZE];
68 D3DXVECTOR4 out_vec[ARRAY_SIZE + 2];
69 D3DXVECTOR4 exp_vec[ARRAY_SIZE + 2];
70 D3DXPLANE inp_plane[ARRAY_SIZE];
71 D3DXPLANE out_plane[ARRAY_SIZE + 2];
72 D3DXPLANE exp_plane[ARRAY_SIZE + 2];
74 viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10;
75 viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5;
77 for (i = 0; i < ARRAY_SIZE + 2; ++i) {
78 out_vec[i].x = out_vec[i].y = out_vec[i].z = out_vec[i].w = 0.0f;
79 exp_vec[i].x = exp_vec[i].y = exp_vec[i].z = exp_vec[i].w = 0.0f;
80 out_plane[i].a = out_plane[i].b = out_plane[i].c = out_plane[i].d = 0.0f;
81 exp_plane[i].a = exp_plane[i].b = exp_plane[i].c = exp_plane[i].d = 0.0f;
84 for (i = 0; i < ARRAY_SIZE; ++i) {
85 inp_plane[i].a = inp_plane[i].c = inp_vec[i].x = inp_vec[i].z = i;
86 inp_plane[i].b = inp_plane[i].d = inp_vec[i].y = inp_vec[i].w = ARRAY_SIZE - i;
89 U(mat).m[0][0] = 1.0f; U(mat).m[0][1] = 2.0f; U(mat).m[0][2] = 3.0f; U(mat).m[0][3] = 4.0f;
90 U(mat).m[1][0] = 5.0f; U(mat).m[1][1] = 6.0f; U(mat).m[1][2] = 7.0f; U(mat).m[1][3] = 8.0f;
91 U(mat).m[2][0] = 9.0f; U(mat).m[2][1] = 10.0f; U(mat).m[2][2] = 11.0f; U(mat).m[2][3] = 12.0f;
92 U(mat).m[3][0] = 13.0f; U(mat).m[3][1] = 14.0f; U(mat).m[3][2] = 15.0f; U(mat).m[3][3] = 16.0f;
94 D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
96 U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f;
97 U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f;
98 U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f;
99 U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f;
100 U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f;
101 U(view).m[3][3] = -40.0f;
103 U(world).m[0][0] = 21.0f; U(world).m[0][1] = 2.0f; U(world).m[0][2] = 3.0f; U(world).m[0][3] = 4.0;
104 U(world).m[1][0] = 5.0f; U(world).m[1][1] = 23.0f; U(world).m[1][2] = 7.0f; U(world).m[1][3] = 8.0f;
105 U(world).m[2][0] = -8.0f; U(world).m[2][1] = -7.0f; U(world).m[2][2] = 25.0f; U(world).m[2][3] = -5.0f;
106 U(world).m[3][0] = -4.0f; U(world).m[3][1] = -3.0f; U(world).m[3][2] = -2.0f; U(world).m[3][3] = 27.0f;
108 /* D3DXVec2TransformCoordArray */
109 exp_vec[1].x = 0.678571f; exp_vec[1].y = 0.785714f;
110 exp_vec[2].x = 0.653846f; exp_vec[2].y = 0.769231f;
111 exp_vec[3].x = 0.625f; exp_vec[3].y = 0.75f;
112 exp_vec[4].x = 0.590909f; exp_vec[4].y = 8.0f/11.0f;
113 exp_vec[5].x = 0.55f; exp_vec[5].y = 0.7f;
114 D3DXVec2TransformCoordArray((D3DXVECTOR2*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
115 compare_vectors(exp_vec, out_vec);
117 /* D3DXVec2TransformNormalArray */
118 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f;
119 exp_vec[2].x = 21.0f; exp_vec[2].y = 26.0f;
120 exp_vec[3].x = 17.0f; exp_vec[3].y = 22.0f;
121 exp_vec[4].x = 13.0f; exp_vec[4].y = 18.0f;
122 exp_vec[5].x = 9.0f; exp_vec[5].y = 14.0f;
123 D3DXVec2TransformNormalArray((D3DXVECTOR2*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
124 compare_vectors(exp_vec, out_vec);
126 /* D3DXVec3TransformCoordArray */
127 exp_vec[1].x = 0.678571f; exp_vec[1].y = 0.785714f; exp_vec[1].z = 0.892857f;
128 exp_vec[2].x = 0.671875f; exp_vec[2].y = 0.78125f; exp_vec[2].z = 0.890625f;
129 exp_vec[3].x = 6.0f/9.0f; exp_vec[3].y = 7.0f/9.0f; exp_vec[3].z = 8.0f/9.0f;
130 exp_vec[4].x = 0.6625f; exp_vec[4].y = 0.775f; exp_vec[4].z = 0.8875f;
131 exp_vec[5].x = 0.659091f; exp_vec[5].y = 0.772727f; exp_vec[5].z = 0.886364f;
132 D3DXVec3TransformCoordArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
133 compare_vectors(exp_vec, out_vec);
135 /* D3DXVec3TransformNormalArray */
136 exp_vec[1].x = 25.0f; exp_vec[1].y = 30.0f; exp_vec[1].z = 35.0f;
137 exp_vec[2].x = 30.0f; exp_vec[2].y = 36.0f; exp_vec[2].z = 42.0f;
138 exp_vec[3].x = 35.0f; exp_vec[3].y = 42.0f; exp_vec[3].z = 49.0f;
139 exp_vec[4].x = 40.0f; exp_vec[4].y = 48.0f; exp_vec[4].z = 56.0f;
140 exp_vec[5].x = 45.0f; exp_vec[5].y = 54.0f; exp_vec[5].z = 63.0f;
141 D3DXVec3TransformNormalArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
142 compare_vectors(exp_vec, out_vec);
144 /* D3DXVec3ProjectArray */
145 exp_vec[1].x = 1089.554199f; exp_vec[1].y = -226.590622f; exp_vec[1].z = 0.215273f;
146 exp_vec[2].x = 1068.903320f; exp_vec[2].y = 103.085129f; exp_vec[2].z = 0.183050f;
147 exp_vec[3].x = 1051.778931f; exp_vec[3].y = 376.462250f; exp_vec[3].z = 0.156329f;
148 exp_vec[4].x = 1037.348877f; exp_vec[4].y = 606.827393f; exp_vec[4].z = 0.133813f;
149 exp_vec[5].x = 1025.023560f; exp_vec[5].y = 803.591248f; exp_vec[5].z = 0.114581f;
150 D3DXVec3ProjectArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (CONST D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &viewport, &projection, &view, &world, ARRAY_SIZE);
151 compare_vectors(exp_vec, out_vec);
153 /* D3DXVec3UnprojectArray */
154 exp_vec[1].x = -6.124031f; exp_vec[1].y = 3.225360f; exp_vec[1].z = 0.620571f;
155 exp_vec[2].x = -3.807109f; exp_vec[2].y = 2.046579f; exp_vec[2].z = 0.446894f;
156 exp_vec[3].x = -2.922839f; exp_vec[3].y = 1.596689f; exp_vec[3].z = 0.380609f;
157 exp_vec[4].x = -2.456225f; exp_vec[4].y = 1.359290f; exp_vec[4].z = 0.345632f;
158 exp_vec[5].x = -2.167897f; exp_vec[5].y = 1.212597f; exp_vec[5].z = 0.324019f;
159 D3DXVec3UnprojectArray((D3DXVECTOR3*)(out_vec + 1), sizeof(D3DXVECTOR4), (CONST D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &viewport, &projection, &view, &world, ARRAY_SIZE);
160 compare_vectors(exp_vec, out_vec);
162 /* D3DXVec2TransformArray */
163 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
164 exp_vec[2].x = 34.0f; exp_vec[2].y = 40.0f; exp_vec[2].z = 46.0f; exp_vec[2].w = 52.0f;
165 exp_vec[3].x = 30.0f; exp_vec[3].y = 36.0f; exp_vec[3].z = 42.0f; exp_vec[3].w = 48.0f;
166 exp_vec[4].x = 26.0f; exp_vec[4].y = 32.0f; exp_vec[4].z = 38.0f; exp_vec[4].w = 44.0f;
167 exp_vec[5].x = 22.0f; exp_vec[5].y = 28.0f; exp_vec[5].z = 34.0f; exp_vec[5].w = 40.0f;
168 D3DXVec2TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), (D3DXVECTOR2*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
169 compare_vectors(exp_vec, out_vec);
171 /* D3DXVec3TransformArray */
172 exp_vec[1].x = 38.0f; exp_vec[1].y = 44.0f; exp_vec[1].z = 50.0f; exp_vec[1].w = 56.0f;
173 exp_vec[2].x = 43.0f; exp_vec[2].y = 50.0f; exp_vec[2].z = 57.0f; exp_vec[2].w = 64.0f;
174 exp_vec[3].x = 48.0f; exp_vec[3].y = 56.0f; exp_vec[3].z = 64.0f; exp_vec[3].w = 72.0f;
175 exp_vec[4].x = 53.0f; exp_vec[4].y = 62.0f; exp_vec[4].z = 71.0f; exp_vec[4].w = 80.0f;
176 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
177 D3DXVec3TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), (D3DXVECTOR3*)inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
178 compare_vectors(exp_vec, out_vec);
180 /* D3DXVec4TransformArray */
181 exp_vec[1].x = 90.0f; exp_vec[1].y = 100.0f; exp_vec[1].z = 110.0f; exp_vec[1].w = 120.0f;
182 exp_vec[2].x = 82.0f; exp_vec[2].y = 92.0f; exp_vec[2].z = 102.0f; exp_vec[2].w = 112.0f;
183 exp_vec[3].x = 74.0f; exp_vec[3].y = 84.0f; exp_vec[3].z = 94.0f; exp_vec[3].w = 104.0f;
184 exp_vec[4].x = 66.0f; exp_vec[4].y = 76.0f; exp_vec[4].z = 86.0f; exp_vec[4].w = 96.0f;
185 exp_vec[5].x = 58.0f; exp_vec[5].y = 68.0f; exp_vec[5].z = 78.0f; exp_vec[5].w = 88.0f;
186 D3DXVec4TransformArray(out_vec + 1, sizeof(D3DXVECTOR4), inp_vec, sizeof(D3DXVECTOR4), &mat, ARRAY_SIZE);
187 compare_vectors(exp_vec, out_vec);
189 /* D3DXPlaneTransformArray */
190 exp_plane[1].a = 90.0f; exp_plane[1].b = 100.0f; exp_plane[1].c = 110.0f; exp_plane[1].d = 120.0f;
191 exp_plane[2].a = 82.0f; exp_plane[2].b = 92.0f; exp_plane[2].c = 102.0f; exp_plane[2].d = 112.0f;
192 exp_plane[3].a = 74.0f; exp_plane[3].b = 84.0f; exp_plane[3].c = 94.0f; exp_plane[3].d = 104.0f;
193 exp_plane[4].a = 66.0f; exp_plane[4].b = 76.0f; exp_plane[4].c = 86.0f; exp_plane[4].d = 96.0f;
194 exp_plane[5].a = 58.0f; exp_plane[5].b = 68.0f; exp_plane[5].c = 78.0f; exp_plane[5].d = 88.0f;
195 D3DXPlaneTransformArray(out_plane + 1, sizeof(D3DXPLANE), inp_plane, sizeof(D3DXPLANE), &mat, ARRAY_SIZE);
196 compare_planes(exp_plane, out_plane);
199 START_TEST(math)
201 test_D3DXVec_Array();