/* * Copyright 2007 David Adam * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include #include "d3dx8.h" #include "wine/test.h" #define admitted_error 0.0001f #define expect_color(expectedcolor,gotcolor) ok((fabs(expectedcolor.r-gotcolor.r)admitted_error) \ {\ equal=0;\ }\ }\ }\ ok(equal, "Expected matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n)\n\n" \ "Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \ U(expectedmat).m[0][0],U(expectedmat).m[0][1],U(expectedmat).m[0][2],U(expectedmat).m[0][3], \ U(expectedmat).m[1][0],U(expectedmat).m[1][1],U(expectedmat).m[1][2],U(expectedmat).m[1][3], \ U(expectedmat).m[2][0],U(expectedmat).m[2][1],U(expectedmat).m[2][2],U(expectedmat).m[2][3], \ U(expectedmat).m[3][0],U(expectedmat).m[3][1],U(expectedmat).m[3][2],U(expectedmat).m[3][3], \ U(gotmat).m[0][0],U(gotmat).m[0][1],U(gotmat).m[0][2],U(gotmat).m[0][3], \ U(gotmat).m[1][0],U(gotmat).m[1][1],U(gotmat).m[1][2],U(gotmat).m[1][3], \ U(gotmat).m[2][0],U(gotmat).m[2][1],U(gotmat).m[2][2],U(gotmat).m[2][3], \ U(gotmat).m[3][0],U(gotmat).m[3][1],U(gotmat).m[3][2],U(gotmat).m[3][3]); \ } #define expect_plane(expectedplane,gotplane) ok((fabs(expectedplane.a-gotplane.a)0 */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = 10.0f; U(mat).m[1][1] = 20.0f; U(mat).m[2][2] = 30.0f; U(mat).m[3][3] = 48.0f; expectedquat.x = 2.368682f; expectedquat.y = 0.768221f; expectedquat.z = -0.384111f; expectedquat.w = 3.905125f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the greater element is (2,2) */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = -60.0f; U(mat).m[2][2] = 40.0f; U(mat).m[3][3] = 48.0f; expectedquat.x = 1.233905f; expectedquat.y = -0.237290f; expectedquat.z = 5.267827f; expectedquat.w = -0.284747f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the greater element is (1,1) */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 60.0f; U(mat).m[2][2] = -80.0f; U(mat).m[3][3] = 48.0f; expectedquat.x = 0.651031f; expectedquat.y = 6.144103f; expectedquat.z = -0.203447f; expectedquat.w = 0.488273f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is near 0 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.9f; U(mat).m[3][3] = 48.0f; expectedquat.x = 1.709495f; expectedquat.y = 2.339872f; expectedquat.z = -0.534217f; expectedquat.w = 1.282122f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is 0.49 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.51f; U(mat).m[3][3] = 48.0f; expectedquat.x = 1.724923f; expectedquat.y = 2.318944f; expectedquat.z = -0.539039f; expectedquat.w = 1.293692f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is 0.51 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.49f; U(mat).m[3][3] = 48.0f; expectedquat.x = 1.725726f; expectedquat.y = 2.317865f; expectedquat.z = -0.539289f; expectedquat.w = 1.294294f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is 0.99 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = -0.01f; U(mat).m[3][3] = 48.0f; expectedquat.x = 1.745328f; expectedquat.y = 2.291833f; expectedquat.z = -0.545415f; expectedquat.w = 1.308996f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is 1.0 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.0f; U(mat).m[3][3] = 48.0f; expectedquat.x = 1.745743f; expectedquat.y = 2.291288f; expectedquat.z = -0.545545f; expectedquat.w = 1.309307f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is 1.01 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.01f; U(mat).m[3][3] = 48.0f; expectedquat.x = 18.408188f; expectedquat.y = 5.970223f; expectedquat.z = -2.985111f; expectedquat.w = 0.502494f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is 1.5 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.5f; U(mat).m[3][3] = 48.0f; expectedquat.x = 15.105186f; expectedquat.y = 4.898980f; expectedquat.z = -2.449490f; expectedquat.w = 0.612372f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is 1.7 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.70f; U(mat).m[3][3] = 48.0f; expectedquat.x = 14.188852f; expectedquat.y = 4.601790f; expectedquat.z = -2.300895f; expectedquat.w = 0.651920f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is 1.99 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 0.99f; U(mat).m[3][3] = 48.0f; expectedquat.x = 13.114303f; expectedquat.y = 4.253287f; expectedquat.z = -2.126644f; expectedquat.w = 0.705337f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /* test the case when the trace is 2.0 in a matrix which is not a rotation */ U(mat).m[0][1] = 5.0f; U(mat).m[0][2] = 7.0f; U(mat).m[0][3] = 8.0f; U(mat).m[1][0] = 11.0f; U(mat).m[1][2] = 16.0f; U(mat).m[1][3] = 33.0f; U(mat).m[2][0] = 19.0f; U(mat).m[2][1] = -21.0f; U(mat).m[2][3] = 43.0f; U(mat).m[3][0] = 2.0f; U(mat).m[3][1] = 3.0f; U(mat).m[3][2] = -4.0f; U(mat).m[0][0] = -10.0f; U(mat).m[1][1] = 10.0f; U(mat).m[2][2] = 2.0f; U(mat).m[3][3] = 48.0f; expectedquat.x = 10.680980f; expectedquat.y = 3.464102f; expectedquat.z = -1.732051f; expectedquat.w = 0.866025f; D3DXQuaternionRotationMatrix(&gotquat,&mat); expect_vec4(expectedquat,gotquat); /*_______________D3DXQuaternionRotationYawPitchRoll__________*/ expectedquat.x = 0.303261f; expectedquat.y = 0.262299f; expectedquat.z = 0.410073f; expectedquat.w = 0.819190f; D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,D3DX_PI/3.0f); expect_vec4(expectedquat,gotquat); /*_______________D3DXQuaternionSlerp________________________*/ expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f; D3DXQuaternionSlerp(&gotquat,&q,&r,scale); expect_vec4(expectedquat,gotquat); expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f; D3DXQuaternionSlerp(&gotquat,&q,&t,scale); expect_vec4(expectedquat,gotquat); /*_______________D3DXQuaternionSquad________________________*/ expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f; D3DXQuaternionSquad(&gotquat,&q,&r,&t,&u,scale); expect_vec4(expectedquat,gotquat); /*_______________D3DXQuaternionToAxisAngle__________________*/ Nq.x = 1.0f/22.0f; Nq.y = 2.0f/22.0f; Nq.z = 4.0f/22.0f; Nq.w = 10.0f/22.0f; expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expected = 2.197869f; D3DXQuaternionToAxisAngle(&Nq,&axis,&angle); expect_vec3(expectedvec,axis); ok(fabs( angle - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle); /* Test if |w|>1.0f */ expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expected = 0.0f; D3DXQuaternionToAxisAngle(&q,&axis,&angle); expect_vec3(expectedvec,axis); ok(fabs( angle - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle); /* Test the null quaternion */ expectedvec.x = 1.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f; expected = 0.0f; D3DXQuaternionToAxisAngle(&nul,&axis,&angle); expect_vec3(expectedvec,axis); ok(fabs( angle - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle); } static void D3X8Vector2Test(void) { D3DXVECTOR2 expectedvec, gotvec, nul, nulproj, u, v, w, x; LPD3DXVECTOR2 funcpointer; D3DXVECTOR4 expectedtrans, gottrans; D3DXMATRIX mat; FLOAT coeff1, coeff2, expected, got, scale; nul.x = 0.0f; nul.y = 0.0f; u.x = 3.0f; u.y = 4.0f; v.x = -7.0f; v.y = 9.0f; w.x = 4.0f; w.y = -3.0f; x.x = 2.0f; x.y = -11.0f; 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; 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; 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; 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; coeff1 = 2.0f; coeff2 = 5.0f; scale = -6.5f; /*_______________D3DXVec2Add__________________________*/ expectedvec.x = -4.0f; expectedvec.y = 13.0f; D3DXVec2Add(&gotvec,&u,&v); expect_vec(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec2Add(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec2Add(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec2BaryCentric___________________*/ expectedvec.x = -12.0f; expectedvec.y = -21.0f; D3DXVec2BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2); expect_vec(expectedvec,gotvec); /*_______________D3DXVec2CatmullRom____________________*/ expectedvec.x = 5820.25f; expectedvec.y = -3654.5625f; D3DXVec2CatmullRom(&gotvec,&u,&v,&w,&x,scale); expect_vec(expectedvec,gotvec); /*_______________D3DXVec2CCW__________________________*/ expected = 55.0f; got = D3DXVec2CCW(&u,&v); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec2CCW(NULL,&v); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); expected=0.0f; got = D3DXVec2CCW(NULL,NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec2Dot__________________________*/ expected = 15.0f; got = D3DXVec2Dot(&u,&v); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec2Dot(NULL,&v); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); expected=0.0f; got = D3DXVec2Dot(NULL,NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec2Hermite__________________________*/ expectedvec.x = 2604.625f; expectedvec.y = -4533.0f; D3DXVec2Hermite(&gotvec,&u,&v,&w,&x,scale); expect_vec(expectedvec,gotvec); /*_______________D3DXVec2Length__________________________*/ expected = 5.0f; got = D3DXVec2Length(&u); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec2Length(NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec2LengthSq________________________*/ expected = 25.0f; got = D3DXVec2LengthSq(&u); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec2LengthSq(NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec2Lerp__________________________*/ expectedvec.x = 68.0f; expectedvec.y = -28.5f; D3DXVec2Lerp(&gotvec,&u,&v,scale); expect_vec(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec2Lerp(&gotvec,NULL,&v,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec2Lerp(NULL,NULL,NULL,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec2Maximize__________________________*/ expectedvec.x = 3.0f; expectedvec.y = 9.0f; D3DXVec2Maximize(&gotvec,&u,&v); expect_vec(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec2Maximize(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec2Maximize(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec2Minimize__________________________*/ expectedvec.x = -7.0f; expectedvec.y = 4.0f; D3DXVec2Minimize(&gotvec,&u,&v); expect_vec(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec2Minimize(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec2Minimize(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec2Normalize_________________________*/ expectedvec.x = 0.6f; expectedvec.y = 0.8f; D3DXVec2Normalize(&gotvec,&u); expect_vec(expectedvec,gotvec); /* Test the nul vector */ expectedvec.x = 0.0f; expectedvec.y = 0.0f; D3DXVec2Normalize(&gotvec,&nul); expect_vec(expectedvec,gotvec); /*_______________D3DXVec2Scale____________________________*/ expectedvec.x = -19.5f; expectedvec.y = -26.0f; D3DXVec2Scale(&gotvec,&u,scale); expect_vec(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec2Scale(&gotvec,NULL,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec2Scale(NULL,NULL,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec2Subtract__________________________*/ expectedvec.x = 10.0f; expectedvec.y = -5.0f; D3DXVec2Subtract(&gotvec,&u,&v); expect_vec(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec2Subtract(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec2Subtract(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec2Transform_______________________*/ expectedtrans.x = 36.0f; expectedtrans.y = 44.0f; expectedtrans.z = 52.0f; expectedtrans.w = 60.0f; D3DXVec2Transform(&gottrans,&u,&mat); expect_vec4(expectedtrans,gottrans); /*_______________D3DXVec2TransformCoord_______________________*/ expectedvec.x = 0.6f; expectedvec.y = 11.0f/15.0f; D3DXVec2TransformCoord(&gotvec,&u,&mat); expect_vec(expectedvec,gotvec); /* Test the nul projected vector */ nulproj.x = -2.0f; nulproj.y = -1.0f; expectedvec.x = 0.0f; expectedvec.y = 0.0f; D3DXVec2TransformCoord(&gotvec,&nulproj,&mat); expect_vec(expectedvec,gotvec); /*_______________D3DXVec2TransformNormal______________________*/ expectedvec.x = 23.0f; expectedvec.y = 30.0f; D3DXVec2TransformNormal(&gotvec,&u,&mat); expect_vec(expectedvec,gotvec); } static void D3X8Vector3Test(void) { D3DVIEWPORT8 viewport; D3DXVECTOR3 expectedvec, gotvec, nul, nulproj, u, v, w, x; LPD3DXVECTOR3 funcpointer; D3DXVECTOR4 expectedtrans, gottrans; D3DXMATRIX mat, projection, view, world; FLOAT coeff1, coeff2, expected, got, scale; nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; u.x = 9.0f; u.y = 6.0f; u.z = 2.0f; v.x = 2.0f; v.y = -3.0f; v.z = -4.0; w.x = 3.0f; w.y = -5.0f; w.z = 7.0f; x.x = 4.0f; x.y = 1.0f; x.z = 11.0f; viewport.Width = 800; viewport.MinZ = 0.2f; viewport.X = 10; viewport.Height = 680; viewport.MaxZ = 0.9f; viewport.Y = 5; 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; 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; 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; 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; U(view).m[0][1] = 5.0f; U(view).m[0][2] = 7.0f; U(view).m[0][3] = 8.0f; U(view).m[1][0] = 11.0f; U(view).m[1][2] = 16.0f; U(view).m[1][3] = 33.0f; U(view).m[2][0] = 19.0f; U(view).m[2][1] = -21.0f; U(view).m[2][3] = 43.0f; U(view).m[3][0] = 2.0f; U(view).m[3][1] = 3.0f; U(view).m[3][2] = -4.0f; U(view).m[0][0] = 10.0f; U(view).m[1][1] = 20.0f; U(view).m[2][2] = 30.0f; U(view).m[3][3] = -40.0f; 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; 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; 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; 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; coeff1 = 2.0f; coeff2 = 5.0f; scale = -6.5f; /*_______________D3DXVec3Add__________________________*/ expectedvec.x = 11.0f; expectedvec.y = 3.0f; expectedvec.z = -2.0f; D3DXVec3Add(&gotvec,&u,&v); expect_vec3(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec3Add(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec3Add(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec3BaryCentric___________________*/ expectedvec.x = -35.0f; expectedvec.y = -67.0; expectedvec.z = 15.0f; D3DXVec3BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2); expect_vec3(expectedvec,gotvec); /*_______________D3DXVec3CatmullRom____________________*/ expectedvec.x = 1458.0f; expectedvec.y = 22.1875f; expectedvec.z = 4141.375f; D3DXVec3CatmullRom(&gotvec,&u,&v,&w,&x,scale); expect_vec3(expectedvec,gotvec); /*_______________D3DXVec3Cross________________________*/ expectedvec.x = -18.0f; expectedvec.y = 40.0f; expectedvec.z = -39.0f; D3DXVec3Cross(&gotvec,&u,&v); expect_vec3(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec3Cross(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec3Cross(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec3Dot__________________________*/ expected = -8.0f; got = D3DXVec3Dot(&u,&v); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec3Dot(NULL,&v); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); expected=0.0f; got = D3DXVec3Dot(NULL,NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec3Hermite__________________________*/ expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f; D3DXVec3Hermite(&gotvec,&u,&v,&w,&x,scale); expect_vec3(expectedvec,gotvec); /*_______________D3DXVec3Length__________________________*/ expected = 11.0f; got = D3DXVec3Length(&u); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec3Length(NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec3LengthSq________________________*/ expected = 121.0f; got = D3DXVec3LengthSq(&u); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec3LengthSq(NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec3Lerp__________________________*/ expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ; D3DXVec3Lerp(&gotvec,&u,&v,scale); expect_vec3(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec3Lerp(&gotvec,NULL,&v,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec3Lerp(NULL,NULL,NULL,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec3Maximize__________________________*/ expectedvec.x = 9.0f; expectedvec.y = 6.0f; expectedvec.z = 2.0f; D3DXVec3Maximize(&gotvec,&u,&v); expect_vec3(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec3Maximize(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec3Maximize(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec3Minimize__________________________*/ expectedvec.x = 2.0f; expectedvec.y = -3.0f; expectedvec.z = -4.0f; D3DXVec3Minimize(&gotvec,&u,&v); expect_vec3(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec3Minimize(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec3Minimize(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec3Normalize_________________________*/ expectedvec.x = 9.0f/11.0f; expectedvec.y = 6.0f/11.0f; expectedvec.z = 2.0f/11.0f; D3DXVec3Normalize(&gotvec,&u); expect_vec3(expectedvec,gotvec); /* Test the nul vector */ expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f; D3DXVec3Normalize(&gotvec,&nul); expect_vec3(expectedvec,gotvec); /*_______________D3DXVec3Project_________________________*/ expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f; D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f); D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world); expect_vec3(expectedvec,gotvec); /*_______________D3DXVec3Scale____________________________*/ expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f; D3DXVec3Scale(&gotvec,&u,scale); expect_vec3(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec3Scale(&gotvec,NULL,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec3Scale(NULL,NULL,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec3Subtract_______________________*/ expectedvec.x = 7.0f; expectedvec.y = 9.0f; expectedvec.z = 6.0f; D3DXVec3Subtract(&gotvec,&u,&v); expect_vec3(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec3Subtract(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec3Subtract(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec3Transform_______________________*/ expectedtrans.x = 70.0f; expectedtrans.y = 88.0f; expectedtrans.z = 106.0f; expectedtrans.w = 124.0f; D3DXVec3Transform(&gottrans,&u,&mat); expect_vec4(expectedtrans,gottrans); /*_______________D3DXVec3TransformCoord_______________________*/ expectedvec.x = 70.0f/124.0f; expectedvec.y = 88.0f/124.0f; expectedvec.z = 106.0f/124.0f; D3DXVec3TransformCoord(&gotvec,&u,&mat); expect_vec3(expectedvec,gotvec); /* Test the nul projected vector */ nulproj.x = 1.0f; nulproj.y = -1.0f, nulproj.z = -1.0f; expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f; D3DXVec3TransformCoord(&gotvec,&nulproj,&mat); expect_vec3(expectedvec,gotvec); /*_______________D3DXVec3TransformNormal______________________*/ expectedvec.x = 57.0f; expectedvec.y = 74.0f; expectedvec.z = 91.0f; D3DXVec3TransformNormal(&gotvec,&u,&mat); expect_vec3(expectedvec,gotvec); /*_______________D3DXVec3Unproject_________________________*/ expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f; D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f); D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&view,&world); expect_vec3(expectedvec,gotvec); } static void D3X8Vector4Test(void) { D3DXVECTOR4 expectedvec, gotvec, nul, u, v, w, x; LPD3DXVECTOR4 funcpointer; D3DXVECTOR4 expectedtrans, gottrans; D3DXMATRIX mat; FLOAT coeff1, coeff2, expected, got, scale; nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f; u.x = 1.0f; u.y = 2.0f; u.z = 4.0f; u.w = 10.0; v.x = -3.0f; v.y = 4.0f; v.z = -5.0f; v.w = 7.0; w.x = 4.0f; w.y =6.0f; w.z = -2.0f; w.w = 1.0f; x.x = 6.0f; x.y = -7.0f; x.z =8.0f; x.w = -9.0f; 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; 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; 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; 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; coeff1 = 2.0f; coeff2 = 5.0; scale = -6.5f; /*_______________D3DXVec4Add__________________________*/ expectedvec.x = -2.0f; expectedvec.y = 6.0f; expectedvec.z = -1.0f; expectedvec.w = 17.0f; D3DXVec4Add(&gotvec,&u,&v); expect_vec4(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec4Add(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec4Add(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec4BaryCentric____________________*/ expectedvec.x = 8.0f; expectedvec.y = 26.0; expectedvec.z = -44.0f; expectedvec.w = -41.0f; D3DXVec4BaryCentric(&gotvec,&u,&v,&w,coeff1,coeff2); expect_vec4(expectedvec,gotvec); /*_______________D3DXVec4CatmullRom____________________*/ expectedvec.x = 2754.625f; expectedvec.y = 2367.5625f; expectedvec.z = 1060.1875f; expectedvec.w = 131.3125f; D3DXVec4CatmullRom(&gotvec,&u,&v,&w,&x,scale); expect_vec4(expectedvec,gotvec); /*_______________D3DXVec4Cross_________________________*/ expectedvec.x = 390.0f; expectedvec.y = -393.0f; expectedvec.z = -316.0f; expectedvec.w = 166.0f; D3DXVec4Cross(&gotvec,&u,&v,&w); expect_vec4(expectedvec,gotvec); /*_______________D3DXVec4Dot__________________________*/ expected = 55.0f; got = D3DXVec4Dot(&u,&v); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec4Dot(NULL,&v); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); expected=0.0f; got = D3DXVec4Dot(NULL,NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec4Hermite_________________________*/ expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f; D3DXVec4Hermite(&gotvec,&u,&v,&w,&x,scale); expect_vec4(expectedvec,gotvec); /*_______________D3DXVec4Length__________________________*/ expected = 11.0f; got = D3DXVec4Length(&u); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec4Length(NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec4LengthSq________________________*/ expected = 121.0f; got = D3DXVec4LengthSq(&u); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec4LengthSq(NULL); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec4Lerp__________________________*/ expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5; expectedvec.w = 29.5; D3DXVec4Lerp(&gotvec,&u,&v,scale); expect_vec4(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec4Lerp(&gotvec,NULL,&v,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec4Lerp(NULL,NULL,NULL,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec4Maximize__________________________*/ expectedvec.x = 1.0f; expectedvec.y = 4.0f; expectedvec.z = 4.0f; expectedvec.w = 10.0; D3DXVec4Maximize(&gotvec,&u,&v); expect_vec4(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec4Maximize(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec4Maximize(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec4Minimize__________________________*/ expectedvec.x = -3.0f; expectedvec.y = 2.0f; expectedvec.z = -5.0f; expectedvec.w = 7.0; D3DXVec4Minimize(&gotvec,&u,&v); expect_vec4(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec4Minimize(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec4Minimize(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec4Normalize_________________________*/ expectedvec.x = 1.0f/11.0f; expectedvec.y = 2.0f/11.0f; expectedvec.z = 4.0f/11.0f; expectedvec.w = 10.0f/11.0f; D3DXVec4Normalize(&gotvec,&u); expect_vec4(expectedvec,gotvec); /* Test the nul vector */ expectedvec.x = 0.0f; expectedvec.y = 0.0f; expectedvec.z = 0.0f; expectedvec.w = 0.0f; D3DXVec4Normalize(&gotvec,&nul); expect_vec4(expectedvec,gotvec); /*_______________D3DXVec4Scale____________________________*/ expectedvec.x = -6.5f; expectedvec.y = -13.0f; expectedvec.z = -26.0f; expectedvec.w = -65.0f; D3DXVec4Scale(&gotvec,&u,scale); expect_vec4(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec4Scale(&gotvec,NULL,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec4Scale(NULL,NULL,scale); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec4Subtract__________________________*/ expectedvec.x = 4.0f; expectedvec.y = -2.0f; expectedvec.z = 9.0f; expectedvec.w = 3.0f; D3DXVec4Subtract(&gotvec,&u,&v); expect_vec4(expectedvec,gotvec); /* Tests the case NULL */ funcpointer = D3DXVec4Subtract(&gotvec,NULL,&v); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); funcpointer = D3DXVec4Subtract(NULL,NULL,NULL); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); /*_______________D3DXVec4Transform_______________________*/ expectedtrans.x = 177.0f; expectedtrans.y = 194.0f; expectedtrans.z = 211.0f; expectedtrans.w = 228.0f; D3DXVec4Transform(&gottrans,&u,&mat); expect_vec4(expectedtrans,gottrans); } START_TEST(math) { D3DXColorTest(); D3DXMatrixTest(); D3DXPlaneTest(); D3X8QuaternionTest(); D3X8Vector2Test(); D3X8Vector3Test(); D3X8Vector4Test(); }