基本上我有一個矩形網格,每個75x75並排。我將一個對象放入這些矩形中,當我放置該對象時,我需要確定它與MOST相交的矩形。如何確定哪個矩形正在相交更多C#XNA
這很可能會是這個樣子:
private Rectangle placeObject(Vector2 cursorPosition)
{
Rectangle HolderRectangle;
Rectangle r1 = new Rectangle((int)cursorPosition.Position.X, (int)cursorPosition.Position.Y, 70, 70);
Foreach(Rectangle r in rectangles)
{
r2 = new Rectangle((int)r.Position.X, (int)r.Position.Y, 75,75)
if(r1.Intersects(r2))
{
//Check how much it intersects
//if it intersects more than the current holder Rectangle
//set HolderRectangle = r2
}
}
return HolderRectangle;
}
就是我問甚至可能嗎?如果是這樣如何? )