Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - tiger_eye

Pages: [1]
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.

2
Programming / Re: Recursive shadowcasting wrong in wiki?
« on: January 08, 2012, 05:04:10 AM »
Shadow casting is weird like that...  It's a tradeoff between accuracy and visual appeal.
No, it's not.  The original post is correct: the recursive shadowcasting code on the wiki is apparently incorrect if it behaves as he showed.  Also, if you're doing recursive shadowcasting in C, then there is no reason whatsoever to switch to a different algorithm based on speed alone.  It should be amply fast enough (even if you don't do the fastest possible implementation).

Anyway, here are a couple quick fixes to your code that should bring you closer to a properly working recursive shadowcasting algorithm:
Code: [Select]
`            int x = 0;            int y = 0;            switch (octant)            {                case 1:                    y = playerPosition.Y - depth;                    x = (int)Math.Round(playerPosition.X - startSlope * depth);                    if (x < 0)                        break;                    if (x >= mapDimensions.X)                        break;                    if (y < 0)                        break;                    if (y >= mapDimensions.Y)                        break;                    while (GetSlope(x, y, playerPosition.X, playerPosition.Y) >= endSlope)                    {                        if (IsWithinVisualRange(playerPosition.X, playerPosition.Y, x, y))                        {                            if (map[y][x].BlocksVision)                            {                                //if (TestCell(x - 1, y, playerPosition.X, playerPosition.Y, false, depth))                                if(!map[y][x - 1].BlocksVision)  // TODO!  Don't do the below on the very first iteration.                                    RecursiveScan(playerPosition, depth + 1, octant, startSlope, GetSlope(x - 0.5, y + 0.5, playerPosition.X, playerPosition.Y));                                lightMap[y][x] = 1;                                visitedMap[y][x] = true;                            }                            else                            {                                //if (TestCell(x - 1, y, playerPosition.X, playerPosition.Y, true, depth))                                // MODIFIED!                                if(map[y][x - 1].BlocksVision)                                {                                    startSlopeNext = GetSlope(x - 0.5, y - 0.5, playerPosition.X, playerPosition.Y);                                    if (startSlope < startSlopeNext)                                    {                                        startSlope = startSlopeNext;                                        if (startSlope > endSlope)                                            break;                                    }                                }                                lightMap[y][x] = 1;                                visitedMap[y][x] = true;                            }                        }                        x++;                    }                    // ADDED!                    if(!map[y][x].BlocksVision)                    {                        if (map[y][x + 1].BlocksVision)                        {                            endSlopeNext = GetSlope(x + 0.5, y + 0.5, playerPosition.X, playerPosition.Y);                            if (endSlopeNext < endSlope)                                endSlope = endSlopeNext;                        }                        RecursiveScan(playerPosition, depth + 1, octant, startSlope, endSlope, playerPosition.X, playerPosition.Y));                    }`

Pages: [1]