void DebugDrawCellDetails(int x, int y, int cellCount, float secondsToDisplay = 0.5f, float textScale = 1f) { ECDebug.DrawHollowRect(new Rectangle(x * _cellSize, y * _cellSize, _cellSize, _cellSize), Color.Red, secondsToDisplay); if (cellCount > 0) { var textPosition = new Vector2((float)x * (float)_cellSize + 0.5f * _cellSize, (float)y * (float)_cellSize + 0.5f * _cellSize); ECDebug.DrawText(Graphics.Instance.DevFont, cellCount.ToString(), textPosition, Color.DarkGreen, secondsToDisplay, textScale); } }
public static bool IntersectMovingCircleBox(Circle s, Box b, Vector2 movement, out float time) { // compute the AABB resulting from expanding b by sphere radius r var e = b.bounds; e.Inflate(s.Radius, s.Radius); // Intersect ray against expanded expanded Rectangle e. Exit with no intersection if ray // misses e, else get intersection point p and time t as result var ray = new Ray2D(s.position - movement, s.position); if (!e.RayIntersects(ref ray, out time) && time > 1.0f) { return(false); } // get the intersection point var point = ray.Start + ray.Direction * time; // compute which min and max faces of b the intersection point p lies outside of. Note, u and v cannot have the // same bits set and they must have at least one bit set among them. int u = 0, v = 0; if (point.X < b.bounds.Left) { u |= 1; } if (point.X > b.bounds.Right) { v |= 1; } if (point.Y < b.bounds.Top) { u |= 2; } if (point.Y > b.bounds.Bottom) { v |= 2; } // 'or' all set bits together into a bitmask (note u + v == u | v) var m = u + v; // if all 3 bits are set then point is in a vertex region if (m == 3) { // must now intersect segment against the capsules of the two edges meeting at the vert and return the best time, // if one or more hit // https://play.google.com/books/reader?printsec=frontcover&output=reader&id=VSoIBwAAAEAJ&pg=GBS.PA267 // https://github.com/noonat/hello/blob/580b986f3bb27b93645087441d2744eeb99d6d35/hello/collisions/Collision.hx#L675 //throw new NotImplementedException(); Debug.Log("m == 3. corner {0}", Time.FrameCount); } // if only one bit is set in m then point is in a face region if ((m & (m - 1)) == 0) { ECDebug.DrawHollowBox(point, 4, Color.Black, 0.4f); // do nothing. time from the expanded rect intersection is the correct time return(true); } // point is on an edge region. intersect against the capsule at the edge. return(true); }