Thursday, 15 July 2010

c# - Can some please explain why the xna Rectangle struct behaves like it does? -


I understand why the XNA rectangle structure is written as it is.

If I run this code:

  var bounds = new rectangle (0, 0, 10, 10); Var bound 2 = new rectangle (0, 10, 10, 10); Var bound3 = new rectangle (0, 19, 10, 10); Debug. Print ("Bounce X: {0}, Y: {1}, Top: {2} Left: {3} Below: {4} Right {5}", Boundaries X., B.2, Boundaries. Width, limitations, width, limitations.); Debug Print ("Bounds 2 X: {0}, Y: {1}, Top: {2} Left: {3} Bottom: {4} Right {5}", Bounds 2.x, Bounds 2.Y, Bounds 2 ., Bounds 2. Late, Bounds 2. Batam, Bounds 2. Right); Debug Print ("Bounce 2 X: {0}, Y: {1}, Top: {2} Left: {3} Bottom: {4} Right {5}", Bound 3. X, Bounds 3. Y, Bound 3 ., Bound 3. Late, Bounds 3. Bottom, Bound 3. Right); Debug Print ("bound, inner circle (boundary) 2: {0}", boundaries, intersection (boundary 2)); Debug.print ("bounds 2. intercexes (frontline 3): {0}", bounds 2. intercexes (frontline 3));   

I get the following output:

  Bunds X: 0, Y: 0, top: 0 left: 0 down: 10 right 10 bounce 2 x : 0, Y: 10, Top: 10 left: 0 down: 20 right 10 bounce 2 X: 0, Y: 19, top: 19 left: 0 down: 29 right 10 bounce. Intersecting (Frontline): False obligations 2. Interception (boundary 3): True, the Intersects method works correctly because  bound  does not overlap  bounds2  at  bounds2  one line of pixels From  bound 3  overlaps with  

However, output seems strange to me for down and right . Both of those report values ​​which are more than 1 pixel, I think they should be and I always get caught by it, it produces frustration.

For example, I can use rectangular to create a bounding box for a rectangular phantom. For convenience, I want to use values ​​like width , height , right and below but true and below values ​​do not give me the column on the right and the right-hand column of pixels, they just give me the bottom line and the column on the right just the texture.

Is there any good reason to work this way? Do you use rectangular boxes for the boxing box in XNA, and if you are seeing such behavior or can you suggest a way to improve your perspective?

thanks

This is the Windows API rect structure Is similar to that which is for at least Windows 3.x

The reason for this is that it simplifies some calculation.

Here is a blog entry from 2004:

Note that drawing a GDI line (and perhaps XNA also uses special intervals for the same line. < / Div>

No comments:

Post a Comment