简体   繁体   English

XNA矩形和包含,将变得疯狂

[英]XNA rectangle & contain, going to be crazy

I'm going to be crazy. 我要疯了。 In fact, i use Rectangle to know if a point if inside of a rectangle. 实际上,我使用Rectangle来确定矩形内是否有一个点。

My rectangle is define like this : {X:0 Y:480 Width:480 Height:480} The point (Vector2) is define like this : {X:283,3333 Y:141,1111} 我的矩形的定义如下:{X:0 Y:480宽度:480高度:480}点(Vector2)的定义如下:{X:283,3333 Y:141,1111}

Normaly, the point is inside of the rectangle ? 通常,该点在矩形的内部? But not... 但不是...

if (rectangle.Contains(new Point((int)point.X, (int)point.Y)))
{
   return true;
}
return false;

With another test, it work with the same code : {X:-480 Y:0 Width:480 Height:480} contain {X:-12,22222 Y:12,22223} 在另一个测试中,它使用相同的代码:{X:-480 Y:0宽度:480高度:480}包含{X:-12,22222 Y:12,22223}

Plz, i really need some advices. Plz,我真的需要一些建议。

Seriously, i don't understand why it don't works ! 说真的,我不明白为什么它不起作用!

如果矩形的起始点为Y = 480,则点(283,141)不在其中。

Sorry but how is the point inside the rectangle? 抱歉,矩形内的点如何?

A simple test to know if a point is inside a rectangle: 判断点是否在矩形内的简单测试:

if ( p.X >= rectangle.X && p.X <= Rectangle.X + Rectangle.Width && p.X >= rectangle.X && p.Y <= Rectangle.Y + Rectangle.Height)

The Point (283, 141) obviously fail the third condition and therefor is not in the Rectangle. 点(283,141)显然没有通过第三个条件,因此不在矩形中。

It is however in this rectangle {X:0 Y:0 Width:480 Height:480} 但是它在此矩形中{X:0 Y:0宽度:480高度:480}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM