Пример #1
0
        public bool isInButton(Location l)
        {
            if (this.sprite == null)
            {
                return(false);
            }
            if (this.sprite.getTexture() == null)
            {
                return(false);
            }
            if (this.sprite.getWidth() <= 0)
            {
                return(false);
            }
            if (this.sprite.getHeight() <= 0)
            {
                return(false);
            }

            l = l.getAbsoluteLocation();

            Location sl   = this.sprite.getLocation().getAbsoluteLocation();
            double   minX = sl.getX();
            double   minY = sl.getY();
            double   maxX = minX + this.sprite.getWidth();
            double   maxY = minY + this.sprite.getHeight();

            bool xVal = minX <= l.getX() && maxX >= l.getX();
            bool yVal = minY <= l.getY() && maxY >= l.getY();

            sl.Dispose();
            l.Dispose();
            return(xVal && yVal);
        }
Пример #2
0
        public static bool isHitting(BoundingBox box1, BoundingBox box2)
        {
            Location box1RefinedMin = box1.getRefinedMinPoint();
            Location box1RefinedMax = box1.getRefinedMaxPoint();
            Location box2RefinedMin = box2.getRefinedMinPoint();
            Location box2RefinedMax = box2.getRefinedMaxPoint();

            Location box1Min = box1RefinedMin.getAbsoluteLocation();
            Location box1Max = box1RefinedMax.getAbsoluteLocation();
            Location box2Min = box2RefinedMin.getAbsoluteLocation();
            Location box2Max = box2RefinedMax.getAbsoluteLocation();

            double myMinX = box1Min.getX();
            double myMinY = box1Min.getY();
            double myMinZ = box1Min.getZ();

            double myMaxX = box1Max.getX();
            double myMaxY = box1Max.getY();
            double myMaxZ = box1Max.getZ();

            double notMinX = box2Min.getX();
            double notMinY = box2Min.getY();
            double notMinZ = box2Min.getZ();

            double notMaxX = box2Max.getX();
            double notMaxY = box2Max.getY();
            double notMaxZ = box2Max.getZ();

            box1RefinedMin.Dispose();
            box1RefinedMax.Dispose();
            box2RefinedMin.Dispose();
            box2RefinedMax.Dispose();

            box1Min.Dispose();
            box1Max.Dispose();
            box2Min.Dispose();
            box2Max.Dispose();

            bool myXInside = (myMinX >= notMinX && myMinX <= notMaxX) || (myMaxX >= notMinX && myMaxX <= notMaxX);
            bool myYInside = (myMinY >= notMinY && myMinY <= notMaxY) || (myMaxY >= notMinY && myMaxY <= notMaxY);
            bool myZinside = (myMinZ >= notMinZ && myMinZ <= notMaxZ) || (myMaxZ >= notMinZ && myMaxZ <= notMaxZ);

            if (myXInside && myYInside && myZinside)
            {
                return(true);
            }

            bool notXInside = (notMinX >= myMinX && notMinX <= myMaxX) || (notMaxX >= myMinX && notMaxX <= myMaxX);
            bool notYInside = (notMinY >= myMinY && notMinY <= myMaxY) || (notMaxY >= myMinY && notMaxY <= myMaxY);
            bool notZInside = (notMinZ >= myMinZ && notMinZ <= myMaxZ) || (notMaxZ >= myMinZ && notMaxZ <= myMaxZ);

            if (notXInside && notYInside && notZInside)
            {
                return(true);
            }
            return(false);
        }
Пример #3
0
        public double getDistanceZ(Location between)
        {
            Location abs  = this.getAbsoluteLocation();
            Location bAbs = between.getAbsoluteLocation();
            double   dist = bAbs.z - abs.z;

            abs.Dispose();
            bAbs.Dispose();
            return(dist);
        }
Пример #4
0
        public double getDistance(Location between)
        {
            Location abs  = this.getAbsoluteLocation();
            Location bAbs = between.getAbsoluteLocation();
            double   dist = Math.Sqrt(
                Math.Pow(abs.x - bAbs.x, 2) +
                Math.Pow(abs.y - bAbs.y, 2) +
                Math.Pow(abs.z - bAbs.z, 2)
                );

            abs.Dispose();
            bAbs.Dispose();

            return(dist);
        }