diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec index 07d62350dbc..9d1efd2ca1e 100644 --- a/dlls/d3dx8/d3dx8.spec +++ b/dlls/d3dx8/d3dx8.spec @@ -30,7 +30,7 @@ @ stdcall D3DXMatrixRotationY(ptr long) @ stdcall D3DXMatrixRotationZ(ptr long) @ stdcall D3DXMatrixRotationAxis(ptr ptr long) -@ stub D3DXMatrixRotationQuaternion +@ stdcall D3DXMatrixRotationQuaternion(ptr ptr) @ stub D3DXMatrixRotationYawPitchRoll @ stub D3DXMatrixTransformation @ stub D3DXMatrixAffineTransformation diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c index bfda84e6b66..d7064a7f92b 100644 --- a/dlls/d3dx8/math.c +++ b/dlls/d3dx8/math.c @@ -76,6 +76,21 @@ D3DXMATRIX* WINAPI D3DXMatrixRotationAxis(D3DXMATRIX *pout, CONST D3DXVECTOR3 *p return pout; } +D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion(D3DXMATRIX *pout, CONST D3DXQUATERNION *pq) +{ + D3DXMatrixIdentity(pout); + pout->m[0][0] = 1.0f - 2.0f * (pq->y * pq->y + pq->z * pq->z); + pout->m[0][1] = 2.0f * (pq->x *pq->y + pq->z * pq->w); + pout->m[0][2] = 2.0f * (pq->x * pq->z - pq->y * pq->w); + pout->m[1][0] = 2.0f * (pq->x * pq->y - pq->z * pq->w); + pout->m[1][1] = 1.0f - 2.0f * (pq->x * pq->x + pq->z * pq->z); + pout->m[1][2] = 2.0f * (pq->y *pq->z + pq->x *pq->w); + pout->m[2][0] = 2.0f * (pq->x * pq->z + pq->y * pq->w); + pout->m[2][1] = 2.0f * (pq->y *pq->z - pq->x *pq->w); + pout->m[2][2] = 1.0f - 2.0f * (pq->x * pq->x + pq->y * pq->y); + return pout; +} + D3DXMATRIX* WINAPI D3DXMatrixRotationX(D3DXMATRIX *pout, FLOAT angle) { D3DXMatrixIdentity(pout); diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c index 22491d82508..a5e6e47be8d 100644 --- a/dlls/d3dx8/tests/math.c +++ b/dlls/d3dx8/tests/math.c @@ -149,6 +149,7 @@ static void D3DXColorTest(void) static void D3DXMatrixTest(void) { D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3; + D3DXQUATERNION q; D3DXVECTOR3 axis; BOOL expected, got; FLOAT angle, expectedfloat, gotfloat; @@ -167,6 +168,8 @@ static void D3DXMatrixTest(void) mat2.m[0][3] = -4.0f; mat2.m[1][3] = -3.0f; mat2.m[2][3] = -2.0f; mat2.m[3][3] = -1.0f; + q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f; + axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f; angle = D3DX_PI/3.0f; @@ -209,6 +212,14 @@ static void D3DXMatrixTest(void) D3DXMatrixRotationAxis(&gotmat,&axis,angle); expect_mat(expectedmat,gotmat); +/*____________D3DXMatrixRotationQuaternion______________*/ + expectedmat.m[0][0] = -129.0f; expectedmat.m[0][1] = -162.0f; expectedmat.m[0][2] = -74.0f; expectedmat.m[0][3] = 0.0f; + expectedmat.m[1][0] = 146.0f; expectedmat.m[1][1] = -99.0f; expectedmat.m[1][2] = -78.0f; expectedmat.m[1][3] = 0.0f; + expectedmat.m[2][0] = 102.0f; expectedmat.m[2][1] = -34.0f; expectedmat.m[2][2] = -33.0f; expectedmat.m[2][3] = 0.0f; + expectedmat.m[3][0] = 0.0f; expectedmat.m[3][1] = 0.0f; expectedmat.m[3][2] = 0.0f; expectedmat.m[3][3] = 1.0f; + D3DXMatrixRotationQuaternion(&gotmat,&q); + expect_mat(expectedmat,gotmat); + /*____________D3DXMatrixRotationX______________*/ expectedmat.m[0][0] = 1.0f; expectedmat.m[0][1] = 0.0f; expectedmat.m[0][2] = 0.0f; expectedmat.m[0][3] = 0.0f; expectedmat.m[1][0] = 0.0; expectedmat.m[1][1] = 0.5f; expectedmat.m[1][2] = sqrt(3.0f)/2.0f; expectedmat.m[1][3] = 0.0f; diff --git a/include/d3dx8math.h b/include/d3dx8math.h index 3e4d25ec3a2..8e56970cf91 100644 --- a/include/d3dx8math.h +++ b/include/d3dx8math.h @@ -61,6 +61,7 @@ typedef struct D3DXCOLOR FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm); D3DXMATRIX* WINAPI D3DXMatrixMultiply(D3DXMATRIX *pout, CONST D3DXMATRIX *pm1, CONST D3DXMATRIX *pm2); D3DXMATRIX* WINAPI D3DXMatrixRotationAxis(D3DXMATRIX *pout, CONST D3DXVECTOR3 *pv, FLOAT angle); +D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion(D3DXMATRIX *pout, CONST D3DXQUATERNION *pq); D3DXMATRIX* WINAPI D3DXMatrixRotationX(D3DXMATRIX *pout, FLOAT angle); D3DXMATRIX* WINAPI D3DXMatrixRotationY(D3DXMATRIX *pout, FLOAT angle); D3DXMATRIX* WINAPI D3DXMatrixRotationZ(D3DXMATRIX *pout, FLOAT angle);