0

At the moment I have the same problem as this post had.

I am trying to make a raycaster and have been stuck on the DDA algorithm for about a week.

The current DDA algorithm I'm using is from a GeeksForGeeks post:

def DDA(x1, y1, x2, y2):
    dx = x2 - x1
    dy = y2 - y1

    steps = abs(dx) if abs(dx) > abs(dy) else abs(dy)

    X = float(dx / steps)
    Y = float(dy / steps)
    
    a = [] 
    for i in range(0, int(steps + 1)):
        a.append((x1, y1))
        x1 += X
        y1 += Y
    return a

To display the returned output I am using:

for p in DDA(x1,y1,x2,y2):
    x=int(p[0])
    y=int(p[1])
    draw_block(x,y)

This is the output that I don't want, see how it will go diagonally, I don't want that.

As I have said, this shows how it can be done, however I do not understand it and have tried to convert it multiple times to python and have been completely unable to.

Does anyone know how i can make this complex function in python. The desired output is shown by this post here. and this image.

0 Answers0