예제 #1
0
	//---------------------------------------------------------------------
	bool LooseOctreeZone::isInside(const Util::AABBPtr & aabb)
	{
		XMVECTOR size = XMVectorReplicate((LOOSE_K * WORLD_SIZE / (2 << mDepth)));

		XMVECTOR minPoint = mAABB->getCenterPoint() - size;
		XMVECTOR maxPoint = mAABB->getCenterPoint() + size;

		return XMVector3LessOrEqual(minPoint, aabb->getMinPoint()) && 
			XMVector3LessOrEqual(aabb->getMaxPoint(), maxPoint);
	}
예제 #2
0
	//---------------------------------------------------------------------
	bool LooseOctreeZone::isFitInChildZone(const Util::AABBPtr & aabb)
	{
		XMVECTOR halfSideSize = XMVectorReplicate((LOOSE_K * WORLD_SIZE / (2 << mDepth)) * 0.5f);

		XMVECTOR nodeSize = aabb->getSize();

		/// "&& true" to kill the warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning).
		return XMVector3LessOrEqual(nodeSize, halfSideSize) && true;
	}
예제 #3
0
파일: Utility.cpp 프로젝트: simplerr/Devbox
//-----------------------------------------------------------------------------
// Compute the intersection of a ray (Origin, Direction) with a triangle 
// (V0, V1, V2).  Return TRUE if there is an intersection and also set *pDist 
// to the distance along the ray to the intersection.
// 
// The algorithm is based on Moller, Tomas and Trumbore, "Fast, Minimum Storage 
// Ray-Triangle Intersection", Journal of Graphics Tools, vol. 2, no. 1, 
// pp 21-28, 1997.
//-----------------------------------------------------------------------------
BOOL GLibIntersectRayTriangle( FXMVECTOR Origin, FXMVECTOR Direction, FXMVECTOR V0, CXMVECTOR V1, CXMVECTOR V2,
							  FLOAT* pDist )
{
	XMASSERT( pDist );
	//XMASSERT( XMVector3IsUnit( Direction ) );

	static const XMVECTOR Epsilon =
	{
		1e-20f, 1e-20f, 1e-20f, 1e-20f
	};

	XMVECTOR Zero = XMVectorZero();

	XMVECTOR e1 = V1 - V0;
	XMVECTOR e2 = V2 - V0;

	// p = Direction ^ e2;
	XMVECTOR p = XMVector3Cross( Direction, e2 );

	// det = e1 * p;
	XMVECTOR det = XMVector3Dot( e1, p );

	XMVECTOR u, v, t;

	if( XMVector3GreaterOrEqual( det, Epsilon ) )
	{
		// Determinate is positive (front side of the triangle).
		XMVECTOR s = Origin - V0;

		// u = s * p;
		u = XMVector3Dot( s, p );

		XMVECTOR NoIntersection = XMVectorLess( u, Zero );
		NoIntersection = XMVectorOrInt( NoIntersection, XMVectorGreater( u, det ) );

		// q = s ^ e1;
		XMVECTOR q = XMVector3Cross( s, e1 );

		// v = Direction * q;
		v = XMVector3Dot( Direction, q );

		NoIntersection = XMVectorOrInt( NoIntersection, XMVectorLess( v, Zero ) );
		NoIntersection = XMVectorOrInt( NoIntersection, XMVectorGreater( u + v, det ) );

		// t = e2 * q;
		t = XMVector3Dot( e2, q );

		NoIntersection = XMVectorOrInt( NoIntersection, XMVectorLess( t, Zero ) );

		if( XMVector4EqualInt( NoIntersection, XMVectorTrueInt() ) )
			return FALSE;
	}
	else if( XMVector3LessOrEqual( det, -Epsilon ) )
	{
		// Determinate is negative (back side of the triangle).
		XMVECTOR s = Origin - V0;

		// u = s * p;
		u = XMVector3Dot( s, p );

		XMVECTOR NoIntersection = XMVectorGreater( u, Zero );
		NoIntersection = XMVectorOrInt( NoIntersection, XMVectorLess( u, det ) );

		// q = s ^ e1;
		XMVECTOR q = XMVector3Cross( s, e1 );

		// v = Direction * q;
		v = XMVector3Dot( Direction, q );

		NoIntersection = XMVectorOrInt( NoIntersection, XMVectorGreater( v, Zero ) );
		NoIntersection = XMVectorOrInt( NoIntersection, XMVectorLess( u + v, det ) );

		// t = e2 * q;
		t = XMVector3Dot( e2, q );

		NoIntersection = XMVectorOrInt( NoIntersection, XMVectorGreater( t, Zero ) );

		if ( XMVector4EqualInt( NoIntersection, XMVectorTrueInt() ) )
			return FALSE;
	}
	else
	{
		// Parallel ray.
		return FALSE;
	}

	XMVECTOR inv_det = XMVectorReciprocal( det );

	t *= inv_det;

	// u * inv_det and v * inv_det are the barycentric cooridinates of the intersection.

	// Store the x-component to *pDist
	XMStoreFloat( pDist, t );

	return TRUE;
}