예제 #1
0
/////////////////////////////////////
// Name:	OBJIsIntersectRay
// Purpose:	checks to see if the given
//			object is intersecting a ray
// Output:	pFaceIndex, pU, pV, pDist
// Return:	true if intersect
/////////////////////////////////////
PUBLIC bool OBJIsIntersectRay(hOBJ obj, D3DXVECTOR3 *pRayPos, D3DXVECTOR3 *pRayDir)
{
	//push world stack and set this object's world mtx
	g_pWrldStack->Push();
	g_pWrldStack->MultMatrix(&obj->wrldMtx.mtxTrans);

	//check the base model
	D3DXVECTOR3 ctr=obj->theMdl->bound.center;

	//D3DXMATRIX mtxView;
    //g_p3DDevice->GetTransform( D3DTS_VIEW, &mtxView );
	//D3DXVec3TransformCoord(&ctr, &ctr,  &mtxView);

	D3DXVec3TransformCoord(&ctr, &ctr, g_pWrldStack->GetTop());

	if(D3DXSphereBoundProbe(&ctr, obj->theMdl->bound.radius, pRayPos, pRayDir))
	{ g_pWrldStack->Pop(); return true; }

	//check for children
	hOBJ thisObj;
	for(LISTPTR::iterator i = obj->objNode->begin(); i != obj->objNode->end(); ++i)
	{
		thisObj = (hOBJ)(*i);
		
		if(OBJIsIntersectRay(thisObj, pRayPos, pRayDir))
			return true;
	}

	//take this junk out!
	g_pWrldStack->Pop();

	return false;
}
예제 #2
0
BOOL BoundElipsoidIntersect ( D3DXVECTOR3 mid, D3DXVECTOR3 e, D3DXVECTOR3 o_pos, D3DXVECTOR3 n_pos )
{
	mid.x /= e.x;
	mid.y /= e.y;
	mid.z /= e.z;

	o_pos.x /= e.x;
	o_pos.y /= e.y;
	o_pos.z /= e.z;

	n_pos.x /= e.x;
	n_pos.y /= e.y;
	n_pos.z /= e.z;

	if ( D3DXSphereBoundProbe ( &mid, 1, &o_pos, &( n_pos - o_pos ) ) &&
		D3DXSphereBoundProbe ( &mid, 1, &n_pos, &( o_pos - n_pos ) ) )
			return TRUE;

	return FALSE;
}
예제 #3
0
파일: mouse.cpp 프로젝트: Alriightyman/RTS
float RAY::Intersect(BSPHERE bSphere)
{
	if(D3DXSphereBoundProbe(&bSphere.center, bSphere.radius, &org, &dir))
		return D3DXVec3Length(&(bSphere.center - org));
	else return -1.0f;
}
예제 #4
0
파일: mesh.c 프로젝트: bilboed/wine
static void D3DXBoundProbeTest(void)
{
    BOOL result;
    D3DXVECTOR3 bottom_point, center, top_point, raydirection, rayposition;
    FLOAT radius;

/*____________Test the Box case___________________________*/
    bottom_point.x = -3.0f; bottom_point.y = -2.0f; bottom_point.z = -1.0f;
    top_point.x = 7.0f; top_point.y = 8.0f; top_point.z = 9.0f;

    raydirection.x = -4.0f; raydirection.y = -5.0f; raydirection.z = -6.0f;
    rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f;
    result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
    ok(result == TRUE, "expected TRUE, received FALSE\n");

    raydirection.x = 4.0f; raydirection.y = 5.0f; raydirection.z = 6.0f;
    rayposition.x = 5.0f; rayposition.y = 5.0f; rayposition.z = 11.0f;
    result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
    ok(result == FALSE, "expected FALSE, received TRUE\n");

    rayposition.x = -4.0f; rayposition.y = 1.0f; rayposition.z = -2.0f;
    result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
    ok(result == TRUE, "expected TRUE, received FALSE\n");

    bottom_point.x = 1.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f;
    top_point.x = 1.0f; top_point.y = 0.0f; top_point.z = 0.0f;
    rayposition.x = 0.0f; rayposition.y = 1.0f; rayposition.z = 0.0f;
    raydirection.x = 0.0f; raydirection.y = 3.0f; raydirection.z = 0.0f;
    result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
    ok(result == FALSE, "expected FALSE, received TRUE\n");

    bottom_point.x = 1.0f; bottom_point.y = 2.0f; bottom_point.z = 3.0f;
    top_point.x = 10.0f; top_point.y = 15.0f; top_point.z = 20.0f;

    raydirection.x = 7.0f; raydirection.y = 8.0f; raydirection.z = 9.0f;
    rayposition.x = 3.0f; rayposition.y = 7.0f; rayposition.z = -6.0f;
    result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
    ok(result == TRUE, "expected TRUE, received FALSE\n");

    bottom_point.x = 0.0f; bottom_point.y = 0.0f; bottom_point.z = 0.0f;
    top_point.x = 1.0f; top_point.y = 1.0f; top_point.z = 1.0f;

    raydirection.x = 0.0f; raydirection.y = 1.0f; raydirection.z = .0f;
    rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f;
    result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
    ok(result == FALSE, "expected FALSE, received TRUE\n");

    raydirection.x = 1.0f; raydirection.y = 0.0f; raydirection.z = .0f;
    rayposition.x = -3.0f; rayposition.y = 0.0f; rayposition.z = 0.0f;
    result = D3DXBoxBoundProbe(&bottom_point, &top_point, &rayposition, &raydirection);
    ok(result == TRUE, "expected TRUE, received FALSE\n");

/*____________Test the Sphere case________________________*/
    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");

    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");

    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");
}