Search code examples
pythoncraycasting

Translate one line from C to Python


I'm currently following a tutorial to program raycasting, the tutorial is in C and I'm rewriting it in Python, but I can't understand the following line and so can't translate it in python :

float aTan = -1/tan(ra);
ry = (((int)py>>6)<<6-0.0001;
rx = (py-ry)*aTan+px;

Where ry and rx are the y and x coordinates of the intersection between, I think, the first horizontal line and the ray. Moreover, ra is the angle of the ray. The lines with aTan and rx are just maths so I understand them but the writing of ry is not familiar for a python student like me, could you enlighten me ?


Solution

  • The ">>" operator is the right shift, so integer division by power of two.

    Numerically

    ry = (((int)py>>6)<<6-0.0001;
    

    is equivalent to

    ry = (py // 64) * 64 - 0.0001
    

    (since 2^6 == 64)