<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Shadowcasting in C#, Part Three</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/12/19/shadowcasting-in-c-part-three.aspx</link><description>Before we get started, thanks for all the great comments to the previous couple of posts. I'll be updating the algorithm to try to make even better-looking circles of light based on the comments. Like I said, there's a lot of subtleties to these algorithms</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Shadowcasting in C#, Part Three</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/12/19/shadowcasting-in-c-part-three.aspx#10249537</link><pubDate>Tue, 20 Dec 2011 10:31:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249537</guid><dc:creator>Ross Morgan-Linial</dc:creator><description>&lt;p&gt;Geometrically, the only important points on a cell are the top-left corner and the bottom-right corner, because they are farthest apart as seen from the origin. If the bottom-right corner is above the field of view, or the top-left corner is below the field of view, the entire cell is outside the field of view; otherwise at least part of the cell is inside the field of view, even if just one point in the corner.&lt;/p&gt;
&lt;p&gt;So the solution to eliminate the artifact in case 4 is to do the calculation for the bottommost visible cell in a column using the left edge, and keep using the right edge for the topmost visible cell.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249537" width="1" height="1"&gt;</description></item><item><title>re: Shadowcasting in C#, Part Three</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/12/19/shadowcasting-in-c-part-three.aspx#10249418</link><pubDate>Tue, 20 Dec 2011 00:35:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249418</guid><dc:creator>pete.d</dc:creator><description>&lt;p&gt;&amp;quot;Under what circumstances can it be even? Can you find an example?&amp;quot;&lt;/p&gt;
&lt;p&gt;Hmmm...I admit, that question confuses me. Are you suggesting that outside of the particular example, it&amp;#39;s not possible for &amp;quot;top.Y&amp;quot; to be even? I agree in the example at hand, top.Y is odd (having the value of 3) and so the dividend is odd and so the remainder must be odd.&lt;/p&gt;
&lt;p&gt;But I don&amp;#39;t see any reason that for any given integer Y, I cannot find some direction vector that has that value of Y as its &amp;quot;rise&amp;quot; (Y) coordinate, including even values. For that matter, an equivalent value of (3,1) as in the first example of the page would be (6,2). Likewise, I can change the (5,3) vector in the final example to (10,6). Even values for Y are even easier, because I can just take any known vector and extend it by a factor of 2.&lt;/p&gt;
&lt;p&gt;Assuming that the magnitude of the direction vector actually doesn&amp;#39;t matter (as stipulated earlier), it seems trivial to find legal direction vectors for arbitrary values of Y (presumably in the expression at hand, I should always get the same remainder value for any equivalent representation of a given direction vector).&lt;/p&gt;
&lt;p&gt;Thus, if I can arbitrarily make &amp;quot;top.Y&amp;quot; an even number, I can likewise arbitrarily make the expression &amp;quot;((2 * x + 1) * top.Y)&amp;quot; (the dividend) even..&lt;/p&gt;
&lt;p&gt;Give your original statement along with your follow-up, I&amp;#39;m left to assume that you have a proof in mind that would show the contrary. This implies I&amp;#39;ve overlooked something (perhaps hidden in the &amp;quot;exercise for the reader&amp;quot; :) ). Suffice to say, at least from my own point of view, if such a proof exists then I think maybe some elaboration on the question is warranted.&lt;/p&gt;
&lt;p&gt;(Oh, by the way...I found that typo: &amp;quot;It sure seems light it ought to be...&amp;quot; &amp;nbsp;Should read &amp;quot;It sure seems like it ought to be...&amp;quot; :) )&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249418" width="1" height="1"&gt;</description></item><item><title>re: Shadowcasting in C#, Part Three</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/12/19/shadowcasting-in-c-part-three.aspx#10249406</link><pubDate>Mon, 19 Dec 2011 23:50:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249406</guid><dc:creator>Oisin Grehan</dc:creator><description>&lt;p&gt;Have you seen this &amp;quot;teleglitch&amp;quot; indie game demo vid? It&amp;#39;s a really nice example of shadowcasting coupled with a top-down early grand-theft auto view. Elements of that old arcade classic, &amp;quot;Smash TV&amp;quot; there too. Check it out at &lt;a rel="nofollow" target="_new" href="http://www.youtube.com/watch?v=c3Wr9EdQVEU"&gt;www.youtube.com/watch&lt;/a&gt; (No, I&amp;#39;m not the author.)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249406" width="1" height="1"&gt;</description></item><item><title>re: Shadowcasting in C#, Part Three</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/12/19/shadowcasting-in-c-part-three.aspx#10249338</link><pubDate>Mon, 19 Dec 2011 20:23:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249338</guid><dc:creator>pete.d</dc:creator><description>&lt;p&gt;On the topic of the final proposal: it seems to me that the main innovation in this particular solution is to shift the point of consideration half a cell to account for the nature of visibility. While the actual math is different to accommodate that and remain in integer computations, as near as I can tell the rounding aspect is still basically the same as in the third proposal (&amp;quot;round to nearest&amp;quot;).&lt;/p&gt;
&lt;p&gt;For what it&amp;#39;s worth, I agree with other commenters about the effectiveness of the narrative. It&amp;#39;s pleasurable to be given the opportunity to come to one&amp;#39;s own realization rather than having it just spread out in an initial article. For example, the statement &amp;quot;When you propose three different plausible calculations and they all turn out to be wrong in different ways, there might be an invalid assumption somewhere in the mix&amp;quot; is essentially the same conclusion I&amp;#39;d already come to by the time I got that far in the article.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s an example of a more general rule that I have, which is that if something starts to seem too difficult, I probably have made it that way and I&amp;#39;m missing some easier way to solve the problem. I&amp;#39;ve found this to be often true in the real world, but especially so in the environment of programming. There are exceptions, especially when working at very low levels where huge numbers of special cases, all of which have to be gotten exactly right. But in most cases, if the path appears to lead toward writing a lot of extra code to deal with lots of special cases that the generalized solution doesn&amp;#39;t address, it just means that the wrong generalization has been made.&lt;/p&gt;
&lt;p&gt;&amp;quot;Path of least-resistance&amp;quot;. &amp;nbsp;It&amp;#39;s not just for fluids, light, and electricity. &amp;nbsp;:)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249338" width="1" height="1"&gt;</description></item><item><title>re: Shadowcasting in C#, Part Three</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/12/19/shadowcasting-in-c-part-three.aspx#10249333</link><pubDate>Mon, 19 Dec 2011 20:06:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249333</guid><dc:creator>pete.d</dc:creator><description>&lt;p&gt;I have to admit, I found the passage from &amp;quot;Suppose the direction vector is (3, 5)...&amp;quot; to &amp;quot;...the remainder will always be an odd number&amp;quot; difficult to understand. The stumbling blocks for me:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;* I have become accustomed to thinking of the vectors/slopes as being written in (x,y) form, but &amp;quot;(3,5)&amp;quot; appears to be written in (y,x) form.&lt;/p&gt;
&lt;div class="yellowbox"&gt;
&lt;p&gt;Whoops, that was a typo. (5,3) is what I intended to write. Fixed, thanks. -- Eric&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;* As I understand it, &amp;quot;The remainder is the number of tenths...&amp;quot; applies to this particular example only; with a run of 5, doubling that produces a divisor of 10, thus all remainders are in tenths.&lt;/p&gt;
&lt;div class="yellowbox"&gt;
&lt;p&gt;Correct. -- Eric&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;* Similarly, the statement that the dividend will always be odd appears to apply only in this example. With a &amp;quot;top.Y&amp;quot; that&amp;#39;s odd, multiplied by an expression that itself will always be odd, the result is always odd. But &amp;quot;top.Y&amp;quot; could be even for other scenarios.&lt;/p&gt;
&lt;div class="yellowbox"&gt;
&lt;p&gt;Under what circumstances can it be even? Can you find an example? -- Eric&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In the second and third issues above, the main point of confusion for me is that the article does not call those statements out as being particular to the example. As a programmer, I am so used to dealing with generalizations and abstractions that when I read claims about the innards of an algorithm, my initial interpretation is to assume those claims refer to the algorithm generally. Given this (IMHO perfectly natural and reasonable assumption) I think it would be clearer and speed comprehension if the passage is explicit about the specific nature of those statements.&lt;/p&gt;
&lt;p&gt;Sorry if the above seems like nitpicking. I&amp;#39;m just trying to offer what I think would be useful pedagogical improvements.&lt;/p&gt;
&lt;div class="yellowbox"&gt;
&lt;p&gt;Good points all; I&amp;#39;ll clarify it. -- Eric&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;I thought I&amp;#39;d seen a simple typo early in the article, but after reloading the page I can&amp;#39;t find it any more. &amp;nbsp;So either I was mistaken, or you&amp;#39;ve fixed it already. &amp;nbsp;:)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249333" width="1" height="1"&gt;</description></item><item><title>re: Shadowcasting in C#, Part Three</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/12/19/shadowcasting-in-c-part-three.aspx#10249323</link><pubDate>Mon, 19 Dec 2011 19:45:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249323</guid><dc:creator>Tom</dc:creator><description>&lt;p&gt;Pre-build a lookup table for each cell based on your algorithm will significantly speed up its computation. &amp;nbsp;The computation time is significant when the radis of visible cells is 8 or more.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249323" width="1" height="1"&gt;</description></item><item><title>re: Shadowcasting in C#, Part Three</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/12/19/shadowcasting-in-c-part-three.aspx#10249309</link><pubDate>Mon, 19 Dec 2011 18:57:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249309</guid><dc:creator>Joshua Ganes</dc:creator><description>&lt;p&gt;I like that you were willing to take this explanation down a few false starts before coming to a more optimal approach. I feel like this is how I might have organically explored the problem myself. I agree that the artifacts from scenario four are not too big a worry, but I would probably not allow the view angle to increase as a result. It&amp;#39;s such a simple check that I feel it is worth doing to prevent strange &amp;quot;seeing around corners&amp;quot; artifacts.&lt;/p&gt;
&lt;div class="yellowbox"&gt;
&lt;p&gt;This series is very much a product of how I &amp;quot;organically explored&amp;quot; the algorithm. I spent a rather confusing Saturday afternoon trying to understand various different implementations of this algorithm and the subtle choices made -- possibly accidentally -- by the implementers. I thought it might be a nice public service to document what I learned from that process. -- Eric&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249309" width="1" height="1"&gt;</description></item><item><title>re: Shadowcasting in C#, Part Three</title><link>http://blogs.msdn.com/b/ericlippert/archive/2011/12/19/shadowcasting-in-c-part-three.aspx#10249308</link><pubDate>Mon, 19 Dec 2011 18:51:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249308</guid><dc:creator>Virtlink</dc:creator><description>&lt;p&gt;Great series! In your implementation of the game in part 1, when you stand on the left or right side of a wall, but not too close to it, then you can see past the wall. For example: &amp;nbsp; [ . . . X . . . @]. This doesn&amp;#39;t happen in the vertical direction or on any of the diagonals. I assume that this may be the case due to artifacts with determining the bottom cell of a column portion?&lt;/p&gt;
&lt;div class="yellowbox"&gt;
&lt;p&gt;Correct; I deliberately introduced those artifacts. We&amp;#39;ll discuss how they arise in Thursday&amp;#39;s episode of FAIC. -- Eric&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249308" width="1" height="1"&gt;</description></item></channel></rss>