[PATCH] Implement D3DXMatrixLookAtRH with a test

David Adam David.Adam at math.cnrs.fr
Sat Nov 3 03:33:51 CDT 2007


---
 dlls/d3dx8/d3dx8.spec   |    2 +-
 dlls/d3dx8/math.c       |   29 +++++++++++++++++++++++++++++
 dlls/d3dx8/tests/math.c |   12 +++++++++++-
 include/d3dx8math.h     |    1 +
 4 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index c19c105..25f3bc4 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -34,7 +34,7 @@
 @ stdcall D3DXMatrixRotationYawPitchRoll(ptr long long long)
 @ stub D3DXMatrixTransformation
 @ stub D3DXMatrixAffineTransformation
-@ stub D3DXMatrixLookAtRH
+@ stdcall D3DXMatrixLookAtRH(ptr ptr ptr ptr ptr)
 @ stub D3DXMatrixLookAtLH
 @ stub D3DXMatrixPerspectiveRH
 @ stub D3DXMatrixPerspectiveLH
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index c81e621..2de1bd1 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -44,6 +44,35 @@ FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm)
     return det;
 }
=20
+D3DXMATRIX* WINAPI D3DXMatrixLookAtRH(D3DXMATRIX *pout, CONST D3DXVECTOR3 *=
peye, CONST D3DXVECTOR3 *pat, CONST D3DXVECTOR3 *pup)
+{
+    D3DXVECTOR3 right, rightn, up, upn, vec, vec2;
+
+    D3DXVec3Subtract(&vec2, pat, peye);
+    D3DXVec3Normalize(&vec, &vec2);
+    D3DXVec3Cross(&right, pup, &vec);
+    D3DXVec3Cross(&up, &vec, &right);
+    D3DXVec3Normalize(&rightn, &right);
+    D3DXVec3Normalize(&upn, &up);
+    pout->m[0][0] =3D -rightn.x;
+    pout->m[1][0] =3D -rightn.y;
+    pout->m[2][0] =3D -rightn.z;
+    pout->m[3][0] =3D D3DXVec3Dot(&rightn,peye);
+    pout->m[0][1] =3D upn.x;
+    pout->m[1][1] =3D upn.y;
+    pout->m[2][1] =3D upn.z;
+    pout->m[3][1] =3D -D3DXVec3Dot(&upn, peye);
+    pout->m[0][2] =3D -vec.x;
+    pout->m[1][2] =3D -vec.y;
+    pout->m[2][2] =3D -vec.z;
+    pout->m[3][2] =3D D3DXVec3Dot(&vec, peye);
+    pout->m[0][3] =3D 0.0f;
+    pout->m[1][3] =3D 0.0f;
+    pout->m[2][3] =3D 0.0f;
+    pout->m[3][3] =3D 1.0f;
+    return pout;
+}
+
 D3DXMATRIX* WINAPI D3DXMatrixMultiply(D3DXMATRIX *pout, CONST D3DXMATRIX *p=
m1, CONST D3DXMATRIX *pm2)
 {
     int i,j;
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index d79bfc7..71da793 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -150,7 +150,7 @@ static void D3DXMatrixTest(void)
 {
     D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
     D3DXQUATERNION q;
-    D3DXVECTOR3 axis;
+    D3DXVECTOR3 at, axis, eye;
     BOOL expected, got;
     FLOAT angle, expectedfloat, gotfloat;
=20
@@ -170,7 +170,9 @@ static void D3DXMatrixTest(void)
=20
     q.x =3D 1.0f; q.y =3D -4.0f; q.z =3D7.0f; q.w =3D -11.0f;
=20
+    at.x =3D -2.0f; at.y =3D 13.0f; at.z =3D -9.0f;
     axis.x =3D 1.0f; axis.y =3D -3.0f; axis.z =3D 7.0f;
+    eye.x =3D 8.0f; eye.y =3D -5.0f; eye.z =3D 5.75f;
=20
     angle =3D D3DX_PI/3.0f;
=20
@@ -196,6 +198,14 @@ static void D3DXMatrixTest(void)
     got =3D D3DXMatrixIsIdentity(NULL);
     ok(expected =3D=3D got, "Expected : %d, Got : %d\n", expected, got);
=20
+/*____________D3DXMatrixLookatRH_______________*/
+    expectedmat.m[0][0] =3D 0.822465f; expectedmat.m[0][1] =3D -0.409489f; =
expectedmat.m[0][2] =3D 0.394803f; expectedmat.m[0][3] =3D 0.0f;
+    expectedmat.m[1][0] =3D 0.555856f; expectedmat.m[1][1] =3D 0.431286f; e=
xpectedmat.m[1][2] =3D -0.710645f; expectedmat.m[1][3] =3D 0.0f;
+    expectedmat.m[2][0] =3D 0.120729f; expectedmat.m[2][1] =3D 0.803935f; e=
xpectedmat.m[2][2] =3D 0.582335f; expectedmat.m[2][3] =3D 0.0f;
+    expectedmat.m[3][0] =3D -4.494634f; expectedmat.m[3][1] =3D 0.809719f; =
expectedmat.m[3][2] =3D -10.060076f; expectedmat.m[3][3] =3D 1.0f;
+    D3DXMatrixLookAtRH(&gotmat,&eye,&at,&axis);
+    expect_mat(expectedmat,gotmat);
+
 /*____________D3DXMatrixMultiply______________*/
     expectedmat.m[0][0] =3D 73.0f; expectedmat.m[0][1] =3D 193.0f; expected=
mat.m[0][2] =3D -197.0f; expectedmat.m[0][3] =3D -77.0f;
     expectedmat.m[1][0] =3D 231.0f; expectedmat.m[1][1] =3D 551.0f; expecte=
dmat.m[1][2] =3D -489.0f; expectedmat.m[1][3] =3D -169.0;
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index 657623c..b31e24d 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -59,6 +59,7 @@ typedef struct D3DXCOLOR
 } D3DXCOLOR, *LPD3DXCOLOR;
=20
 FLOAT WINAPI D3DXMatrixfDeterminant(CONST D3DXMATRIX *pm);
+D3DXMATRIX* WINAPI D3DXMatrixLookAtRH(D3DXMATRIX *pout, CONST D3DXVECTOR3 *=
peye, CONST D3DXVECTOR3 *pat, CONST D3DXVECTOR3 *pup);
 D3DXMATRIX* WINAPI D3DXMatrixMultiply(D3DXMATRIX *pout, CONST D3DXMATRIX *p=
m1, CONST D3DXMATRIX *pm2);
 D3DXMATRIX* WINAPI D3DXMatrixRotationAxis(D3DXMATRIX *pout, CONST D3DXVECTO=
R3 *pv, FLOAT angle);
 D3DXMATRIX* WINAPI D3DXMatrixRotationQuaternion(D3DXMATRIX *pout, CONST D3D=
XQUATERNION *pq);
--=20
1.5.3.2


--=_2ygplxx9r1c0--



More information about the wine-patches mailing list