Пример #1
0
 public AABBMask(PointFP p, FPInt width, FPInt height)
 {
     _type = MaskType.AABB;
     _point = p;
     _w = width;
     _h = height;
 }
Пример #2
0
 public LineMask(PointFP p0, PointFP p1)
 {
     _type = MaskType.Line;
     _p0 = p0;
     _w = p1.X - p0.X;
     _h = p1.Y - p0.Y;
 }
Пример #3
0
        private void Init(FPInt scalex, FPInt scaley)
        {
            _lookup = new Dictionary<int, Mask>();

            FPInt h = (FPInt)0.5f;

            // Row 1
            _lookup[1] = BuildRec(scalex, scaley, 0, 0, 1, 1);
            _lookup[2] = BuildTri(scalex, scaley, 0, 1, 1, 1, 1, 0);
            _lookup[3] = BuildTri(scalex, scaley, 0, 0, 0, 1, 1, 1);
            _lookup[4] = BuildTri(scalex, scaley, 0, 0, 1, 1, 1, 0);
            _lookup[5] = BuildTri(scalex, scaley, 0, 0, 0, 1, 1, 0);
            _lookup[6] = BuildRec(scalex, scaley, 0, 0, 1, h);
            _lookup[7] = BuildRec(scalex, scaley, 0, h, 1, 1);

            // Row2
            _lookup[8] = BuildRec(scalex, scaley, 0, 0, h, 1);
            _lookup[9] = BuildRec(scalex, scaley, h, 0, 1, 1);
            _lookup[10] = BuildTri(scalex, scaley, 0, 1, 1, 1, 1, h);
            _lookup[11] = BuildCom(
                BuildTri(scalex, scaley, 0, h, 1, h, 1, 0),
                BuildRec(scalex, scaley, 0, h, 1, 1));
            _lookup[12] = BuildCom(
                BuildTri(scalex, scaley, 0, 0, 0, h, 1, h),
                BuildRec(scalex, scaley, 0, h, 1, 1));
            _lookup[13] = BuildTri(scalex, scaley, 0, h, 0, 1, 1, 1);
            _lookup[14] = BuildTri(scalex, scaley, 0, h, 1, h, 1, 0);
            _lookup[15] = BuildTri(scalex, scaley, 0, 0, 0, h, 1, h);
        }
Пример #4
0
 public Position(FPInt x, FPInt y)
 {
     _x = x;
     _y = y;
     _prevX = x;
     _prevY = y;
 }
Пример #5
0
 public LineMask(PointFP p0, FPInt dw, FPInt dh)
 {
     _type = MaskType.Line;
     _p0 = p0;
     _w = dw;
     _h = dh;
 }
Пример #6
0
 public static FPInt Sqrt(FPInt f)
 {
     byte numberOfIterations = 8;
     if (f._raw > 100 * FPInt.OneL)
         numberOfIterations = 12;
     if (f._raw > 1000 * FPInt.OneL)
         numberOfIterations = 16;
     return Sqrt(f, numberOfIterations);
 }
        /*public TileCollisionManager TileCollisionManager
        {
            get { return _tileMan; }
            set { _tileMan = value; }
        }*/
        public bool Test(FPInt x, FPInt y)
        {
            foreach (TileCollisionManager manager in _managers) {
                if (manager.OverlapsAny(x, y))
                    return true;
            }

            return false;
        }
Пример #8
0
 public static FPInt Abs(FPInt v)
 {
     if (v._raw < 0) {
         return v.Inverse;
     }
     else {
         return v;
     }
 }
Пример #9
0
        public AABBMask(PointFP p0, PointFP p1)
        {
            _type = MaskType.AABB;

            FPInt minx = (p0.X < p1.X) ? p0.X : p1.X;
            FPInt miny = (p0.Y < p1.Y) ? p0.Y : p1.Y;

            _point = new PointFP(minx, miny);
            _w = FPMath.Abs(p1.X - p0.X);
            _h = FPMath.Abs(p1.Y - p0.Y);
        }
Пример #10
0
        public static bool TestOverlap(CircleMask cMask, FPInt x, FPInt y)
        {
            VectorFP p1 = (VectorFP)cMask._pos + cMask._p;

            FPInt dx = p1.X - x;
            FPInt dy = p1.Y - y;
            FPInt d2 = dx * dx + dy * dy;
            FPInt r2 = cMask._radius * cMask._radius;

            return (d2 < r2);
        }
Пример #11
0
        public static FPInt Sqrt(FPInt f, int numberOfIterations)
        {
            if (f._raw < 0) //NaN in Math.Sqrt
                throw new ArithmeticException("Input Error");
            if (f._raw == 0)
                return 0;
            FPInt k = f + FPInt.OneFP >> 1;
            for (int i = 0; i < numberOfIterations; i++)
                k = (k + (f / k)) >> 1;

            if (k._raw < 0)
                throw new ArithmeticException("Overflow");
            else
                return k;
        }
Пример #12
0
        public TriangleMask(PointFP p0, PointFP p1, PointFP p2)
        {
            _type = MaskType.Triangle;
            _p0 = p0;
            _p1 = p1;
            _p2 = p2;

            VectorFP a = (VectorFP)_pos + _p0;
            VectorFP b = (VectorFP)_pos + _p1;
            VectorFP c = (VectorFP)_pos + _p2;

            _det = (b.Y - c.Y) * (a.X - c.X) + (c.X - b.X) * (a.Y - c.Y);
            //_det = 1 / _det;

            FPInt minx = FPMath.Min(_p0.X, FPMath.Min(_p1.X, _p2.X));
            FPInt maxx = FPMath.Max(_p0.X, FPMath.Max(_p1.X, _p2.X));
            FPInt miny = FPMath.Min(_p0.Y, FPMath.Min(_p1.Y, _p2.Y));
            FPInt maxy = FPMath.Max(_p0.Y, FPMath.Max(_p1.Y, _p2.Y));

            _bound = new RectangleFP(minx, miny, maxx - minx, maxy - miny);
        }
Пример #13
0
 private Mask BuildRec(FPInt scalex, FPInt scaley, FPInt x1, FPInt y1, FPInt x2, FPInt y2)
 {
     return new AABBMask(new PointFP(scalex * x1, scaley * y1), new PointFP(scalex * x2, scaley * y2));
 }
Пример #14
0
 public override bool TestOverlapEdge(FPInt x, FPInt y)
 {
     return Collision.TestOverlapEdge(this, x, y);
 }
Пример #15
0
 public CircleMask(PointFP center, FPInt radius)
 {
     _type = MaskType.Circle;
     _p = center;
     _radius = radius;
 }
Пример #16
0
        public static bool TestOverlapEdge(TriangleMask triMask, FPInt x, FPInt y)
        {
            PointFP bary = triMask.Barycentric(new VectorFP(x, y));

            return (bary.X >= 0 && bary.Y >= 0 && (bary.X + bary.Y) <= 1);
        }
Пример #17
0
        public static bool TestOverlapEdge(AABBMask rMask, FPInt x, FPInt y)
        {
            VectorFP p1 = (VectorFP)rMask._pos + rMask._point;

            return (x >= p1.X && x <= p1.X + rMask._w && y >= p1.Y && y <= p1.Y + rMask._h);
        }
Пример #18
0
        public static bool TestOverlapEdge(LineMask lnMask, FPInt x, FPInt y)
        {
            PointFP cp = lnMask.ClosestPoint(new PointFP(x, y));

            return x == cp.X && y == cp.Y;
        }
Пример #19
0
 public static bool TestOverlapEdge(AYLine ylMask, FPInt x, FPInt y)
 {
     return (x == ylMask.X && y >= ylMask.Top && y <= ylMask.Bottom);
 }
Пример #20
0
        public static bool TestOverlapEdge(AYLineMask ylMask, FPInt x, FPInt y)
        {
            VectorFP p2 = (VectorFP)ylMask._pos + ylMask._p;

            return (x == p2.X && y >= p2.Y && y <= p2.Y + ylMask._h);
        }
Пример #21
0
 public virtual bool TestOverlapEdge(FPInt x, FPInt y)
 {
     return TestOverlap(x, y);
 }
Пример #22
0
 public Frog(FPInt x, FPInt y)
     : base()
 {
     _position.X = x;
     _position.Y = y;
     //AddBehavior(new CircleMovement(this, new Vector2(x, y), 50, MathHelper.Pi));
 }
Пример #23
0
        public AXLineMask(PointFP p, FPInt w)
        {
            _type = MaskType.AXLine;

            if (w > 0) {
                _p = p;
                _w = w;
            }
            else {
                _p = new PointFP(p.X - w, p.Y);
                _w = 0 - w;
            }
        }
Пример #24
0
 public AXLine(PointFP origin, FPInt length)
 {
     _y = origin.Y;
     _x1 = origin.X;
     _x2 = origin.X + length;
 }
Пример #25
0
 public CollisionTileMapper(FPInt scalex, FPInt scaley)
 {
     Init(scalex, scaley);
 }
Пример #26
0
        // Point -- [____] Collision + Edge Tests
        public static bool TestOverlapEdge(PointMask ptMask, FPInt x, FPInt y)
        {
            VectorFP p2 = (VectorFP)ptMask._pos + ptMask._point;

            return x == p2.X && y == p2.Y;
        }
Пример #27
0
 private Mask BuildTri(FPInt scalex, FPInt scaley, FPInt x1, FPInt y1, FPInt x2, FPInt y2, FPInt x3, FPInt y3)
 {
     return new TriangleMask(new PointFP(scalex * x1, scaley * y1),
         new PointFP(scalex * x2, scaley * y2),
         new PointFP(scalex * x3, scaley * y3));
 }
Пример #28
0
        public static bool TestOverlapEdge(AXLineMask xlMask, FPInt x, FPInt y)
        {
            VectorFP p2 = (VectorFP)xlMask._pos + xlMask._p;

            return (y == p2.Y && x >= p2.X && x <= p2.X + xlMask._w);
        }
Пример #29
0
        public bool OverlapsEdgeAny(FPInt x, FPInt y)
        {
            int txId = (int)(x.Floor / _tileWidth);
            int tyId = (int)(y.Floor / _tileHeight);

            if (txId < 0 || txId >= _width || tyId < 0 || tyId >= _height) {
                return false;
            }

            if (_grid[txId, tyId] == null) {
                return false;
            }

            return _grid[txId, tyId].TestOverlapEdge(x, y);
        }
Пример #30
0
 public static bool TestOverlapEdge(AXLine xlMask, FPInt x, FPInt y)
 {
     return (y == xlMask.Y && x >= xlMask.Left && x <= xlMask.Right);
 }