예제 #1
0
        public static bool Test(LineSegment seg, Vector3 a, Vector3 b, Vector3 c, out float u, out float v, out float w)
        {
            Vector3 ab = b - a;
            Vector3 ac = c - a;
            Vector3 qp = seg.Point1 - seg.Point2;

            // Compute triangle normal. Can be precalculated or cached if
            // intersecting multiple segments against the same triangle
            Vector3 n = Vector3.Cross(ab, ac);

            // Compute denominator d. If d <= 0, segment is parallel to or points
            // away from triangle, so exit early
            float d = Vector3.Dot(qp, n);
            if (d <= 0.0f)
            {
                u = 0; v = 0; w = 0;
                return false;
            }
            // Compute intersection t value of pq with plane of triangle. A ray
            // intersects iff 0 <= t. Segment intersects iff 0 <= t <= 1. Delay
            // dividing by d until intersection has been found to pierce triangle
            Vector3 ap = seg.Point1 - a;
            float t = Vector3.Dot(ap, n);
            if (t < 0.0f)
            {
                u = 0; v = 0; w = 0;
                return false;
            }
            if (t > d)
            {
                u = 0; v = 0; w = 0;
                return false; // For segment; exclude this code line for a ray test
            }
            // Compute barycentric coordinate components and test if within bounds
            Vector3 e = Vector3.Cross(qp, ap);
            v = Vector3.Dot(ac, e);
            if (v < 0.0f || v > d)
            {
                u = 0; w = 0;
                return false;
            }
            w = -Vector3.Dot(ab, e);
            if (w < 0.0f || v + w > d)
            {
                u = 0;
                return false;
            }
            // Segment/ray intersects triangle. Perform delayed division and
            // compute the last barycentric coordinate component
            float ood = 1.0f / d;
            t *= ood;
            v *= ood;
            w *= ood;
            u = 1.0f - v - w;
            return true;
        }
예제 #2
0
파일: Ray.cs 프로젝트: ukitake/Stratum
 public override bool Test(LineSegment other)
 {
     // TODO
     throw new NotImplementedException();
 }
예제 #3
0
 public static bool Test(LineSegment seg, BoundingSphere sphere)
 {
     ContainmentType ct1 = sphere.Contains(seg.Point1);
     ContainmentType ct2 = sphere.Contains(seg.Point2);
     return ct1 != ct2;
 }
예제 #4
0
        public static bool Test(LineSegment seg, Plane plane)
        {
            Vector3 q;
            float t;

            // Compute the t value for the directed line ab intersecting the plane
            Vector3 ab = seg.Point2 - seg.Point1;
            t = (plane.D - Vector3.Dot(plane.Normal, seg.Point1)) / Vector3.Dot(plane.Normal, ab);

            // If t in [0..1] compute and return intersection point
            if (t >= 0.0f && t <= 1.0f)
            {
                q = seg.Point1 + t * ab;
                return true;
            }
            // Else no intersection
            return false;
        }
예제 #5
0
        public static bool Test(LineSegment seg, AxisAlignedBoundingBox bb)
        {
            Vector3 c = (bb.Min + bb.Max) * 0.5f;     // box center point
            Vector3 e = bb.Max - c;                      // box halflength extents
            Vector3 m = (seg.Point1 + seg.Point2) * 0.5f;           // segment midpoint
            Vector3 d = seg.Point1 - m;                         // segment halflength vector
            m = m - c;                                      // translate box and segment to origin

            // try world coordinate axes as seperating axes
            float adx = Math.Abs(d.X);
            if (Math.Abs(m.X) > e.X + adx)
                return false;
            float ady = Math.Abs(d.Y);
            if (Math.Abs(m.Y) > e.Y + ady)
                return false;
            float adz = Math.Abs(d.Z);
            if (Math.Abs(m.Z) > e.Z + adz)
                return false;

            // add in an epsilon term to counteract arithmetic errors when segment is (near) parallel to a coordinate axis
            adx += FPPrecisionHelper.EPSILON; ady += FPPrecisionHelper.EPSILON; adz += FPPrecisionHelper.EPSILON;

            // try cross products of segment direction vector with coordinate axes
            if (Math.Abs(m.Y * d.Z - m.Z * d.Y) > e.Y * adz + e.Z * ady)
                return false;
            if (Math.Abs(m.Z * d.X - m.X * d.Z) > e.X * adz + e.Z * adx)
                return false;
            if (Math.Abs(m.X * d.Y - m.Y * d.X) > e.X * ady + e.Y * adx)
                return false;

            // no separating axis found; segment must be overlapping AABB
            return true;
        }
예제 #6
0
 public static bool Test(LineSegment seg, BoundingFrustum frus)
 {
     ContainmentType ct1 = frus.Contains(seg.Point1);
     ContainmentType ct2 = frus.Contains(seg.Point2);
     return ct1 != ct2;
 }
예제 #7
0
 public abstract bool Test(LineSegment other);
예제 #8
0
 public abstract bool Test(LineSegment other);
예제 #9
0
 public override bool Test(LineSegment other)
 {
     return IntersectionTests.Test(other, this);
 }
예제 #10
0
 public override bool Test(LineSegment other)
 {
     return(IntersectionTests.Test(other, this));
 }
예제 #11
0
 public override bool Test(LineSegment other)
 {
     // TODO
     throw new NotImplementedException();
 }