gamercade-io / gamercade_console

A Neo-Retro Fantasy Console. Make WASM-powered, networked multiplayer games.
https://gamercade.io
Apache License 2.0
168 stars 10 forks source link

"Draw Lines" function doesn't handle out of bounds areas correctly. #3

Closed RobDavenport closed 1 year ago

RobDavenport commented 2 years ago

When trying to call draw_lines and passing bounds outside of the window, the line will sometimes appear or not, depending on start/end position.

We should draw lines across the screen regardless of the location, assuming it actually has pixels inside of the screen.

RobDavenport commented 2 years ago

For more clarity here, its mostly happening with non-horizontal and non-vertical lines.

This can be solved by finding the intersection point if the line with the clipping plane (where x or y equals 0 or width/height -1), and clamping the point to that value.

Its usually called "raster clipping" and there are articles about it for triangles (for 3d rendering), so it shouldn't be too hard to do the same with a single line.

RobDavenport commented 2 years ago

For some more clarity on the issue at hand here:

image

The two images on the left is what should be seen, but it's not whats happening at the moment

RobDavenport commented 1 year ago

Resolved in https://github.com/gamercade-io/gamercade_console/commit/4082bb425b02b85db053771b0261dde78d23d353