示例#1
0
        public override bool Test(AxisAlignedBoundingBox other)
        {
            var c1 = Collision.BoxContainsPoint(ref other.sbb, ref P1);
            if (c1 == ContainmentType.Disjoint)
            {
                var c2 = Collision.BoxContainsPoint(ref other.sbb, ref P2);
                if (c2 == ContainmentType.Disjoint)
                {
                    var c3 = Collision.BoxContainsPoint(ref other.sbb, ref P3);
                    if (c3 == ContainmentType.Disjoint)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
示例#2
0
文件: Ray.cs 项目: ukitake/Stratum
 public override bool Test(AxisAlignedBoundingBox other)
 {
     return sray.Intersects(ref other.sbb);
 }
示例#3
0
 public override bool Test(AxisAlignedBoundingBox other)
 {
     throw new NotImplementedException();
 }
示例#4
0
        // tests the aabb with triangle [v0,v1,v2] for intersection
        public static bool Test(AxisAlignedBoundingBox b, Vector3 v0, Vector3 v1, Vector3 v2)
        {
            float p0, p1, p2, r;

            // Compute box center and extents (if not already given in that format)
            Vector3 c = (b.Min + b.Max) * 0.5f;
            float e0 = (b.Max.X - b.Min.X) * 0.5f;
            float e1 = (b.Max.Y - b.Min.Y) * 0.5f;
            float e2 = (b.Max.Z - b.Min.Z) * 0.5f;

            // Translate triangle as conceptually moving AABB to origin
            v0 = v0 - c;
            v1 = v1 - c;
            v2 = v2 - c;

            // Compute edge vectors for triangle
            Vector3 f0 = v1 - v0, f1 = v2 - v1, f2 = v0 - v2;

            // Test axes a00..a22 (category 3)
            // Test axis a00
            p0 = v0.Z * v1.Y - v0.Y * v1.Z;
            p2 = v2.Z * (v1.Y - v0.Y) - v2.Y * (v1.Z - v0.Z);
            r = e1 * Math.Abs(f0.Z) + e2 * Math.Abs(f0.Y);
            if (Math.Max(-Math.Max(p0, p2), Math.Min(p0, p2)) > r) return false; // Axis is a separating axis

            // axis a01
            p0 = -v0.Y * f1.Z + v0.Z * f1.Y;
            p1 = -v1.Y * f1.Z + v1.Z * f1.Y;
            p2 = -v2.Y * f1.Z + v2.Z * f1.Y;
            r = e1 * Math.Abs(f1.Z) + e2 * Math.Abs(f1.Y);
            if (Math.Max(Math.Max(Math.Max(p0, p1), p2), Math.Min(Math.Min(p0, p1), p2)) > r) return false;

            // axis a02
            p0 = -v0.Y * f2.Z + v0.Z * f2.Y;
            p1 = -v1.Y * f2.Z + v1.Z * f2.Y;
            p2 = -v2.Y * f2.Z + v2.Z * f2.Y;
            r = e1 * Math.Abs(f2.Z) + e2 * Math.Abs(f2.Y);
            if (Math.Max(Math.Max(Math.Max(p0, p1), p2), Math.Min(Math.Min(p0, p1), p2)) > r) return false;

            // axis a10
            p0 = v0.X * f0.Z - v0.Z * f0.X;
            p1 = v1.X * f0.Z - v1.Z * f0.X;
            p2 = v2.X * f0.Z - v2.Z * f0.X;
            r = e0 * Math.Abs(f0.Z) + e2 * Math.Abs(f0.X);
            if (Math.Max(Math.Max(Math.Max(p0, p1), p2), Math.Min(Math.Min(p0, p1), p2)) > r) return false;

            // axis a11
            p0 = v0.X * f1.Z - v0.Z * f1.X;
            p1 = v1.X * f1.Z - v1.Z * f1.X;
            p2 = v2.X * f1.Z - v2.Z * f1.X;
            r = e0 * Math.Abs(f1.Z) + e2 * Math.Abs(f1.X);
            if (Math.Max(Math.Max(Math.Max(p0, p1), p2), Math.Min(Math.Min(p0, p1), p2)) > r) return false;

            // axis a12
            p0 = v0.X * f2.Z - v0.Z * f2.X;
            p1 = v1.X * f2.Z - v1.Z * f2.X;
            p2 = v2.X * f2.Z - v2.Z * f2.X;
            r = e0 * Math.Abs(f2.Z) + e2 * Math.Abs(f2.X);
            if (Math.Max(Math.Max(Math.Max(p0, p1), p2), Math.Min(Math.Min(p0, p1), p2)) > r) return false;

            // axis20
            p0 = -v0.X * f0.Y + v0.Y * f0.X;
            p1 = -v1.X * f0.Y + v1.Y * f0.X;
            p2 = -v2.X * f0.Y + v2.Y * f0.X;
            r = e0 * Math.Abs(f0.Y) + e1 * Math.Abs(f0.X);
            if (Math.Max(Math.Max(Math.Max(p0, p1), p2), Math.Min(Math.Min(p0, p1), p2)) > r) return false;

            // axis21
            p0 = -v0.X * f1.Y + v0.Y * f1.X;
            p1 = -v1.X * f1.Y + v1.Y * f1.X;
            p2 = -v2.X * f1.Y + v2.Y * f1.X;
            r = e0 * Math.Abs(f1.Y) + e1 * Math.Abs(f1.X);
            if (Math.Max(Math.Max(Math.Max(p0, p1), p2), Math.Min(Math.Min(p0, p1), p2)) > r) return false;

            // axis22
            p0 = -v0.X * f2.Y + v0.Y * f2.X;
            p1 = -v1.X * f2.Y + v1.Y * f2.X;
            p2 = -v2.X * f2.Y + v2.Y * f2.X;
            r = e0 * Math.Abs(f2.Y) + e1 * Math.Abs(f2.X);
            if (Math.Max(Math.Max(Math.Max(p0, p1), p2), Math.Min(Math.Min(p0, p1), p2)) > r) return false;

            // Test the three axes corresponding to the face normals of AABB b (category 1).
            // Exit if...
            // ... [-e0, e0] and [min(v0.x,v1.x,v2.x), max(v0.x,v1.x,v2.x)] do not overlap
            if (Math.Max(Math.Max(v0.X, v1.X), v2.X) < -e0 || Math.Min(Math.Min(v0.X, v1.X), v2.X) > e0) return false;
            // ... [-e1, e1] and [min(v0.y,v1.y,v2.y), max(v0.y,v1.y,v2.y)] do not overlap
            if (Math.Max(Math.Max(v0.Y, v1.Y), v2.Y) < -e1 || Math.Min(Math.Min(v0.Y, v1.Y), v2.Y) > e1) return false;
            // ... [-e2, e2] and [min(v0.z,v1.z,v2.z), max(v0.z,v1.z,v2.z)] do not overlap
            if (Math.Max(Math.Max(v0.Z, v1.Z), v2.Z) < -e2 || Math.Min(Math.Min(v0.Z, v1.Z), v2.Z) > e2) return false;

            // Test separating axis corresponding to triangle face normal (category 2)
            SharpDX.Plane p = new SharpDX.Plane();
            p.Normal = Vector3.Cross(f0, f1);
            p.D = Vector3.Dot(p.Normal, v0);

            return b.Test(p);
        }
示例#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 override bool Test(AxisAlignedBoundingBox other)
 {
     return IntersectionTests.Test(this, other);
 }
示例#7
0
 public abstract bool Test(AxisAlignedBoundingBox other);
示例#8
0
 public override BoundingVolume Merge(AxisAlignedBoundingBox other)
 {
     throw new NotImplementedException();
 }
示例#9
0
 public ContainmentType Contains(AxisAlignedBoundingBox other)
 {
     return sbf.Contains(ref other.sbb);
 }
示例#10
0
 public abstract BoundingVolume Merge(AxisAlignedBoundingBox other);
示例#11
0
 public override BoundingVolume Merge(AxisAlignedBoundingBox other)
 {
     var otherS = SharpDX.BoundingSphere.FromBox(other.sbb);
     return new BoundingSphere(SharpDX.BoundingSphere.Merge(this.sSphere, otherS));
 }
示例#12
0
 public override BoundingVolume Merge(AxisAlignedBoundingBox other)
 {
     return AxisAlignedBoundingBox.Merge(this, other);
 }
示例#13
0
 public static AxisAlignedBoundingBox Merge(AxisAlignedBoundingBox first, AxisAlignedBoundingBox second)
 {
     return new AxisAlignedBoundingBox(BoundingBox.Merge(first.sbb, second.sbb));
 }
示例#14
0
文件: Plane.cs 项目: ukitake/Stratum
 public override bool Test(AxisAlignedBoundingBox other)
 {
     return splane.Intersects(ref other.sbb) == PlaneIntersectionType.Intersecting;
 }