예제 #1
0
파일: Triangle.cpp 프로젝트: katik/naali
/// [groupSyntax]
bool Triangle::Intersects(const AABB &aabb) const
{
    /** The AABB-Triangle test implementation is based on the pseudo-code in
    	Christer Ericson's Real-Time Collision Detection, pp. 169-172. */
    ///@todo The Triangle-AABB intersection test can be greatly optimized by manually unrolling loops, trivial math and by avoiding
    /// unnecessary copying.
    float t1, t2, a1, a2;
    const float3 e[3] = { float3(1,0,0), float3(0,1,0), float3(0,0,1) };

    for(int i = 0; i < 3; ++i)
    {
        ProjectToAxis(e[i], t1, t2);
        aabb.ProjectToAxis(e[i], a1, a2);
        if (!RangesOverlap(t1, t2, a1, a2))
            return false;
    }

    float3 n = UnnormalizedNormalCCW();
    ProjectToAxis(n, t1, t2);
    aabb.ProjectToAxis(n, a1, a2);
    if (!RangesOverlap(t1, t2, a1, a2))
        return false;

    const float3 t[3] = { b-a, c-a, c-b };

    for(int i = 0; i < 3; ++i)
        for(int j = 0; j < 3; ++j)
        {
            float3 axis = Cross(e[i], t[j]);
            float len = axis.LengthSq();
            if (len <= 1e-4f)
                continue; // Ignore tests on degenerate axes.

            ProjectToAxis(axis, t1, t2);
            aabb.ProjectToAxis(axis, a1, a2);
            if (!RangesOverlap(t1, t2, a1, a2))
                return false;
        }

    // No separating axis exists, the AABB and triangle intersect.
    return true;
}
예제 #2
0
/*******************************************************************************
Name        : IsInCache
Description : Check if memory area is in cache
Parameters  : first and last address of the memory area to check
Assumptions :
Limitations :
Returns     : TRUE if is in cache, FALSE otherwise
*******************************************************************************/
static BOOL IsInCache(void * const FirstAddr_p, void * const LastAddr_p)
{
    U32 AreaIndex;

    for (AreaIndex = 0; AreaIndex < stavmem_MemAccessDevice.NumberOfDCachedAreas; AreaIndex++)
    {
        if (RangesOverlap(FirstAddr_p, LastAddr_p, stavmem_MemAccessDevice.DCachedRanges_p[AreaIndex].StartAddr_p,
                                                   stavmem_MemAccessDevice.DCachedRanges_p[AreaIndex].StopAddr_p))
        {
            return(TRUE);
        }
    }

    return(FALSE);
} /* end of IsInCache() */