I'm trying to wrap my head around how to check for collision along a raycast. What I am doing is raycasting from a source to a goal and I want to check if that path is clear. I am doing this in a HTML canvas so it's a 2d environment.
Since raycasting is a one-frame thing I can't iteratively check each pixel unless I map them to an array or something, and checking the pixel colour doesn't seem like a good idea anyway, since that's not really a programmatic solution. I could record the boundary space of every object on screen and check my raycast against them but that would require me to map the pixels of my raycast again, and would require that I record in an array and loop through every pixel on screen.
How do you cast a ray and check that it is clear? And if it isn't clear, how do you find out where it is blocked and what it hit?
EDIT: on a side note, what is the usually accepted way to programmatically record and define the entirety of an edge or face in 2d space? I am recording the four corners of the bounding box and then figuring out the location of all the pixels in between the points and recording them on a multidimensional array. It's really clunky. Is there a better data type to use for this? Or is it something that can be sidestepped entirely?







