コード例 #1
0
ファイル: Colliders.cpp プロジェクト: Demiguise/PDAsteroids
	bool TestForOverlap(	const BoxCollider* a,
							const BoxCollider* b,
							const EnVector3& axis)
	{
		float aProjection = ProjectToAxis(a, axis);
		float bProjection = ProjectToAxis(b, axis);
		EnVector3 abVector = b->parent->GetLocalAxis(3) - a->parent->GetLocalAxis(3);
		float abVectorProjection = abs(abVector.ADot(axis));
		return abVectorProjection <= (aProjection + bProjection);
	}
コード例 #2
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;
}