Page 2 of 2

Re: Find top, bottom, left and right side of the window?

Posted: Tue Dec 14, 2021 9:09 am
by pgimeno
Pixel centres are where darkfrei said. For lines, line rectangles and polygons, it's generally better to use those. For rectangles and images (and anything rectangular) it's best to use integral dimensions.

Technically the left border is indeed 0, 0 but the right border is love.graphics.getWidth(), love.graphics.getHeight(). For collisions, which is what the OP was about, you usually have a rectangle-rectangle collision, and if you use 0 and love.graphics.getWidth() - 1 as left and right limits for the X coordinate respectively, there will be a 1 pixel line margin on the right.

Re: Find top, bottom, left and right side of the window?

Posted: Tue Dec 14, 2021 9:38 am
by grump
This thread has everything: window coordinates, physics, a short essay on canvas scaling, pixel center coordinates, arrays (???), and where to render primitives.

To summarise the important information:

The left-top pixel in window coordinates is at 0, 0. The right-bottom pixel in window coordinates is at love.graphics.getWidth() - 1, love.graphics.getHeight() - 1.

The bounds encompassing the window area are 0, 0 (left, top) and love.graphics.getWidth(), love.graphics.getHeight() (right, bottom).

Re: Find top, bottom, left and right side of the window?

Posted: Tue Dec 14, 2021 11:30 am
by darkfrei
grump wrote: Tue Dec 14, 2021 8:52 am
darkfrei wrote: Tue Dec 14, 2021 8:10 am 0.5, 0.5 and love.graphics.getWidth() - 0.5, love.graphics.getHeight() - 0.5,
No. I think you're confusing different coordinate systems.
But you can have 0 to width and 0 to height arrays for them.
What do you mean, arrays for "them"? What is "them", pixels? And why would those arrays be larger than the window?
If you draw the rectangle in "line", then it must be shifted at 0.5 pixel. The same for lines, as I know.

If you make a grid every 100 pixels in the window 800x600, then you can draw the lines at x=0, x=800, y=0, y=600 too.

Re: Find top, bottom, left and right side of the window?

Posted: Tue Dec 14, 2021 12:08 pm
by grump
darkfrei wrote: Tue Dec 14, 2021 11:30 am If you draw the rectangle in "line", then it must be shifted at 0.5 pixel. The same for lines, as I know.

If you make a grid every 100 pixels in the window 800x600, then you can draw the lines at x=0, x=800, y=0, y=600 too.
Yeah, points, lines, and other primitives in 'line' mode. Those are the rasterizer rules, not the window coordinate rules. Window coordinates are integer. For example, a mouse cursor in the top-left corner of the window is at 0, 0. Not 0.5, 0.5.

I wouldn't count on your grid thing. Whether or not those lines are visible is a gamble and depends on GPU and drivers, and the selected line smoothing mode.

All of this is severely underdocumented in the wiki, and all examples are wrong.