Commit b8eb4cf8 authored by David Adam's avatar David Adam Committed by Alexandre Julliard

d3dx8: Implement D3DXIntersectTri.

parent 5bef4520
......@@ -109,6 +109,7 @@
@ stub D3DXFVFFromDeclarator
@ stub D3DXWeldVertices
@ stub D3DXIntersect
@ cdecl D3DXIntersectTri(ptr ptr ptr ptr ptr ptr ptr ptr)
@ stdcall D3DXSphereBoundProbe(ptr long ptr ptr)
@ stdcall D3DXBoxBoundProbe(ptr ptr ptr ptr)
@ stub D3DXCreatePolygon
......
......@@ -90,6 +90,48 @@ done we've got an intersection of the ray with the box.
return TRUE;
}
BOOL CDECL D3DXIntersectTri(CONST D3DXVECTOR3 *p0, CONST D3DXVECTOR3 *p1, CONST D3DXVECTOR3 *p2, CONST D3DXVECTOR3 *praypos, CONST D3DXVECTOR3 *praydir, FLOAT *pu, FLOAT *pv, FLOAT *pdist)
{
D3DXMATRIX m;
D3DXVECTOR4 vec;
m.m[0][0] = p1->x - p0->x;
m.m[1][0] = p2->x - p0->x;
m.m[2][0] = -praydir->x;
m.m[3][0] = 0.0f;
m.m[0][1] = p1->y - p0->z;
m.m[1][1] = p2->y - p0->z;
m.m[2][1] = -praydir->y;
m.m[3][1] = 0.0f;
m.m[0][2] = p1->z - p0->z;
m.m[1][2] = p2->z - p0->z;
m.m[2][2] = -praydir->z;
m.m[3][2] = 0.0f;
m.m[0][3] = 0.0f;
m.m[1][3] = 0.0f;
m.m[2][3] = 0.0f;
m.m[3][3] = 1.0f;
vec.x = praypos->x - p0->x;
vec.y = praypos->y - p0->y;
vec.z = praypos->z - p0->z;
vec.w = 0.0f;
if ( D3DXMatrixInverse(&m, NULL, &m) )
{
D3DXVec4Transform(&vec, &vec, &m);
if ( (vec.x >= 0.0f) && (vec.y >= 0.0f) && (vec.x + vec.y <= 1.0f) && (vec.z >= 0.0f) )
{
*pu = vec.x;
*pv = vec.y;
*pdist = fabs( vec.z );
return TRUE;
}
}
return FALSE;
}
BOOL WINAPI D3DXSphereBoundProbe(CONST D3DXVECTOR3 *pcenter, FLOAT radius, CONST D3DXVECTOR3 *prayposition, CONST D3DXVECTOR3 *praydirection)
{
D3DXVECTOR3 difference;
......
......@@ -20,6 +20,13 @@
#include "wine/test.h"
#define admitted_error 0.0001f
BOOL compare(FLOAT u, FLOAT v)
{
return (fabs(u-v) < admitted_error);
}
static void D3DXBoundProbeTest(void)
{
BOOL result;
......@@ -94,7 +101,61 @@ static void D3DXBoundProbeTest(void)
ok(result == FALSE, "expected FALSE, received TRUE\n");
}
static void D3DXIntersectTriTest(void)
{
BOOL exp_res, got_res;
D3DXVECTOR3 position, ray, vertex[3];
FLOAT exp_dist, got_dist, exp_u, got_u, exp_v, got_v;
vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
position.x = -14.5f; position.y = -23.75f; position.z = -32.0f;
ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
exp_res = TRUE; exp_u = 0.5f; exp_v = 0.25f; exp_dist = 8.0f;
got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
ok( compare(exp_u,got_u), "Expected u = %f, got %f\n",exp_u,got_u);
ok( compare(exp_v,got_v), "Expected v = %f, got %f\n",exp_v,got_v);
ok( compare(exp_dist,got_dist), "Expected distance = %f, got %f\n",exp_dist,got_dist);
/*Only positive ray is taken in account*/
vertex[0].x = 1.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
vertex[1].x = 2.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
vertex[2].x = 1.0f; vertex[2].y = 1.0f; vertex[2].z = 0.0f;
position.x = 17.5f; position.y = 24.25f; position.z = 32.0f;
ray.x = 2.0f; ray.y = 3.0f; ray.z = 4.0f;
exp_res = FALSE;
got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
/*Intersection between ray and triangle in a same plane is considered as empty*/
vertex[0].x = 4.0f; vertex[0].y = 0.0f; vertex[0].z = 0.0f;
vertex[1].x = 6.0f; vertex[1].y = 0.0f; vertex[1].z = 0.0f;
vertex[2].x = 4.0f; vertex[2].y = 2.0f; vertex[2].z = 0.0f;
position.x = 1.0f; position.y = 1.0f; position.z = 0.0f;
ray.x = 1.0f; ray.y = 0.0f; ray.z = 0.0f;
exp_res = FALSE;
got_res = D3DXIntersectTri(&vertex[0],&vertex[1],&vertex[2],&position,&ray,&got_u,&got_v,&got_dist);
ok( got_res == exp_res, "Expected result = %d, got %d\n",exp_res,got_res);
}
START_TEST(mesh)
{
D3DXBoundProbeTest();
D3DXIntersectTriTest();
}
......@@ -167,7 +167,7 @@
@ stdcall D3DXGetVertexShaderProfile(ptr)
@ stdcall D3DXIntersect(ptr ptr ptr ptr ptr ptr ptr ptr ptr ptr) d3dx8.D3DXIntersect
@ stdcall D3DXIntersectSubset(ptr long ptr ptr ptr ptr ptr ptr ptr ptr ptr) d3dx8.D3DXIntersectSubset
@ stdcall D3DXIntersectTri(ptr ptr ptr ptr ptr ptr ptr ptr) d3dx8.D3DXIntersectTri
@ stub D3DXIntersectTri
@ stub D3DXLoadMeshFromXA
@ stub D3DXLoadMeshFromXInMemory
@ stub D3DXLoadMeshFromXResource
......
......@@ -30,6 +30,7 @@ HRESULT WINAPI D3DXCreateBuffer(DWORD,LPD3DXBUFFER*);
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 *);
#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