d3dx9: Simplify D3DXSphereBoundProbe() a bit.

Spurred by a patch by Alex Henrie.

Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Matteo Bruni 2020-07-09 21:35:49 +02:00 committed by Alexandre Julliard
parent ea7cf67915
commit 18ae539c91
2 changed files with 38 additions and 13 deletions

View File

@ -2409,20 +2409,21 @@ BOOL WINAPI D3DXIntersectTri(const D3DXVECTOR3 *p0, const D3DXVECTOR3 *p1, const
return FALSE;
}
BOOL WINAPI D3DXSphereBoundProbe(const D3DXVECTOR3 *pcenter, float radius,
const D3DXVECTOR3 *prayposition, const D3DXVECTOR3 *praydirection)
BOOL WINAPI D3DXSphereBoundProbe(const D3DXVECTOR3 *center, float radius,
const D3DXVECTOR3 *ray_position, const D3DXVECTOR3 *ray_direction)
{
D3DXVECTOR3 difference;
FLOAT a, b, c, d;
D3DXVECTOR3 difference = {0};
float a, b, c, d;
a = D3DXVec3LengthSq(praydirection);
if (!D3DXVec3Subtract(&difference, prayposition, pcenter)) return FALSE;
b = D3DXVec3Dot(&difference, praydirection);
D3DXVec3Subtract(&difference, ray_position, center);
c = D3DXVec3LengthSq(&difference) - radius * radius;
if (c < 0.0f)
return TRUE;
a = D3DXVec3LengthSq(ray_direction);
b = D3DXVec3Dot(&difference, ray_direction);
d = b * b - a * c;
if ( ( d <= 0.0f ) || ( sqrt(d) <= b ) ) return FALSE;
return TRUE;
return d >= 0.0f && (b <= 0.0f || d > b * b);
}
/*************************************************************************

View File

@ -435,18 +435,42 @@ static void D3DXBoundProbeTest(void)
radius = sqrt(77.0f);
center.x = 1.0f; center.y = 2.0f; center.z = 3.0f;
raydirection.x = 2.0f; raydirection.y = -4.0f; raydirection.z = 2.0f;
rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 9.0f;
result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
ok(result == TRUE, "expected TRUE, received FALSE\n");
ok(result == TRUE, "Got unexpected result %#x.\n", result);
rayposition.x = 45.0f; rayposition.y = -75.0f; rayposition.z = 49.0f;
result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
ok(result == FALSE, "expected FALSE, received TRUE\n");
ok(result == FALSE, "Got unexpected result %#x.\n", result);
raydirection.x = -2.0f; raydirection.y = 4.0f; raydirection.z = -2.0f;
result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
ok(result == TRUE, "Got unexpected result %#x.\n", result);
rayposition.x = 5.0f; rayposition.y = 11.0f; rayposition.z = 9.0f;
result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
ok(result == FALSE, "expected FALSE, received TRUE\n");
ok(result == FALSE, "Got unexpected result %#x.\n", result);
raydirection.x = 2.0f; raydirection.y = -4.0f; raydirection.z = 2.0f;
result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
ok(result == FALSE, "Got unexpected result %#x.\n", result);
radius = 1.0f;
rayposition.x = 2.0f; rayposition.y = 2.0f; rayposition.z = 3.0f;
result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
ok(result == FALSE, "Got unexpected result %#x.\n", result);
raydirection.x = 0.0f; raydirection.y = 0.0f; raydirection.z = 1.0f;
result = D3DXSphereBoundProbe(&center, radius, &rayposition, &raydirection);
ok(result == TRUE, "Got unexpected result %#x.\n", result);
if (0)
{
/* All these crash on native. */
D3DXSphereBoundProbe(&center, radius, &rayposition, NULL);
D3DXSphereBoundProbe(&center, radius, NULL, &raydirection);
D3DXSphereBoundProbe(NULL, radius, &rayposition, &raydirection);
}
}
static void D3DXComputeBoundingBoxTest(void)