David Adam : d3dx8: Implement D3DXComputeBoundingBox.

Alexandre Julliard julliard at winehq.org
Fri Feb 6 09:56:14 CST 2009


Module: wine
Branch: master
Commit: f1bb04ff8a421378508302b978bd54b097812f16
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f1bb04ff8a421378508302b978bd54b097812f16

Author: David Adam <david.adam.cnrs at gmail.com>
Date:   Fri Feb  6 11:42:01 2009 +0100

d3dx8: Implement D3DXComputeBoundingBox.

---

 dlls/d3dx8/d3dx8.spec   |    2 +-
 dlls/d3dx8/mesh.c       |   28 +++++++++++++++++++
 dlls/d3dx8/tests/mesh.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++
 include/d3dx8mesh.h     |    1 +
 4 files changed, 98 insertions(+), 1 deletions(-)

diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index ff9ec79..88666f7 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -93,7 +93,7 @@
 @ stub D3DXGeneratePMesh
 @ stub D3DXSimplifyMesh
 @ stdcall D3DXComputeBoundingSphere(ptr long long ptr ptr)
-@ stub D3DXComputeBoundingBox
+@ stdcall D3DXComputeBoundingBox(ptr long long ptr ptr)
 @ stub D3DXComputeNormals
 @ stdcall D3DXCreateBuffer(long ptr)
 @ stub D3DXLoadMeshFromX
diff --git a/dlls/d3dx8/mesh.c b/dlls/d3dx8/mesh.c
index 43d309f..baa5f20 100644
--- a/dlls/d3dx8/mesh.c
+++ b/dlls/d3dx8/mesh.c
@@ -97,6 +97,34 @@ done we've got an intersection of the ray with the box.
     return TRUE;
 }
 
+HRESULT WINAPI D3DXComputeBoundingBox(PVOID ppointsFVF, DWORD numvertices, DWORD FVF, D3DXVECTOR3 *pmin, D3DXVECTOR3 *pmax)
+{
+    D3DXVECTOR3 vec;
+    unsigned int i;
+
+    if( !ppointsFVF || !pmin || !pmax ) return D3DERR_INVALIDCALL;
+
+    *pmin = *(D3DXVECTOR3*)((char*)ppointsFVF);
+    *pmax = *pmin;
+
+/* It looks like that D3DXComputeBoundingBox does not take in account the last vertex. */
+    for(i=0; i<numvertices-1; i++)
+    {
+        vec = *(D3DXVECTOR3*)((char*)ppointsFVF + D3DXGetFVFVertexSize(FVF) * i);
+
+        if ( vec.x < pmin->x ) pmin->x = vec.x;
+        if ( vec.x > pmax->x ) pmax->x = vec.x;
+
+        if ( vec.y < pmin->y ) pmin->y = vec.y;
+        if ( vec.y > pmax->y ) pmax->y = vec.y;
+
+        if ( vec.z < pmin->z ) pmin->z = vec.z;
+        if ( vec.z > pmax->z ) pmax->z = vec.z;
+    }
+
+    return D3D_OK;
+}
+
 HRESULT WINAPI D3DXComputeBoundingSphere(PVOID ppointsFVF, DWORD numvertices, DWORD FVF, D3DXVECTOR3 *pcenter, FLOAT *pradius)
 {
     D3DXVECTOR3 temp, temp1;
diff --git a/dlls/d3dx8/tests/mesh.c b/dlls/d3dx8/tests/mesh.c
index 26d1d21..c16ee15 100644
--- a/dlls/d3dx8/tests/mesh.c
+++ b/dlls/d3dx8/tests/mesh.c
@@ -111,6 +111,73 @@ static void D3DXBoundProbeTest(void)
     ok(result == FALSE, "expected FALSE, received TRUE\n");
 }
 
+static void D3DXComputeBoundingBoxTest(void)
+{
+    D3DXVECTOR3 exp_max, exp_min, got_max, got_min, vertex[5];
+    HRESULT hr;
+
+    vertex[0].x = 1.0f; vertex[0].y = 1.0f; vertex[0].z = 1.0f;
+    vertex[1].x = 1.0f; vertex[1].y = 1.0f; vertex[1].z = 1.0f;
+    vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 1.0f;
+    vertex[3].x = 1.0f; vertex[3].y = 1.0f; vertex[3].z = 1.0f;
+    vertex[4].x = 9.0f; vertex[4].y = 9.0f; vertex[4].z = 9.0f;
+
+    exp_min.x = 1.0f; exp_min.y = 1.0f; exp_min.z = 1.0f;
+    exp_max.x = 1.0f; exp_max.y = 1.0f; exp_max.z = 1.0f;
+
+    hr = D3DXComputeBoundingBox(&vertex[3],2,D3DFVF_XYZ,&got_min,&got_max);
+
+    ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
+    ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
+    ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);
+
+/*________________________*/
+
+    vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
+    vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
+    vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
+    vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
+    vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;
+
+    exp_min.x = -6.92f; exp_min.y = -0.90f; exp_min.z = -3.80f;
+    exp_max.x = 7.43f; exp_max.y = 7.90f; exp_max.z = 11.9f;
+
+    hr = D3DXComputeBoundingBox(&vertex[0],5,D3DFVF_XYZ,&got_min,&got_max);
+
+    ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
+    ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
+    ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);
+
+/*________________________*/
+
+    vertex[0].x = 2.0f; vertex[0].y = 5.9f; vertex[0].z = -1.2f;
+    vertex[1].x = -1.87f; vertex[1].y = 7.9f; vertex[1].z = 7.4f;
+    vertex[2].x = 7.43f; vertex[2].y = -0.9f; vertex[2].z = 11.9f;
+    vertex[3].x = -6.92f; vertex[3].y = 6.3f; vertex[3].z = -3.8f;
+    vertex[4].x = 11.4f; vertex[4].y = -8.1f; vertex[4].z = 4.5f;
+
+    exp_min.x = -1.87f; exp_min.y = -0.90f; exp_min.z = -1.20f;
+    exp_max.x = 7.43f; exp_max.y = 7.90f; exp_max.z = 11.9f;
+
+    hr = D3DXComputeBoundingBox(&vertex[0],4,D3DFVF_XYZ,&got_min,&got_max);
+
+    ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
+    ok( compare_vec3(exp_min,got_min), "Expected min: (%f, %f, %f), got: (%f, %f, %f)\n", exp_min.x,exp_min.y,exp_min.z,got_min.x,got_min.y,got_min.z);
+    ok( compare_vec3(exp_max,got_max), "Expected max: (%f, %f, %f), got: (%f, %f, %f)\n", exp_max.x,exp_max.y,exp_max.z,got_max.x,got_max.y,got_max.z);
+
+/*________________________*/
+    hr = D3DXComputeBoundingBox(NULL,5,D3DFVF_XYZ,&got_min,&got_max);
+    ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
+
+/*________________________*/
+    hr = D3DXComputeBoundingBox(&vertex[3],5,D3DFVF_XYZ,NULL,&got_max);
+    ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
+
+/*________________________*/
+    hr = D3DXComputeBoundingBox(&vertex[3],5,D3DFVF_XYZ,&got_min,NULL);
+    ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
+}
+
 static void D3DXComputeBoundingSphereTest(void)
 {
     D3DXVECTOR3 exp_cen, got_cen, vertex[5];
@@ -322,6 +389,7 @@ static void D3DXIntersectTriTest(void)
 START_TEST(mesh)
 {
     D3DXBoundProbeTest();
+    D3DXComputeBoundingBoxTest();
     D3DXComputeBoundingSphereTest();
     D3DXGetFVFVertexSizeTest();
     D3DXIntersectTriTest();
diff --git a/include/d3dx8mesh.h b/include/d3dx8mesh.h
index 64c0be5..7f9262d 100644
--- a/include/d3dx8mesh.h
+++ b/include/d3dx8mesh.h
@@ -31,6 +31,7 @@ UINT    WINAPI D3DXGetFVFVertexSize(DWORD);
 BOOL    WINAPI D3DXBoxBoundProbe(CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *);
 BOOL    WINAPI D3DXSphereBoundProbe(CONST D3DXVECTOR3 *,FLOAT,CONST D3DXVECTOR3 *,CONST D3DXVECTOR3 *);
 BOOL    CDECL  D3DXIntersectTri(CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, FLOAT *, FLOAT *, FLOAT *);
+HRESULT WINAPI D3DXComputeBoundingBox(PVOID, DWORD, DWORD, D3DXVECTOR3 *, D3DXVECTOR3 *);
 HRESULT WINAPI D3DXComputeBoundingSphere(PVOID, DWORD, DWORD, D3DXVECTOR3 *, FLOAT *);
 
 #ifdef __cplusplus




More information about the wine-cvs mailing list