internal override bool GetCollisionCircle(CollisionCircle obj) { //float rd2 = Pow2(obj.Radius + Width); //Vector2 ao = obj.Position - Position; //Vector2 bo = obj.Position - End; //if (ao.LengthSquared() <= rd2 || bo.LengthSquared() <= rd2) return true; //if (!(Vector2.Dot(-Line, ao) * Vector2.Dot(Line, bo) >= 0)) return false; //if ((Line.Y * obj.Position.X + Line.X * obj.Position.Y + Position.X * Line.Y - Position.Y * Line.X) // / Line.LengthSquared() <= rd2) return true; if (System.Math.Abs(MathUtilXNA.Cross(obj.Position - Begin, Line) / (Line.Length())) > obj.Radius) return false; if (Vector2.Dot(Line, obj.Position - Begin) * Vector2.Dot(-Line, obj.Position - End) <= 0) return true; if (obj.GetCollision(new CollisionPoint(Begin)) || obj.GetCollision(new CollisionPoint(End))) return true; return false; }
public CollisionPolygon(Vector2[] v) { vertices = (Vector2[])v.Clone(); Trans = true; temp = new Vector2[v.Length]; float or = 0, ir = float.MaxValue; float t; foreach (var item in vertices) { t = item.LengthSquared(); or = MathHelper.Max(or, t); ir = MathHelper.Min(ir, t); } or = (float)System.Math.Sqrt(or); ir = (float)System.Math.Sqrt(ir); outCircle = new CollisionCircle(or, Position); inCircle = new CollisionCircle(ir, Position); }
internal override bool GetCollisionCircle(CollisionCircle obj) { return obj.GetCollision(this); }
internal override bool GetCollisionCircle(CollisionCircle obj) { Apply(); if (!outCircle.GetCollision(obj)) return false; if (inCircle.GetCollision(obj)) return true; if (GetCollisionPoint(new CollisionPoint(obj.Position))) return true;//円が完全に入っている for (int i = 0; i < temp.Length; i++)//辺と円が交わる { if (Line(i).GetCollision(obj)) return true; } foreach (var item in temp)//頂点と円が交わる { if (new CollisionPoint(item).GetCollision(obj)) return true; } return false; }
internal override bool GetCollisionCircle(CollisionCircle obj) { return Pow2(obj.Radius + Radius) >= (obj.Position - Position).LengthSquared(); }
internal abstract bool GetCollisionCircle(CollisionCircle obj);
//適当 internal override bool GetCollisionCircle(CollisionCircle obj) { return obj.Position.X + obj.Radius > Left && obj.Position.X - obj.Radius < Right && obj.Position.Y - obj.Radius < Top && obj.Position.Y + obj.Radius > Bottom; }