1
Programming / Re: Recursive shadowcasting wrong in wiki?
« on: January 08, 2012, 03:29:31 PM »
Nope and nope. Copy/paste error on my part. I guess the end of the case should probably be:
Code: [Select]
}
x++;
}
x--;
// ADDED!
if (map[y][x + 1].BlocksVision)
{
endSlopeNext = GetSlope(x + 0.5, y + 0.5, playerPosition.X, playerPosition.Y);
if (endSlopeNext < endSlope)
endSlope = endSlopeNext;
}
since the recursive call is done after all the switch/cases in the example code on the wiki. This is a minor check, but still necessary for fully proper behavior. I think with the way you're doing the rounding, you iterate over a grid if the constraining slope intersects with a full-width diamond within a tile. Obstructions, on the other hand, are treated as squares. This code checks whether endSlope intersects with a blocked tile (full square) that it didn't otherwise iterate over b/c it didn't intersect with the diamond within the tile and adjusts endSlope as necessary.