光線の方向を決める
光線方向が負の x 成分を持つ場合、stepX は -1 で、
光線方向が正の x 成分を持つ場合、stepX +1 となります。
光線方向が正の x 成分を持つ場合、stepX +1 となります。
光線方向が 0 がx 成分 の場合、stepX は使用されないので、どのような値であっても問題ではありません。
同様なロジックがy-成分でも言えます。
//calculate step and initial sideDist
if (rayDirX < 0)
{
stepX = -1;
sideDistX = (posX - mapX) * deltaDistX;
}
else
{
stepX = 1;
sideDistX = (mapX + 1.0 - posX) * deltaDistX;
}
if (rayDirY < 0)
{
stepY = -1;
sideDistY = (posY - mapY) * deltaDistY;
}
else
{
stepY = 1;
sideDistY = (mapY + 1.0 - posY) * deltaDistY;
}