public AABBMask(PointFP p, FPInt width, FPInt height) { _type = MaskType.AABB; _point = p; _w = width; _h = height; }
public LineMask(PointFP p0, PointFP p1) { _type = MaskType.Line; _p0 = p0; _w = p1.X - p0.X; _h = p1.Y - p0.Y; }
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); }
public Position(FPInt x, FPInt y) { _x = x; _y = y; _prevX = x; _prevY = y; }
public LineMask(PointFP p0, FPInt dw, FPInt dh) { _type = MaskType.Line; _p0 = p0; _w = dw; _h = dh; }
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; }
public static FPInt Abs(FPInt v) { if (v._raw < 0) { return v.Inverse; } else { return v; } }
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); }
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); }
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; }
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); }
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)); }
public override bool TestOverlapEdge(FPInt x, FPInt y) { return Collision.TestOverlapEdge(this, x, y); }
public CircleMask(PointFP center, FPInt radius) { _type = MaskType.Circle; _p = center; _radius = radius; }
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); }
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); }
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; }
public static bool TestOverlapEdge(AYLine ylMask, FPInt x, FPInt y) { return (x == ylMask.X && y >= ylMask.Top && y <= ylMask.Bottom); }
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); }
public virtual bool TestOverlapEdge(FPInt x, FPInt y) { return TestOverlap(x, y); }
public Frog(FPInt x, FPInt y) : base() { _position.X = x; _position.Y = y; //AddBehavior(new CircleMovement(this, new Vector2(x, y), 50, MathHelper.Pi)); }
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; } }
public AXLine(PointFP origin, FPInt length) { _y = origin.Y; _x1 = origin.X; _x2 = origin.X + length; }
public CollisionTileMapper(FPInt scalex, FPInt scaley) { Init(scalex, scaley); }
// 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; }
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)); }
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); }
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); }
public static bool TestOverlapEdge(AXLine xlMask, FPInt x, FPInt y) { return (y == xlMask.Y && x >= xlMask.Left && x <= xlMask.Right); }