bool BasicPrimitiveTests::IntersectingSegmentAgainstPlane(const LineSegment & segment, const Plane & plane, float & rtn_t)
{
	/*
		Main Idea:
            -> Subsitutes line equation into plane to find intersection
                -> Tests if intersection is within segment endpoints

        Let:
            -> Line Segment S:
                -> S(t) = A + t * (B-A)
                    -> for 0 <= t <= 1
            -> Plane P:
                -> dot(n, X) = d

        Solve for "t" of intersection:
            -> t = (    d - dot(n, A)    /    dot(n, B-A)    )

        -> Return intersection only if:
            -> 0 <= t <= 1
	*/
	
	rtn_t = (    plane.GetD() - plane.GetNormal().dot(segment.GetPointA())    )    /    plane.GetNormal().dot(segment.GetPointB() - segment.GetPointA());
	return (rtn_t <= 1.0f && rtn_t >= 0.0f);
	
}
Ejemplo n.º 2
0
	bool Ray::GetIntersection(const Plane &plane, float &t) const
	{
		real denom = glm::dot(plane.GetNormal(), mDirection);

		if(!denom) {
			return false;
		}

		real numer = -(glm::dot(plane.GetNormal(), mOrigin) + plane.GetD());

		t = numer / denom;

		if(t >= 0) {
			return true;
		}

		return false;
	}