示例#1
0
        public bool Contains(ref Vector3D point)
        {
            // Transform the point into box-local space and check against
            // our extents.
            Quaternion qinv   = Quaternion.Conjugate(Orientation);
            Vector3D   plocal = Vector3D.Transform(point - Center, qinv);

            return(Math.Abs(plocal.X) <= HalfExtent.X &&
                   Math.Abs(plocal.Y) <= HalfExtent.Y &&
                   Math.Abs(plocal.Z) <= HalfExtent.Z);
        }
        public ContainmentType Contains(ref MyOrientedBoundingBoxD other)
        {
            Quaternion quaternion;
            Quaternion quaternion2;

            Quaternion.Conjugate(ref this.Orientation, out quaternion);
            Quaternion.Multiply(ref quaternion, ref other.Orientation, out quaternion2);
            MatrixD mB = MatrixD.CreateFromQuaternion(quaternion2);

            mB.Translation = Vector3D.Transform(other.Center - this.Center, quaternion);
            return(ContainsRelativeBox(ref this.HalfExtent, ref other.HalfExtent, ref mB));
        }
        public ContainmentType Contains(ref BoundingBoxD box)
        {
            Quaternion quaternion;
            Vector3D   vectord = (Vector3D)((box.Max + box.Min) * 0.5);
            Vector3D   hB      = (Vector3D)((box.Max - box.Min) * 0.5);

            Quaternion.Conjugate(ref this.Orientation, out quaternion);
            MatrixD matrix = MatrixD.CreateFromQuaternion(quaternion);

            matrix.Translation = Vector3D.TransformNormal(vectord - this.Center, matrix);
            return(ContainsRelativeBox(ref this.HalfExtent, ref hB, ref matrix));
        }
        public bool Intersects(ref BoundingSphereD sphere)
        {
            Quaternion rotation = Quaternion.Conjugate(this.Orientation);
            Vector3    vector   = Vector3.Transform((Vector3)(sphere.Center - this.Center), rotation);
            double     num      = Math.Abs(vector.X) - this.HalfExtent.X;
            double     num2     = Math.Abs(vector.Y) - this.HalfExtent.Y;
            double     num3     = Math.Abs(vector.Z) - this.HalfExtent.Z;

            num  = Math.Max(num, 0.0);
            num2 = Math.Max(num2, 0.0);
            num3 = Math.Max(num3, 0.0);
            double radius = sphere.Radius;

            return((((num * num) + (num2 * num2)) + (num3 * num3)) < (radius * radius));
        }
示例#5
0
        // Determine whether this box contains, intersects, or is disjoint from
        // the given other box.
        public ContainmentType Contains(ref MyOrientedBoundingBoxD other)
        {
            // Build the 3x3 rotation matrix that defines the orientation of 'other' relative to this box
            Quaternion invOrient;

            Quaternion.Conjugate(ref Orientation, out invOrient);
            Quaternion relOrient;

            Quaternion.Multiply(ref invOrient, ref other.Orientation, out relOrient);

            MatrixD relTransform = MatrixD.CreateFromQuaternion(relOrient);

            relTransform.Translation = Vector3D.Transform(other.Center - Center, invOrient);

            return(ContainsRelativeBox(ref HalfExtent, ref other.HalfExtent, ref relTransform));
        }
示例#6
0
        // Determine if this box contains, intersects, or is disjoint from the given BoundingBox.
        public ContainmentType Contains(ref BoundingBox box)
        {
            Vector3D boxCenter     = (box.Max + box.Min) * 0.5f;
            Vector3D boxHalfExtent = (box.Max - box.Min) * 0.5f;

            // Build the 3x3 rotation matrix that defines the orientation of 'other' relative to this box
            Quaternion relOrient;

            Quaternion.Conjugate(ref Orientation, out relOrient);

            MatrixD relTransform = MatrixD.CreateFromQuaternion(relOrient);

            relTransform.Translation = Vector3D.TransformNormal(boxCenter - Center, relTransform);

            return(ContainsRelativeBox(ref HalfExtent, ref boxHalfExtent, ref relTransform));
        }
        public PlaneIntersectionType Intersects(ref PlaneD plane)
        {
            double   num         = plane.DotCoordinate(this.Center);
            Vector3D vectord     = Vector3D.Transform(plane.Normal, Quaternion.Conjugate(this.Orientation));
            double   introduced3 = Math.Abs((double)(this.HalfExtent.X * vectord.X));
            double   num2        = (introduced3 + Math.Abs((double)(this.HalfExtent.Y * vectord.Y))) + Math.Abs((double)(this.HalfExtent.Z * vectord.Z));

            if (num > num2)
            {
                return(PlaneIntersectionType.Front);
            }
            if (num < -num2)
            {
                return(PlaneIntersectionType.Back);
            }
            return(PlaneIntersectionType.Intersecting);
        }
示例#8
0
        // Convert this BoundingOrientedBox to a BoundingFrustum describing the same volume.
        //
        // A BoundingFrustum is defined by the matrix that carries its volume to the
        // box from (-1,-1,0) to (1,1,1), so we just need a matrix that carries our box there.
        public BoundingFrustumD ConvertToFrustum()
        {
            Quaternion invOrientation;

            Quaternion.Conjugate(ref Orientation, out invOrientation);
            double  sx = 1.0 / HalfExtent.X;
            double  sy = 1.0 / HalfExtent.Y;
            double  sz = 0.5 / HalfExtent.Z;
            MatrixD temp;

            MatrixD.CreateFromQuaternion(ref invOrientation, out temp);
            temp.M11        *= sx; temp.M21 *= sx; temp.M31 *= sx;
            temp.M12        *= sy; temp.M22 *= sy; temp.M32 *= sy;
            temp.M13        *= sz; temp.M23 *= sz; temp.M33 *= sz;
            temp.Translation = Vector3.UnitZ * 0.5f + Vector3D.TransformNormal(-Center, temp);

            return(new BoundingFrustumD(temp));
        }
示例#9
0
        // Test whether this box intersects the given sphere
        public bool Intersects(ref BoundingSphereD sphere)
        {
            // Transform the sphere into local box space
            Quaternion iq          = Quaternion.Conjugate(Orientation);
            Vector3    localCenter = Vector3.Transform(sphere.Center - Center, iq);

            // (dx,dy,dz) = signed distance of center of sphere from edge of box
            double dx = Math.Abs(localCenter.X) - HalfExtent.X;
            double dy = Math.Abs(localCenter.Y) - HalfExtent.Y;
            double dz = Math.Abs(localCenter.Z) - HalfExtent.Z;

            // Compute how far away the sphere is in each dimension
            dx = Math.Max(dx, 0.0f);
            dy = Math.Max(dy, 0.0f);
            dz = Math.Max(dz, 0.0f);
            double r = sphere.Radius;

            return(dx * dx + dy * dy + dz * dz < r * r);
        }
        public ContainmentType Contains(ref BoundingSphereD sphere)
        {
            Quaternion rotation = Quaternion.Conjugate(this.Orientation);
            Vector3    vector   = Vector3.Transform((Vector3)(sphere.Center - this.Center), rotation);
            double     num      = Math.Abs(vector.X) - this.HalfExtent.X;
            double     num2     = Math.Abs(vector.Y) - this.HalfExtent.Y;
            double     num3     = Math.Abs(vector.Z) - this.HalfExtent.Z;
            double     radius   = sphere.Radius;

            if (((num <= -radius) && (num2 <= -radius)) && (num3 <= -radius))
            {
                return(ContainmentType.Contains);
            }
            num  = Math.Max(num, 0.0);
            num2 = Math.Max(num2, 0.0);
            num3 = Math.Max(num3, 0.0);
            if ((((num * num) + (num2 * num2)) + (num3 * num3)) >= (radius * radius))
            {
                return(ContainmentType.Disjoint);
            }
            return(ContainmentType.Intersects);
        }
        public BoundingFrustumD ConvertToFrustum()
        {
            Quaternion quaternion;
            MatrixD    xd;

            Quaternion.Conjugate(ref this.Orientation, out quaternion);
            double num  = 1.0 / this.HalfExtent.X;
            double num2 = 1.0 / this.HalfExtent.Y;
            double num3 = 0.5 / this.HalfExtent.Z;

            MatrixD.CreateFromQuaternion(ref quaternion, out xd);
            xd.M11        *= num;
            xd.M21        *= num;
            xd.M31        *= num;
            xd.M12        *= num2;
            xd.M22        *= num2;
            xd.M32        *= num2;
            xd.M13        *= num3;
            xd.M23        *= num3;
            xd.M33        *= num3;
            xd.Translation = ((Vector3D)(Vector3.UnitZ * 0.5f)) + Vector3D.TransformNormal(-this.Center, xd);
            return(new BoundingFrustumD(xd));
        }
        public BoundingFrustum ConvertToFrustum()
        {
            Quaternion quaternion;
            Matrix     matrix;

            Quaternion.Conjugate(ref this.Orientation, out quaternion);
            float num  = 1f / this.HalfExtent.X;
            float num2 = 1f / this.HalfExtent.Y;
            float num3 = 0.5f / this.HalfExtent.Z;

            Matrix.CreateFromQuaternion(ref quaternion, out matrix);
            matrix.M11        *= num;
            matrix.M21        *= num;
            matrix.M31        *= num;
            matrix.M12        *= num2;
            matrix.M22        *= num2;
            matrix.M32        *= num2;
            matrix.M13        *= num3;
            matrix.M23        *= num3;
            matrix.M33        *= num3;
            matrix.Translation = ((Vector3)(Vector3.UnitZ * 0.5f)) + Vector3.TransformNormal(-this.Center, matrix);
            return(new BoundingFrustum(matrix));
        }