I got a little bit of a weird question. Way back when, when I was still learning about this sort of thing, I looked into Line Drawing Algorithms at the suggestion of someone else.
Basically, someone, somewhere, (Not that same someone who told me about line algorithms in the first place) SPECIFICALLY pointed out that instead of calculating how much big a Step is in one direction compared to a full Step in another, like this image here: https://lodev.org/cgtutor/images/raycastdelta.gif
You could just use the full distance values.
E.G. instead of going,
Xdelta=129:Ydelta=48
XD=1:YD=Ydelta/Xdelta
You could just use Xdelta and Ydelta in place of XD and YD and increase a counter instead, something like that.
It could be said over on stack exchange, heck I kind of feel like it might've been on a tutorial or a thread here on Smile, I'm not sure. Most other tutorials I've searched through come to the same or similar conclusion, they just don't specifically point it out. Any chance anyone's familiar with it?
I've got the code on my 3DS, I think it's based on Bresenham's Algorithm, but I can't search using it since I think I made some modifications to account for 16x16 tiles and I used my own variable names anyways.
Does anyone know this Line Drawing Algorithm article/tutorial/thread?
Gaelstrom_ValenceCreated:
I'm not entirely sure what you're asking here, but that image you found is from this tutorial: https://lodev.org/cgtutor/raycasting.html
Maybe the information you're looking for is there? I know I used that website to try and understand the math before.
Replying to:Minxrod
I'm not entirely sure what you're asking here, but that image you found is from this tutorial: https://lodev.org/cgtutor/raycasting.html
Maybe the information you're looking for is there? I know I used that website to try and understand the math before.
Naw, I just wanted to use that image as a reference. I've gone through that tutorial and... I mean, maybe I'm remembering things wrong, there is a similiar line in there, but I don't think that's it.
It sounds like you are looking for Bresenham's line drawing algorithm. There is some pseudo-code at the end of the following link.
https://en.wikipedia.org/wiki/Bresenham's_line_algorithm
You will have dx and dy as the distance traveled along the x, and y directions. You will iterate over the larger of the two. The code has an error counter with each step you add the dx or dy to the error counter (the one you aren't stepping over), if it exceeds the count you are iterating over you subtract that off and move by one in the minor direction.
I found another Bresenham reference by Michael Abrash online. (There is some BSP rendering code in the table of contents too.) It is old school DOS code so keep your expectations reasonable.
http://www.phatcode.net/res/224/files/html/ch35/35-01.html#Heading1