Example #1
0
/// [groupSyntax]
bool Triangle::Intersects(const LineSegment &l, float *d, float3 *intersectionPoint) const
{
	/** The Triangle-Line/LineSegment/Ray intersection tests are based on Möller-Trumbore method:
		"T. Möller, B. Trumbore. Fast, Minimum Storage Ray/Triangle Intersection. 2005."
		http://jgt.akpeters.com/papers/MollerTrumbore97/. */
	float u, v;
	float t = IntersectLineTri(l.a, l.Dir(), a, b, c, u, v);
	bool success = (t >= 0 && t != FLOAT_INF);
	if (!success)
		return false;
	float length = l.LengthSq();
	if (t < 0.f || t*t >= length)
		return false;
	length = Sqrt(length);
	if (d)
	{
		float len = t / length;
		*d = len;
		if (intersectionPoint)
			*intersectionPoint = l.GetPoint(len);
	}
	else if (intersectionPoint)
		*intersectionPoint = l.GetPoint(t / length);
	return true;
}
Example #2
0
bool Plane::Intersects(const LineSegment &lineSegment, float *d) const
{
    float t;
    bool success = IntersectLinePlane(PointOnPlane(), normal, lineSegment.a, lineSegment.Dir(), &t);
    const float lineSegmentLength = lineSegment.Length();
    if (d)
        *d = t / lineSegmentLength;
    return success && t >= 0.f && t <= lineSegmentLength;
}
Example #3
0
bool Plane::Intersects(const LineSegment &lineSegment, float *dist) const
{
	float t;
	bool success = IntersectLinePlane(normal, this->d, lineSegment.a, lineSegment.Dir(), t);
	const float lineSegmentLength = lineSegment.Length();
	if (dist)
		*dist = t / lineSegmentLength;
	return success && t >= 0.f && t <= lineSegmentLength;
}
Example #4
0
File: AABB.cpp Project: katik/naali
bool AABB::Intersects(const LineSegment &lineSegment, float *dNear, float *dFar) const
{
	float tNear, tFar;
	bool success = IntersectLineAABB(lineSegment.a, lineSegment.Dir(), *this, tNear, tFar);
	success = (tNear >= 0.f && tNear*tNear <= lineSegment.LengthSq());
	if (dNear)
		*dNear = tNear / lineSegment.Length();
	if (dFar)
		*dFar = tFar / lineSegment.Length();
	return success;
}
Example #5
0
int Sphere::Intersects(const LineSegment &l, vec *intersectionPoint, vec *intersectionNormal, float *d, float *d2) const
{
	float t1, t2;
	int numIntersections = IntersectLine(l.a, l.Dir(), pos, r, t1, t2);

	if (numIntersections == 0)
		return 0;

	float lineLength = l.Length();
	if (t2 < 0.f || t1 > lineLength)
		return 0;
	vec hitPoint = l.GetPoint(t1 / lineLength);
	if (intersectionPoint)
		*intersectionPoint = hitPoint;
	if (intersectionNormal)
		*intersectionNormal = (hitPoint - pos).Normalized();
	if (d)
		*d = t1 / lineLength;
	if (d2)
		*d2 = t2 / lineLength;

	return true;
}
Example #6
0
File: Ray.cpp Project: Ilikia/naali
Ray::Ray(const LineSegment &lineSegment)
:pos(lineSegment.a), dir(lineSegment.Dir())
{
}
Example #7
0
Line::Line(const LineSegment &lineSegment)
    :pos(lineSegment.a), dir(lineSegment.Dir())
{
}