<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coder&#039;s Playground</title>
	<atom:link href="http://blog.codersplayground.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codersplayground.net</link>
	<description>Coder by Design. Designer by Code.</description>
	<lastBuildDate>Fri, 03 May 2013 10:38:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Website Getting an Update</title>
		<link>http://blog.codersplayground.net/2013/general-information/website-getting-an-update/</link>
		<comments>http://blog.codersplayground.net/2013/general-information/website-getting-an-update/#comments</comments>
		<pubDate>Thu, 02 May 2013 18:24:56 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[General Information]]></category>

		<guid isPermaLink="false">http://blog.codersplayground.net/?p=485</guid>
		<description><![CDATA[My website that this blog is attached to (<a href="http://www.codersplayground.net/">codersplayground.net</a>) is getting an update. If you want to see what I am doing with it you can go to the <a href="http://www.codersplayground.net/dev/">dev section</a>. Be aware that not all the content will be present.]]></description>
				<content:encoded><![CDATA[<p>My website that this blog is attached to (<a href="http://www.codersplayground.net/">codersplayground.net</a>) is getting an update. If you want to see what I am doing with it you can go to the <a href="http://www.codersplayground.net/dev/">dev section</a>. Be aware that not all the content will be present.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2013/general-information/website-getting-an-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing For Loops</title>
		<link>http://blog.codersplayground.net/2013/coding/optimizing-for-loops/</link>
		<comments>http://blog.codersplayground.net/2013/coding/optimizing-for-loops/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 01:12:55 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Code Optimization]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Optimized Code]]></category>
		<category><![CDATA[Professional Code]]></category>

		<guid isPermaLink="false">http://blog.codersplayground.net/?p=476</guid>
		<description><![CDATA[I am pretty obsessed with getting every little bit of performance I can out of my code, especially when developing for mobile platforms. For loops, believe it or not, can be optimized using some very simple tricks.]]></description>
				<content:encoded><![CDATA[<p>I am pretty obsessed with getting every little bit of performance I can out of my code, especially when developing for mobile platforms. For loops, believe it or not, can be optimized using some very simple tricks. Normally you probably write a for loop like this:</p>
<pre class="brush:c#">for (int i = 0; i < some.Length; i++) {
    // Code
}</pre>
<p>If you know that the length of whatever you're iterating is going to be less than 256 (0-255) you can use byte instead of int, if you aren't completely certain, you can probably get away with ushort (0-65,535). This will free up 24 and 16 bits as compared to int respectively, it's not much, but it can add up. You can also pre-lock the length into a variable to help speed things up. The reason this works is because for loop check their condition (second block) every single iteration. This means that you are accessing the length property every single iteration. Accessing a member of a class is more expensive than accessing a single variable, and thus adds up over many iterations. The performance change might be slight, but it adds up pretty quickly, especially if you are iterating through hundreds of pieces of data every single frame. So, what should the for loop look like? Well, like this:</p>
<pre class="brush:c#">
byte length = some.Length;
for (byte i = 0; i < length; i++) {
    // Code
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2013/coding/optimizing-for-loops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Initial Velocity Given Angle and Distance</title>
		<link>http://blog.codersplayground.net/2013/coding/math-science/finding-initial-velocity-given-angle-and-distance/</link>
		<comments>http://blog.codersplayground.net/2013/coding/math-science/finding-initial-velocity-given-angle-and-distance/#comments</comments>
		<pubDate>Sat, 16 Mar 2013 18:31:59 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[Math & Science]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Coding Equations]]></category>
		<category><![CDATA[Deriving Equations]]></category>
		<category><![CDATA[Equation Code]]></category>
		<category><![CDATA[Equations]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Physics]]></category>
		<category><![CDATA[Projectile Physics]]></category>
		<category><![CDATA[Solving Equations]]></category>

		<guid isPermaLink="false">http://blog.codersplayground.net/?p=268</guid>
		<description><![CDATA[Projectile physics can be a little complicated, especially if you already know where you want the projectile to go, and just need to figure out the required velocity. This post derives an equation which takes in a destination and launch angle and gives you the velocity you need.]]></description>
				<content:encoded><![CDATA[<p>Most of the time a physics problem involves using a given angle and velocity to figure out where a projectile lands. This is all well and good, but when working on a game with projectiles you already know where it should land, and what angle it should be launched at. This article shows the process by which I solved the basic physics equations to take in the desired difference in distance, height, and launch angle, and give you the required velocity in return. If you aren't terribly interested in the work, you can just skip to the <u><a href="#solution">solution</a></u>. Without further ado, here's the process by which I solved the equations.</p>
<h2>The Standard Equations</h2>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_f802d0b36ed7069751496e8381b77cff.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align*}x\prime\ &=\ x\ +\ tv\cos\theta\\y\prime\ &=\ y\ +\ tv\sin\theta\ -\ \frac{1}{2}gt^2\end{align*}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align*}x\prime\ &=\ x\ +\ tv\cos\theta\\y\prime\ &=\ y\ +\ tv\sin\theta\ -\ \frac{1}{2}gt^2\end{align*}}</script></p></p>
<h2>Rearranging and Replacing</h2>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_c1825f31ad4074e70d8158a75e2de164.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align*}x\prime\ -\ x\ &=\ tv\cos\theta\tag{x.1}\\d\ &=\ tv\cos\theta\label{x.2}\tag{x.2}\end{align*}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align*}x\prime\ -\ x\ &=\ tv\cos\theta\tag{x.1}\\d\ &=\ tv\cos\theta\label{x.2}\tag{x.2}\end{align*}}</script></p><br />
<p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_a1ea087b845f31c4b8bc4b920a913784.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align*}0\ &=\ y\ -\ y\prime\ +\ tv\sin\theta\ -\ \frac{1}{2}gt^2\tag{y.1}\\0\ &=\ h\ +\ tv\sin\theta\ -\ \frac{1}{2}gt^2\label{y2}\tag{y.2}\end{align*}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align*}0\ &=\ y\ -\ y\prime\ +\ tv\sin\theta\ -\ \frac{1}{2}gt^2\tag{y.1}\\0\ &=\ h\ +\ tv\sin\theta\ -\ \frac{1}{2}gt^2\label{y2}\tag{y.2}\end{align*}}</script></p></p>
<p>To make things more obvious, we will replace the differences with a single variable, namely  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_c9f9c3db0a2dab7fdbf88c0b66be8b6e.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="\large{d\ =\ x\prime\ -\ x}" /></span><script type='math/tex'>\large{d\ =\ x\prime\ -\ x}</script>  (where  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_71f3384c3c175ce2869811a1c2158cab.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="\large{d}" /></span><script type='math/tex'>\large{d}</script>  is the intended travel distance), and  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_28c648f0e2ca5483488711473c986491.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\large{h\ =\ y\ -\ y\prime}" /></span><script type='math/tex'>\large{h\ =\ y\ -\ y\prime}</script>  (where  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_ab2c6c21114e6bdd8d9cc01ae7b71d0e.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="\large{h}" /></span><script type='math/tex'>\large{h}</script>  is how high the projectile starts relative to its ending height).</p>
<h2>Eliminating  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_849f6a677dce8bb96d3b098d6cc3c6f5.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="t\!\!\!\;" /></span><script type='math/tex'>t\!\!\!\;</script> ime</h2>
<p>In order for this equation to work, time cannot be a factor. In truth, it really doesn't matter how long the projectile takes to get there, just that we arrive. If you need time later, just divide the range by the  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_051821cf5f33d3fed9ac433b446de8e5.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\large{x}" /></span><script type='math/tex'>\large{x}</script>  velocity component. Since the  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_8766c463206073030f7807badcb022af.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="\large{y}" /></span><script type='math/tex'>\large{y}</script>  equation has a quadratic for time, we'll solve that one.</p>
<p>Using the condensed height equation in  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_a16fcb1ae1c29a4d9002acd5295d7c36.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\large{\eqref{y2}\!}" /></span><script type='math/tex'>\large{\eqref{y2}\!}</script> , we can solve using the quadratic formula (and some basic negation cancellation).</p>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_6de2e1ec3e36b8b2c6d299a3bf62a860.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align*}t\ =\ \frac{v\sin\theta\ \pm\ \sqrt{v^2\sin^2\theta\ +\ 2gh}}{g}\label{t}\tag{t}\end{align*}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align*}t\ =\ \frac{v\sin\theta\ \pm\ \sqrt{v^2\sin^2\theta\ +\ 2gh}}{g}\label{t}\tag{t}\end{align*}}</script></p></p>
<p>Since we know that what is coming out of the square root is positive, we can eliminate the possibility of a negative option as being the one we ultimately want. The projectile is supposed to be moving forwards after all.</p>
<h2>The Heart of the Matter</h2>
<p>Now that we have time eliminated from  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_d5975764cb968a607caa19cf1674183f.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\large{\eqref{t}\!}" /></span><script type='math/tex'>\large{\eqref{t}\!}</script> , we need to plug it in to the  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_9eab7466e95172f0402c42d615d968c8.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\eqref{x.2}" /></span><script type='math/tex'>\eqref{x.2}</script>  equation.</p>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_7d9dcd061002373cbbca58fc98aab17a.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align}d\ &=\ \frac{v\cos\theta}{g}\left[v\sin\theta\ +\ \sqrt{v^2\sin^2\theta\ +\ 2gh}\right]\end{align}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align}d\ &=\ \frac{v\cos\theta}{g}\left[v\sin\theta\ +\ \sqrt{v^2\sin^2\theta\ +\ 2gh}\right]\end{align}}</script></p></p>
<p>Then we need to solve that monster for  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_2605a894c5adf9b65ae356be67cb3a7f.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\large{v}" /></span><script type='math/tex'>\large{v}</script> . We start by moving  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_a679b56d33c8a96c92fa02c3aa8808c9.gif' style='vertical-align: middle; border: none; padding-bottom:1px;' class='tex' alt="\large{g}" /></span><script type='math/tex'>\large{g}</script>  over, and distributing  <span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_692734e155f1c114b81008515c85098d.gif' style='vertical-align: middle; border: none; ' class='tex' alt="\large{v\cos\theta}" /></span><script type='math/tex'>\large{v\cos\theta}</script> .</p>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_5f05e918960e5a8f069b2f281903f1d7.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align}dg\ =&\ v\cos\theta\left[v\sin\theta\ +\ \sqrt{v^2\sin^2\theta\ +\ 2gh}\right]\\\nonumber\\=&\ v^2\sin\theta\cos\theta\ +\ v\cos\theta\sqrt{v^2\sin^2\theta\ +\ 2gh}\\\nonumber\\=&\ v^2\sin\theta\cos\theta\ +\nonumber\\&\ \sqrt{v^4\sin^2\theta\cos^2\theta\ +\ 2ghv^2\cos^2\theta}\end{align}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align}dg\ =&\ v\cos\theta\left[v\sin\theta\ +\ \sqrt{v^2\sin^2\theta\ +\ 2gh}\right]\\\nonumber\\=&\ v^2\sin\theta\cos\theta\ +\ v\cos\theta\sqrt{v^2\sin^2\theta\ +\ 2gh}\\\nonumber\\=&\ v^2\sin\theta\cos\theta\ +\nonumber\\&\ \sqrt{v^4\sin^2\theta\cos^2\theta\ +\ 2ghv^2\cos^2\theta}\end{align}}</script></p></p>
<p>We then isolate the square root and square both sides to eliminate it, and consolidate common terms.</p>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_2f75b24658d5ac09aea09edb1483f65f.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align}dg\ -\ &v^2\sin\theta\cos\theta\ =\ \nonumber\\\ &\ \sqrt{v^4\sin^2\theta\cos^2\theta\ +\ 2ghv^2\cos^2\theta}\\\nonumber\\d^2g^2\ -\ &2dgv^2\sin\theta\cos\theta\ +\ v^4\sin^2\theta\cos^2\theta\ =\nonumber\\&\ v^4\sin^2\theta\cos^2\theta\ +\ 2ghv^2\cos^2\theta\\\nonumber\\d^2g^2\ -\ &2dgv^2\sin\theta\cos\theta\ =\ 2ghv^2\cos^2\theta\\\nonumber\\d^2g^2\ =&\ \ 2ghv^2\cos^2\theta\ +\ 2dgv^2\sin\theta\cos\theta\end{align}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align}dg\ -\ &v^2\sin\theta\cos\theta\ =\ \nonumber\\\ &\ \sqrt{v^4\sin^2\theta\cos^2\theta\ +\ 2ghv^2\cos^2\theta}\\\nonumber\\d^2g^2\ -\ &2dgv^2\sin\theta\cos\theta\ +\ v^4\sin^2\theta\cos^2\theta\ =\nonumber\\&\ v^4\sin^2\theta\cos^2\theta\ +\ 2ghv^2\cos^2\theta\\\nonumber\\d^2g^2\ -\ &2dgv^2\sin\theta\cos\theta\ =\ 2ghv^2\cos^2\theta\\\nonumber\\d^2g^2\ =&\ \ 2ghv^2\cos^2\theta\ +\ 2dgv^2\sin\theta\cos\theta\end{align}}</script></p></p>
<p>We continue to eliminate like terms, extract the velocity component, and re-balance.</p>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_427495023e6398cb918d2d646e94b24c.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align}d^2g\ =&\ \ 2hv^2\cos^2\theta\ +\ 2dv^2\sin\theta\cos\theta\\\nonumber\\d^2g\ =&\ v^2\left(2h\cos^2\theta\ +\ 2d\cos\theta\sin\theta\right)\\\nonumber\\v^2\ =&\ \frac{d^2g}{2h\cos^2\theta\ +\ 2d\cos\theta\sin\theta}\end{align}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align}d^2g\ =&\ \ 2hv^2\cos^2\theta\ +\ 2dv^2\sin\theta\cos\theta\\\nonumber\\d^2g\ =&\ v^2\left(2h\cos^2\theta\ +\ 2d\cos\theta\sin\theta\right)\\\nonumber\\v^2\ =&\ \frac{d^2g}{2h\cos^2\theta\ +\ 2d\cos\theta\sin\theta}\end{align}}</script></p></p>
<p>Using trig identities we can simplify the equation, and keep like terms.</p>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_4c268048a9144f5020c42028f0542b24.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align}v^2\ =&\ \frac{d^2g}{2h\cos^2\theta\ +\ d\sin2\theta}\\\nonumber\\v^2\ =&\ \frac{d^2g}{h\cos2\theta\ +\ h\ +\ d\sin2\theta}\end{align}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align}v^2\ =&\ \frac{d^2g}{2h\cos^2\theta\ +\ d\sin2\theta}\\\nonumber\\v^2\ =&\ \frac{d^2g}{h\cos2\theta\ +\ h\ +\ d\sin2\theta}\end{align}}</script></p></p>
<p>We're pretty much done here, just need to take the square root and integrate it into code.<a id="solution">&nbsp;</a></p>
<h2>Solution</h2>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_f2b153bc5b92a5f27d22dbe215a5298a.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align}v\ =\ \sqrt{\frac{d^2g}{h\cos2\theta\ +\ h\ +\ d\sin2\theta}}\end{align}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align}v\ =\ \sqrt{\frac{d^2g}{h\cos2\theta\ +\ h\ +\ d\sin2\theta}}\end{align}}</script></p></p>
<h3>Where:</h3>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://blog.codersplayground.net/wp-content/plugins/latex/cache/tex_11492f212729af08ee01e744d561538f.gif' style='vertical-align: middle; border: none;' class='tex' alt="\Large{\begin{align*}g\ &=\ 9.81\ \text{(or whatever your gravity is)}\\h\ &=\ y\ -\ y\prime\\d\ &=\ x\prime\ -\ x\end{align*}\\\arctan(\tfrac{h}{d})\quad<\quad\theta\quad<\quad\frac{\pi}{2}}" /></span><script type='math/tex;  mode=display'>\Large{\begin{align*}g\ &=\ 9.81\ \text{(or whatever your gravity is)}\\h\ &=\ y\ -\ y\prime\\d\ &=\ x\prime\ -\ x\end{align*}\\\arctan(\tfrac{h}{d})\quad<\quad\theta\quad<\quad\frac{\pi}{2}}</script></p></p>
<h2>Putting it into Code</h2>
<p>Coding it is pretty straight forward, below is an example function that I wrote to handle doing the mathematics of finding the velocity.</p>
<pre class="brush:c#; highlight:13; toolbar:false;">// This function determines the required velocity to reach the range at the given height and angle
private float DoTheMath(float distance, float height, float doubAngle)
{
    // The lowest angle is a direct shot at an infinite velocity
    float lowestAngle = Mathf.Atan2(height, distance) * 2;
    
    // If the angle doesn't fall within the (lowestPossible, 90) range, there is no solution
    if (doubAngle >= Mathf.PI || doubAngle <= -lowestAngle) {
        return 0;
    }
    
    // I figured this equation out after working through the standard physics equations. See: http://wp.me/p35fKy-4k
    return Mathf.Sqrt((9.81f * distance * distance) / (height * Mathf.Cos(doubAngle) + height + distance * Mathf.Sin(doubAngle)));
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2013/coding/math-science/finding-initial-velocity-given-angle-and-distance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Thing About Raycasts</title>
		<link>http://blog.codersplayground.net/2013/general-information/the-thing-about-raycasts/</link>
		<comments>http://blog.codersplayground.net/2013/general-information/the-thing-about-raycasts/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 02:29:59 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[General Information]]></category>
		<category><![CDATA[Math & Science]]></category>
		<category><![CDATA[Napkin Western]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Physics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Raycast]]></category>
		<category><![CDATA[Raycasting]]></category>

		<guid isPermaLink="false">http://blog.codersplayground.net/?p=262</guid>
		<description><![CDATA[Raycasts are expensive, or so we are told, but just how expensive are they? This post, at a basic level, covers what exactly they do, and how are they used regularly.]]></description>
				<content:encoded><![CDATA[<p>Raycasts are extremely versatile. With raycasts you can see if there is something under the mouse, in the path of a straight shooting object, or just about anything else regarding something being in the path of something else. As far as calculations go, raycasts are probably one of the most expensive (in terms of computational time) things that you can do. But how expensive are they? Well, let's put things into perspective about just how expensive raycasts are. We'll look at the basics of raycasting and how it is used with great frequency in  a standard setting.</p>
<h2>Raycast Basics</h2>
<p>What exactly is a raycast, how does it work, why is it so expensive? A raycast has an origin and a direction, like any vector, and is literally cast, or thrown if you will, into the scene. The process basically involves going through every object, then checking ever vertex, face, and edge, for an intersection. Even with rigorous optimization this can be checking against hundreds of elements, and this is what makes it computationally expensive.</p>
<h2>How it's Used</h2>
<p>While it is relatively expensive, it is exactly how the scene is rendered. On my desktop that means 1680 x 1050 = 1,764,000 raycasts per frame just to display what is going on. On my tablet it's 1920 x 1200 = 2,304,000 raycasts per frame and 960 x 540 = 518,400 for my phone. So while it is an expensive calculation, remember that it is happening half a million to two million times a frame just to render, so doing it another 30 or so times is no worse than a 6 x 5 grid of extra pixels.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2013/general-information/the-thing-about-raycasts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity Android Key Mappings</title>
		<link>http://blog.codersplayground.net/2013/general-information/unity-android-key-mappings/</link>
		<comments>http://blog.codersplayground.net/2013/general-information/unity-android-key-mappings/#comments</comments>
		<pubDate>Mon, 25 Feb 2013 02:56:37 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[General Information]]></category>
		<category><![CDATA[Napkin Western]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Key Codes]]></category>
		<category><![CDATA[Mapping]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.codersplayground.net/?p=259</guid>
		<description><![CDATA[Android devices have a number of physical or partially physical buttons. These and other inputs actually map to keyboard and mouse events for convenience. Here is a list of the mappings.]]></description>
				<content:encoded><![CDATA[<p>If you are using Unity to develop for Android platforms, you may be wondering what keys the different buttons map to. I happened to find the answer in a location unrelated to Unity, but the information is still valid. In order to make touch devices generally compatible, touch and key inputs are directly mapped to mouse and keyboard buttons respectively. Below is a short table snagged from a <a href="https://groups.google.com/forum/?fromgroups=#!topic/android-x86/uM5WQnEWqys">Google Group</a></p>
<ul>
<li>One finger tap = left mouse button</li>
<li>Two finger tap = right mouse button</li>
<li>Menu key =
<ul>
<li>Middle mouse</li>
<li>Windows key</li>
</ul>
</li>
<li>Home button = HOME key</li>
<li>Back button = ESC key</li>
<li>Power button = END key</li>
</ul>
<h2>Note:</h2>
<p>After testing with my tablet, I could not confirm any other keys besides the back button. The menu key did not even show up.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2013/general-information/unity-android-key-mappings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Importance of Humor</title>
		<link>http://blog.codersplayground.net/2013/general-information/the-importance-of-humor/</link>
		<comments>http://blog.codersplayground.net/2013/general-information/the-importance-of-humor/#comments</comments>
		<pubDate>Mon, 11 Feb 2013 15:11:07 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[General Information]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://blog.rplantedesigns.com/?p=249</guid>
		<description><![CDATA[It is important to maintain a sense of humor while working. Not only will things be more bearable, but your positive attitude will cause you to run into fewer problems.]]></description>
				<content:encoded><![CDATA[<p>Many people say that having a good sense of humor is beneficial. This is the case with coding as well. Having a good sense of humor will make your code more readable as it will provide a little chuckle here and there, as well as keep you in a good mood. Working while happier is a great way to avoid lots of little errors. Not only that but, since you are in a good mood, you will be less tempted to distraction making you more efficient. Who doesn't want to complete "8 hours of work" in 5 or 6? Below is a little snippet of some good humor that I put in my code that may or may not be funny, but is of non-detrimental nature, and gave me a bit of a smile.</p>
<div id="attachment_250" class="wp-caption aligncenter" style="width: 336px"><a href="http://blog.codersplayground.net/wp-content/uploads/2013/02/2-11-2013-0000.png"><img src="http://blog.codersplayground.net/wp-content/uploads/2013/02/2-11-2013-0000.png" alt="Coding Humor" width="326" height="55" class="size-full wp-image-250" /></a><p class="wp-caption-text">Why yes, public health is important.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2013/general-information/the-importance-of-humor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Particular Problems with Public Variables in Unity</title>
		<link>http://blog.codersplayground.net/2013/coding/particular-problems-with-public-variables-in-unity/</link>
		<comments>http://blog.codersplayground.net/2013/coding/particular-problems-with-public-variables-in-unity/#comments</comments>
		<pubDate>Sat, 26 Jan 2013 22:06:00 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Napkin Western]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[Access Modifiers]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Fixes]]></category>
		<category><![CDATA[Good Practice]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[Inspector]]></category>
		<category><![CDATA[Know-How]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Variables]]></category>

		<guid isPermaLink="false">http://blog.rplantedesigns.com/?p=237</guid>
		<description><![CDATA[In the <a href="http://docs.unity3d.com/Documentation/Manual/Scripting.html">Unity documentation</a> it is indicated that all public variables are made available in the inspector for direct editing. While this is handy, it is also dangerous. This article will cover a few things regarding public variables, and also how to avoid them in Unity.]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://docs.unity3d.com/Documentation/Manual/Scripting.html">Unity documentation</a> it indicates that all public variables are made available in the inspector for direct editing. While this is handy, it is also dangerous. This article will cover a few things regarding public variables, and how to avoid them in Unity.</p>
<p><span id="more-237"></span></p>
<h1>Public Variables</h1>
<p>In a <a href="http://blog.rplantedesigns.com/2013/coding/the-importance-of-class-and-object-oriented-programming/">earlier post</a> I made mention of public variables, specifically in a class-based architecture. One of the dangers of public variables is that <em>anything</em> can change their value. When testing Napkin Western (working title) on a tablet, some of the variables were corrupted from the values set in the Inspector. The values changed from 6 and 15 to 2.435e-43 and 2.643e-45 respectively.</p>
<h1>Solution</h1>
<p>What's the solution? Simple, set the access to all your variables, functions, enums, etc. to exactly what they should be. Make only variables public that absolutely need to be. Then take advantage of the <a href="http://docs.unity3d.com/Documentation/ScriptReference/HideInInspector.html"><code>[HideInInspector]</code></a> to keep certain public variables hidden, and <a href="http://docs.unity3d.com/Documentation/ScriptReference/SerializeField.html"><code>[SerializeField]</code></a> to show hidden or private variables. This way things won't get accidentally modified, and you will have access to all the pieces you need while retaining the proper level of access.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2013/coding/particular-problems-with-public-variables-in-unity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avoiding Long Compile Times</title>
		<link>http://blog.codersplayground.net/2013/coding/avoiding-long-compile-times/</link>
		<comments>http://blog.codersplayground.net/2013/coding/avoiding-long-compile-times/#comments</comments>
		<pubDate>Fri, 18 Jan 2013 23:31:00 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Napkin Western]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Compile]]></category>
		<category><![CDATA[Compiling]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Problem Solving]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Shaders]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://blog.rplantedesigns.com/?p=233</guid>
		<description><![CDATA[Compile times can be a major hindrance, especially when you just need to figure out why one little thing isn't working. This article will help you to avoid those long compile times as much as possible.]]></description>
				<content:encoded><![CDATA[<p>Long compile times are a real chore when it comes to testing things. It is especially cumbersome when all you are doing is making small edits resulting in 2 seconds worth of editing, and 2 minutes waiting for compiling.</p>
<p><span id="more-233"></span></p>
<h1>Problem</h1>
<p>One place where this is particularly the case is shader debugging. This is the actual problem that prompted me to find such a solution. Being a Unity project for mobile devices, Napkin Western must be tested on its target platform, from time to time. In this particular instance, my nifty hand-crafted shader specifically took issue with the mobile device for no apparent reason. Since compiling for the platform takes a fair amount of time, and all I needed to do was make minor changes to find the issue, I had to come up with another solution.</p>
<h1>Solution</h1>
<p>The solution? Make 6 different versions of the shader; yes, 6. Each version had one thing to test within its code. That way I could independently verify each of 6 different components to see if any of them were the cause of the problem without having to compile the game 6 times. Then I loaded in some spheres and gave each one a different version of the shader.</p>
<h1>Result</h1>
<p>So, what ended up being the problem with my awesome custom toon/cel shader? Oddly enough, nothing you would expect. It ended up being the fact that I tried to condense my code by using a ternary instead of an expanded if/else statement. I never caught this because it worked fine during the standard visual tests yet, for some odd reason, when testing on the various available Android devices, it resulted in an all black shader effectively always evaluating the ternary to false.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2013/coding/avoiding-long-compile-times/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Importance of Class and Object Oriented Programming</title>
		<link>http://blog.codersplayground.net/2013/coding/the-importance-of-class-and-object-oriented-programming/</link>
		<comments>http://blog.codersplayground.net/2013/coding/the-importance-of-class-and-object-oriented-programming/#comments</comments>
		<pubDate>Tue, 15 Jan 2013 13:24:00 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Good Practice]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[Know-How]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Object Oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Professional Code]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.rplantedesigns.com/?p=142</guid>
		<description><![CDATA[Object Oriented Programming (OOP) is one of the most useful high level concepts that a programmer can know. This article looks to give a short introduction into what it is, and how to use it.]]></description>
				<content:encoded><![CDATA[<p>While class is certainly important to have in real life, it is equally important to have while programming. Taking advantage of an Object Oriented Programming method (or OOP method) may very well be one of the most important higher concepts to learn and understand. This article helps cover what OOP is, its benefits, and how to use it.</p>
<p><span id="more-142"></span></p>
<h1>What are objects?</h1>
<p>In the real world each thing, or object, acts independently of everything else with no interconnected reliance. Objects can <em>react</em> to other objects, but do not necessarily <em>depend</em> on other objects. Note: there are objects which are entirely dependent on other objects, but we'll get to that. If you have just started programming you likely will have noticed that the program as a whole runs in a very linear fashion with events occurring in a very specific order. To get around this many programming languages have implemented a class based architecture. Even Objective-C has structs which function in a similar manner.</p>
<h1>What is a class?</h1>
<p>What is a class exactly? Succinctly, a class is whatever you want it to be. At its most basic level, a class is an object that you define yourself. What a class does is entirely up to you, but you will want to put some thought into constructing it to make sure it behaves as you intended. Classes allow you to group functions, variables, and even other classes into one contained object that does not interfere with other objects.</p>
<h1>Interaction principles</h1>
<p>Does not interfere? What if it needs to? Well, that's where access identifiers come in. They let you determine what can access the particular variable/function. There are three main access modifiers, and one that is less well known. The three main modifiers are (ordered by access level): <code>
<ul>
<li>Public</li>
<li>Protected</li>
<li>Private</li>
</ul>
<p></code> The last modifier is <code>internal</code>, it is not very well known, and has limited to no use in smaller projects and therefore will only be covered briefly.</p>
<h1><code>Public</code> Access</h1>
<p>First is the <code>public</code> access modifier. <code>Public</code> variables, functions, classes, etc. Can be accessed and modified by anything and everything. Some will say that one should never have public data, and others will say to use it with extreme caution. I fall in the latter camp personally. Ideally you only ever want to have a variable <code>public</code> if you want it to be modified by an external process, otherwise it is better to have it be a <code>protected</code> or <code>private</code> variable and then define a public function that allows the data to be read by other processes. To some this does seem much, but it all depends on your security needs, and whether or not you are the only one who will ever work on the project. A good rule of thumb is, "if you do not want it modified by just about anything, don't make it <code>public</code>." One exception is in Unity where a variable must be public in order to allow modification of said variable within the inspector tab(s).</p>
<h1><code>Protected</code> Access</h1>
<p><code>Protected</code> methods can be accessed by the class they are defined in, as well as any other class that is built on top of the class. This brings us to the topic of inheritance, which will be covered briefly before moving on to the <code>private</code> and <code>internal</code> definitions.</p>
<h1>Inheritance</h1>
<p>To better understand inheritance we need to look at a real world example. Chances are you know what a car is, what it does, and generally how to use one. Most cars function the same, but yet are very different. One main difference is Manual vs. Automatic transmission. Aside from that there are sports cars, luxury cars, commercial vehicles, and many many more. Yet these are all cars, and they all have many things in common: wheels, brakes, an engine, the need for gasoline, a battery, drive shaft, steering wheel, lights, horn, and on and on. To represent this in programming you would create a car class, then you would probably make several other classes based on these for the different vehicle types. To do this you would use the <code>extends</code> keyword followed the class which this class is to be based upon. This new class will have access to absolutely everything that its parent has access too, except <code>private</code> members. As mentioned above, <code>protected</code> members can be accessed only by a class and its sub-classes.</p>
<h1><code>Private</code> Accesss</h1>
<p>This brings us to the last of the three main access modifiers: <code>private</code>. The <code>private</code> modifier lets the defined method only be accessed by the class itself, and absolutely nothing else, not even derived classes. Taking the real-world car example, the basic car class would probably define how the engine works to produce thrust, but any sub-class would simply access the <code>accelerate</code> function instead of directly modifying the various engine components required to make acceleration happen. Thus, opening the valves, controlling airflow, fuel injection, ignition sequence, and exhaust are <code>private</code>, and for good reason too. Imagine having to control all of that every single time you wanted one of the cars to accelerate, instead of just pushing a handy little pedal.</p>
<h1><code>Internal</code> Access</h1>
<p>The <code>internal</code> modifier is not very well known because it limits access to the assembled package. This means that only this program, and no other program, can access the method. This can be handy if you are building a DLL file and want certain methods public within the DLL, but not available outside of its local program scope. Reading that definition may make you wonder why internal is needed at all since most everything is limited by its scope. The key thing here is classes. In particular you want a class accessible within a DLL for instantiation, but not available outside of it because the name it uses might clash with something else, or because it is a security concern. As aforementioned, this modifier is used very little in smaller projects.</p>
<h1>Construction Tips</h1>
<p>"That's all well and good," you might say, "but how do I actually <em>use</em> classes in my workflow?" There are a few things to keep in mind when constructing a class, and it can help to diagram out what is to do what well ahead of actually implementing anything. This will prevent you from having to come back and restructure the class an untold number of times.</p>
<h2>Instantiation</h2>
<p>Classes typically require a public function of the same name as the class which acts as the instantiation method. What this means is that when you define "<code>ClassName obj = new ClassName(a, b, c);</code>" the parameters listed by your favorite IDE are pulled from the function with the same name as the class you are creating, which in this case is <code>ClassName</code>. It is possible, at least in every language I have encountered besides Objective-C, to have multiple, or overloaded, functions with the class name. This will allow for different ways to create the object depending on the circumstances and the amount of information actually required.</p>
<h2>Update</h2>
<p>In many cases it is also beneficial to have at least one commonly named update function whose function name exists in all necessary classes to provide a simple means of running standard loop logic. That way in the main body of the program you could just iterate through all objects and call their update functions, if they exist.</p>
<h2>Input</h2>
<p>Likewise it is a good idea to come up with a naming convention for various types of input. Windows allows you to register a listener function for keyboard, mouse, and other input. Within the function it would be very easy to call the respective listener functions of everything in your program if they all had similarly named listener functions.</p>
<h1>Final thoughts</h1>
<p>Ultimately classes are the best way to have a modular system, and there are very few applications that could not benefit from such an approach. I strongly suggest reading more about classes and the OOP method for your respective programming language. It can only help.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2013/coding/the-importance-of-class-and-object-oriented-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Update</title>
		<link>http://blog.codersplayground.net/2012/general-information/quick-update/</link>
		<comments>http://blog.codersplayground.net/2012/general-information/quick-update/#comments</comments>
		<pubDate>Sat, 24 Nov 2012 06:39:19 +0000</pubDate>
		<dc:creator>Robert Plante</dc:creator>
				<category><![CDATA[General Information]]></category>

		<guid isPermaLink="false">http://blog.rplantedesigns.com/?p=211</guid>
		<description><![CDATA[I haven't had time to make any posts this week for a number of reasons, but I plan to resume next week with a series on Object Oriented Programming as well as what Aspect Oriented Programming means.]]></description>
				<content:encoded><![CDATA[<p>I haven't had time to make any posts this week for a number of reasons, but I plan to resume next week with a series on Object Oriented Programming as well as what Aspect Oriented Programming means.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codersplayground.net/2012/general-information/quick-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
