Commit 0ccc431a authored by David Adam's avatar David Adam Committed by Alexandre Julliard

d3dx8: Implement D3DXComputeBoundingSphere.

parent 1d3889fa
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
@ stub D3DXValidMesh @ stub D3DXValidMesh
@ stub D3DXGeneratePMesh @ stub D3DXGeneratePMesh
@ stub D3DXSimplifyMesh @ stub D3DXSimplifyMesh
@ stub D3DXComputeBoundingSphere @ stdcall D3DXComputeBoundingSphere(ptr long long ptr ptr)
@ stub D3DXComputeBoundingBox @ stub D3DXComputeBoundingBox
@ stub D3DXComputeNormals @ stub D3DXComputeNormals
@ stdcall D3DXCreateBuffer(long ptr) @ stdcall D3DXCreateBuffer(long ptr)
......
...@@ -97,6 +97,37 @@ done we've got an intersection of the ray with the box. ...@@ -97,6 +97,37 @@ done we've got an intersection of the ray with the box.
return TRUE; return TRUE;
} }
HRESULT WINAPI D3DXComputeBoundingSphere(PVOID ppointsFVF, DWORD numvertices, DWORD FVF, D3DXVECTOR3 *pcenter, FLOAT *pradius)
{
D3DXVECTOR3 temp, temp1;
FLOAT d;
unsigned int i;
if( !ppointsFVF || !pcenter || !pradius ) return D3DERR_INVALIDCALL;
temp.x = 0.0f;
temp.y = 0.0f;
temp.z = 0.0f;
temp1 = temp;
d = 0.0f;
*pradius = 0.0f;
for(i=0; i<numvertices; i++)
{
D3DXVec3Add(&temp1, &temp, (D3DXVECTOR3*)((char*)ppointsFVF + D3DXGetFVFVertexSize(FVF) * i));
temp = temp1;
}
D3DXVec3Scale(pcenter, &temp, 1.0f/((FLOAT)numvertices));
for(i=0; i<numvertices; i++)
{
d = D3DXVec3Length(D3DXVec3Subtract(&temp, (D3DXVECTOR3*)((char*)ppointsFVF + D3DXGetFVFVertexSize(FVF) * i), pcenter));
if ( d > *pradius ) *pradius = d;
}
return D3D_OK;
}
static UINT Get_TexCoord_Size_From_FVF(DWORD FVF, int tex_num) static UINT Get_TexCoord_Size_From_FVF(DWORD FVF, int tex_num)
{ {
return (((((FVF) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1); return (((((FVF) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1);
......
...@@ -32,6 +32,11 @@ static BOOL compare(FLOAT u, FLOAT v) ...@@ -32,6 +32,11 @@ static BOOL compare(FLOAT u, FLOAT v)
return (fabs(u-v) < admitted_error); return (fabs(u-v) < admitted_error);
} }
BOOL compare_vec3(D3DXVECTOR3 u, D3DXVECTOR3 v)
{
return ( compare(u.x, v.x) && compare(u.y, v.y) && compare(u.z, v.z) );
}
static void D3DXBoundProbeTest(void) static void D3DXBoundProbeTest(void)
{ {
BOOL result; BOOL result;
...@@ -106,6 +111,57 @@ static void D3DXBoundProbeTest(void) ...@@ -106,6 +111,57 @@ static void D3DXBoundProbeTest(void)
ok(result == FALSE, "expected FALSE, received TRUE\n"); ok(result == FALSE, "expected FALSE, received TRUE\n");
} }
static void D3DXComputeBoundingSphereTest(void)
{
D3DXVECTOR3 exp_cen, got_cen, vertex[5];
FLOAT exp_rad, got_rad;
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_rad = 6.928203f;
exp_cen.x = 5.0; exp_cen.y = 5.0; exp_cen.z = 5.0;
hr = D3DXComputeBoundingSphere(&vertex[3],2,D3DFVF_XYZ,&got_cen,&got_rad);
ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
ok( compare(exp_rad, got_rad), "Expected radius: %f, got radius: %f\n", exp_rad, got_rad);
ok( compare_vec3(exp_cen,got_cen), "Expected center: (%f, %f, %f), got center: (%f, %f, %f)\n", exp_cen.x,exp_cen.y,exp_cen.z,got_cen.x,got_cen.y,got_cen.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_rad = 13.707883f;
exp_cen.x = 2.408f; exp_cen.y = 2.22f; exp_cen.z = 3.76f;
hr = D3DXComputeBoundingSphere(&vertex[0],5,D3DFVF_XYZ,&got_cen,&got_rad);
ok( hr == D3D_OK, "Expected D3D_OK, got %#x\n", hr);
ok( compare(exp_rad, got_rad), "Expected radius: %f, got radius: %f\n", exp_rad, got_rad);
ok( compare_vec3(exp_cen,got_cen), "Expected center: (%f, %f, %f), got center: (%f, %f, %f)\n", exp_cen.x,exp_cen.y,exp_cen.z,got_cen.x,got_cen.y,got_cen.z);
/*________________________*/
hr = D3DXComputeBoundingSphere(NULL,5,D3DFVF_XYZ,&got_cen,&got_rad);
ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
/*________________________*/
hr = D3DXComputeBoundingSphere(&vertex[3],5,D3DFVF_XYZ,NULL,&got_rad);
ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
/*________________________*/
hr = D3DXComputeBoundingSphere(&vertex[3],5,D3DFVF_XYZ,&got_cen,NULL);
ok( hr == D3DERR_INVALIDCALL, "Expected D3DERR_INVALIDCALL, got %#x\n", hr);
}
static void D3DXGetFVFVertexSizeTest(void) static void D3DXGetFVFVertexSizeTest(void)
{ {
UINT got; UINT got;
...@@ -266,6 +322,7 @@ static void D3DXIntersectTriTest(void) ...@@ -266,6 +322,7 @@ static void D3DXIntersectTriTest(void)
START_TEST(mesh) START_TEST(mesh)
{ {
D3DXBoundProbeTest(); D3DXBoundProbeTest();
D3DXComputeBoundingSphereTest();
D3DXGetFVFVertexSizeTest(); D3DXGetFVFVertexSizeTest();
D3DXIntersectTriTest(); D3DXIntersectTriTest();
} }
...@@ -31,6 +31,7 @@ UINT WINAPI D3DXGetFVFVertexSize(DWORD); ...@@ -31,6 +31,7 @@ UINT WINAPI D3DXGetFVFVertexSize(DWORD);
BOOL WINAPI D3DXBoxBoundProbe(CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *); BOOL WINAPI D3DXBoxBoundProbe(CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *);
BOOL WINAPI D3DXSphereBoundProbe(CONST D3DXVECTOR3 *,FLOAT,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 *); BOOL CDECL D3DXIntersectTri(CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, FLOAT *, FLOAT *, FLOAT *);
HRESULT WINAPI D3DXComputeBoundingSphere(PVOID, DWORD, DWORD, D3DXVECTOR3 *, FLOAT *);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment