<?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>DevLog &#187; algorithms</title>
	<atom:link href="http://82.30.70.163/BlueThen/wordpress/tag/algorithms/feed/" rel="self" type="application/rss+xml" />
	<link>http://82.30.70.163/BlueThen/wordpress</link>
	<description></description>
	<lastBuildDate>Mon, 06 Sep 2010 15:24:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Cursor Glove, Day 11, and 12</title>
		<link>http://82.30.70.163/BlueThen/wordpress/2010/01/cursor-glove-day-11-and-12/</link>
		<comments>http://82.30.70.163/BlueThen/wordpress/2010/01/cursor-glove-day-11-and-12/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 03:07:37 +0000</pubDate>
		<dc:creator>BlueThen</dc:creator>
				<category><![CDATA[Chase Engine]]></category>
		<category><![CDATA[Dev Log]]></category>
		<category><![CDATA[Glove Cursor]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[cam]]></category>
		<category><![CDATA[Chase]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[glove]]></category>
		<category><![CDATA[interactive]]></category>
		<category><![CDATA[johnny]]></category>
		<category><![CDATA[lee]]></category>
		<category><![CDATA[lens]]></category>
		<category><![CDATA[pointer]]></category>
		<category><![CDATA[sunglass]]></category>
		<category><![CDATA[sunglasses]]></category>
		<category><![CDATA[transformations]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://82.30.70.163/BlueThen/BlueThen/wordpress/?p=198</guid>
		<description><![CDATA[On Sunday of last week, I had a pretty neat idea. I was looking around the internet, and ran into some sort of gaming glove. I thought &#8220;Hey! That&#8217;s pretty cool.&#8221; I had something different in mind, and found that this glove didn&#8217;t have the capabilities I&#8217;d hope for. I was thinking of something like [...]]]></description>
			<content:encoded><![CDATA[<p><a href="/BlueThen/wordpress/wp-content/uploads/2010/01/DSC00272.jpg"><img src="/BlueThen/wordpress/wp-content/uploads/2010/01/DSC00272-300x224.jpg" alt="" title="DSC00272" width="300" height="224" class="alignleft size-medium wp-image-206" /></a>
<p style="text-indent:20pt; line-height:20pt;">On Sunday of last week, I had a pretty neat idea. I was looking around the internet, and ran into some sort of <a href="http://www.engadget.com/2009/12/18/peregrine-gaming-glove-modeled-calibrated-and-demoed-on-video/">gaming glove</a>. I thought &#8220;Hey! That&#8217;s pretty cool.&#8221; I had something different in mind, and found that this glove didn&#8217;t have the capabilities I&#8217;d hope for. I was thinking of something like a <a href="http://kernelreloaded.blog385.com/sadrzaj/wiimote.jpg">wiimote</a> but in the form of a glove.</p>
<p style="text-indent:20pt; line-height:20pt;">I remembered seeing <a href="http://www.youtube.com/user/jcl5m">Johnny Lee&#8217;s videos</a> of his <a href="http://johnnylee.net/projects/wii/">wiimote hacks</a>. He set up his wiimote to receive input from external infrared lights, and to track it while doing several neat things like <a href="http://www.youtube.com/watch?v=Jd3-eiid-Uw">head-tracking</a> or a <a href="http://www.youtube.com/watch?v=5s5EvhHy7eQ">multi-touch projector white-board</a>. This was all very impressive, considering he was using very cheap supplies to accomplish these things. He also made a <a href="http://www.youtube.com/watch?v=0awjPUkBXOU">finger-tracker using an infrared light array (grid of lights), and some reflectors taped onto his fingers</a>. I eventually came to the idea of using an IR light with the webcam. I understood that cameras have a tendency of picking up infrared lights, unlike our human eyes. I grabbed a TV remote, wrote a quick script, and it worked greatly!</p>
<p><span id="more-198"></span></p>
<p style="text-indent:20pt; line-height:20pt;">I went to Radio Shack that evening, picked up an IR light, a battery holder, and a button. I then went to Lowes and got a pair of gardener gloves. When I got home, I taped it all together using some electrical tape, ran the script, and it worked beautifully. The glove wasn&#8217;t perfect yet though. The algorithm takes all the pixels the webcam inputs, finds the brightest ones, then averages them and use that. I actually discovered that sunglass lenses blocks visible light from entering, but NOT infrared light, which was extremely convenient on my part. I popped the 2 lenses out of the glasses, taped them together, and made a little holder so it can slide onto the webcam. This also helped reduce glare, which is another cause of some error in accuracy. Another fall-back was the jitterness that occurs naturally in your hands, and the wide range of brightnesses the infrared light can give off when angled differently. Fixing this was simple, simply load all the calculated positions into an array of 5, 10, or however much and average those out to significantly smooth the cursor.</p>
<p style="text-indent:20pt;">Hopefully I&#8217;ll be able to work on from that. Add another infrared light and add some sort of &#8220;multi-touch&#8221; capabilities, or maybe even attempt something like a virtual tablet, using the same methods as Johnny Lee&#8217;s white-board. The possibilities are endless. Below is a gallery of a bunch of different high-res images involving the cursor glove.</p>
<p style="text-indent:20pt; line-height:20pt;">This doesn&#8217;t mean I&#8217;m letting go of Chase, however. I&#8217;m working on it as much as I can. I worked on it again, and got even closer to a working graphics engine. I&#8217;m currently creating a Scene datatype. It&#8217;ll act much like Adobe Flash Professional&#8217;s scene, but in programming. In my engine, you&#8217;ll plot different models and polygons in a 3D or 2D space in the scene. All 3D coordinates are rendered, but 2D coordinates are kept the same. Using a scene class will make it easy for the developer to rotate, translate, dilate, or do whatever globally to all the coordinates being displayed. </p>
<p style="text-indent:20pt; line-height:20pt;">I got rid of all of the transformation functions (translate, dilate, etc), since they&#8217;re already existent inside Coordinate and Polygon&#8217;s class. Hopefully I can get the Scene class to work pretty soon here, so I can proceed to start adding actual new features and tools to the engine.</p>
<p style="text-indent:20pt; line-height:20pt;">Below is a library of pictures of the cursor glove and webcam filter made out of sunglass lenses:</p>

 <img src="http://82.30.70.163/BlueThen/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=198" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://82.30.70.163/BlueThen/wordpress/2010/01/cursor-glove-day-11-and-12/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Chase</title>
		<link>http://82.30.70.163/BlueThen/wordpress/2009/12/chase/</link>
		<comments>http://82.30.70.163/BlueThen/wordpress/2009/12/chase/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 04:42:24 +0000</pubDate>
		<dc:creator>BlueThen</dc:creator>
				<category><![CDATA[Chase Engine]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[Chase]]></category>
		<category><![CDATA[formulas]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[isometric]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[mirc]]></category>
		<category><![CDATA[msl]]></category>
		<category><![CDATA[particles]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[program]]></category>

		<guid isPermaLink="false">http://bluethen.wordpress.com/?p=37</guid>
		<description><![CDATA[I&#8217;ve been working on a game for a little under a month (ever since November 21st). It started out as an idea several months earlier, in which I proceeded to work on in mSL.  I got a  wireframe isometric engine made and running fairly nice (roughly 40 fps, which was godly for such a slow language). I had [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a game for a little under a month (ever since November 21st). It started out as an idea several months earlier, in which I proceeded to work on in mSL.  I got a  wireframe isometric engine made and running fairly nice (roughly 40 fps, which was godly for such a slow language). I had some problems with mSL, however. Resources played too large of a factor, and involved having to use every little hack I could come up with to speed it up. I was literally optimizing it to the very byte. That would&#8217;ve been fine for a simple game, but I had bigger plans for my game.</p>
<p><span id="more-37"></span></p>
<p>I didn&#8217;t really want my game to be wireframe. It didn&#8217;t seem very ideal to me.  So I scripted up a simple hidden line removal algorithm, where lines being overlapped by polygons wouldn&#8217;t be displayed. mSL didn&#8217;t provide support for drawing custom polygons, and making a loop to draw each individual pixel of one would be way too slow. I went over every solution I could come up with, like storing different values that would be used in some of the frames. But I&#8217;d always run into one problem or another.</p>
<p>So I gave up on the idea all together. Later, I moved on to Processing. I made a couple of experimental apps, some being duplicates of previous scripts in mSL, and released them on<a title="BlueThen's profile on OpenProcessing" href="http://www.openprocessing.org/portal/?userID=3044"> OpenProcessing</a>. After getting a feel for the language, I started to revisit the idea of the game I wanted to make. The idea of it kept coming back to me. In my mind, it seemed completely revolutionary. Concepts that are used very little, if at all, in main stream games.</p>
<p>I love isometric rendering. Something about the diagonal lines grabs my attention, and stimulates interest into the media. Photographers and artists would tell you that diagonal lines shows action, depth, and stimulation. They convey feelings of movement, and tend to lead your eyes throughout the piece.</p>
<p>Another reason I was interested in isometric rendering was the ease of use. All that&#8217;s required is a simple formula to plug the xyz coordinates, and you&#8217;re done. No rotations, matrixes, or whatever is really required. Just a basic knowledge of 3 dimensional Cartesian coordinates.</p>
<p><a href="http://bluethen.files.wordpress.com/2009/12/isometric.gif"><img class="size-full wp-image-38 alignright" title="isometric" src="http://bluethen.files.wordpress.com/2009/12/isometric.gif" alt="" width="292" height="261" /></a></p>
<p>I began using an isometric formula I came across a number of months ago.<br />
onScreenX = (x &#8211; z) * cos(radians(30)) + width/2<br />
onScreenY = (x + z) * sin(radians(30)) &#8211; y + height/2<br />
Assentially, adding width/2 to the x, and height/2 to the y, moves the point of origin (0,0) to the center of the window. I later came across the translate() function in Processing, which allowed me to do just that: translate(width/2,height/2);<br />
onScreenX = (x &#8211; z) * cos(radians(30))<br />
onScreenY = (x + z) * sin(radians(30)) &#8211; y</p>
<p>When multiplying anything by cosine and sine, the radius of an ellipse is created. (x-z) determines the width of the ellipse, and (x+z) is the height. The x-coordinate is then calculated to be 30 degrees counter clockwise from the x axis, and the z-coordinate is calculated 30 degrees clockwise from the x axis.</p>
<p><a href="http://bluethen.files.wordpress.com/2009/12/pixels.gif"><img class="alignleft size-full wp-image-39" title="pixels" src="http://bluethen.files.wordpress.com/2009/12/pixels.gif" alt="" width="100" height="70" /></a>I was suggested to later on to use something like 33 degrees instead. Ideally to line it up so that the pixels aren&#8217;t abnormally lined up when drawn directly along the x or z axis. Instead of having 2 dots sideways, then one up, then 3 side, or whatever, it&#8217;d be a clean 2 dots to the side, then 2 dots vertical from that. I never adopted the idea, since none of my scripts ever heavily involved lines parallel to the x or z axis.</p>
<p>The isometric formula was an essential part of all my algorithms. It&#8217;d be used hundreds of thousands of times, for each coordinate involves this calculation. I later decided that it&#8217;d be a good idea to optimize it. Knowing that I&#8217;ll always be using 30 degrees for my isometric formulas, I precalculated that accordingly. 30 degrees in radians is 0.523598776,  cosine of that is roughly 0.866, and sin of our radians is conveniently 0.5.</p>
<p>Later, I rounded the 0.866 to 1. Rounding it that much seemed like it&#8217;d have a significant effect, and it sort of did. It was, however, only noticeable when placed side by side, or immediately compared, to an accurate rendering. The inaccurate rendering only appeared to be a slightly wider scaled version of the accurate rendering.  I ended up with an extremely simple formula:<br />
onScreenX = x &#8211; z<br />
onScreenY = (x + z)/2 &#8211; y</p>
<p>This, I planned to be the main component of the Chase Engine. Chase Engine is essentially going to be the name of the collective algorithms, functions, and classes in my game. I plan to make the graphical engine vector-based. Most isometric/dimetric/trimetric games are bitmap based, where images are used for every angle of every object.</p>
<p>I will render models polygon by polygon, just as if I were doing everything as if it were truely 3D. Textures would probably not be used, and if they are, they&#8217;d be procedural just as well as the rendering.</p>
<p>The isometric formula is the simple part of my game. Other, more complex and brain-tumor-inducing, things will be involved. They will involve my collective knowledge of everything I know about mathematics, programming, graphical algorithms, and plus some. I&#8217;ve thought about it for hours on end,  getting every basic concept ironed out. I knew my game inside and out before I even started, or so I assumed.</p>
<p>I started on November 21st, 2009. I&#8217;ve been dedicating entire days to the game. No less than 3 hours at a time, if you don&#8217;t count the brief breaks I take frequently to keep a fresh mind. The first thing I&#8217;ve accomplished was simple rendering. Functions that&#8217;d draw different shapes and lines in the isometric space. I then added a rough draft of the vehicle class, and of the environment class. The environment class was simply a place-holder, to test the vehicle class. In the vehicle class, featured a simple algorithm for calculating the y position of the vehicle&#8217;s corners, as they act as springs according to the wheels. This was to simulate suspension.</p>
<p>By day 2, November 22nd, I already had about 402 lines of code.  I created a model class and a function for reading files. I then wrote an algorithm to take on screen coordinates and convert them to isometric coordinates.</p>
<p>On day 3, or November 25th, the line count was cut down to 342, and the file reader was turned into a model importer. The model importer took in coordinates from a file, and loaded them into a 3D model class. I was lacking a z-buffer at that time.</p>
<p><a href="http://bluethen.files.wordpress.com/2009/12/suspensions.gif"><img class="alignright size-medium wp-image-48" title="suspensions" src="http://bluethen.files.wordpress.com/2009/12/suspensions.gif?w=288" alt="" width="288" height="300" /></a>I got a basic Scene buffer going by December 6th, 2009. There was no z-buffering yet. I also recreated the suspension algorithm for vehicles. This one was a little more dynamic, since it allowed me to change the mass, dampening, and other values with ease.</p>
<p>The algorithm I came up with for suspension was</p>
<p>newRest = rest + min ; The resting y position, is determined by a preset rest coordinate + min, or the tire&#8217;s y coordinate. This allows the resting coordinate to change as the wheel coordinate changes.</p>
<div id="_mcePaste">velocity += 0.2 * (newRest &#8211; yPos) &#8211; mass ; The velocity is adjusted. The y position of the car is subtracted from the new resting coordinate. This finds the distance between the vehicle and the resting position. It&#8217;s then multiplied by 0.2 so it the velocity isn&#8217;t significant, and mass is subtracted to simulate gravity.</div>
<div id="_mcePaste">velocity *= dampening ; velocity is multiplied by dampening (which is less than 1), to simulate friction.</div>
<div id="_mcePaste">yPos += velocity ; velocity is added to the y position.</div>
<div id="_mcePaste">constrain(yPos, newMin, maxHeight+newMin) ; the y position is constrained to withing the minimum and maximum heights.</div>
<div></div>
<div>On the 5th day, today, December 12th, 2009, I finally made a working zbuffer. I&#8217;ve probably spent over 10 hours trying to get a working zbuffer. My main problem was the syntax. The logic seemed simple. Simply sort the polygons according to their values.  sort(polygons), right? Wrong!</div>
<div></div>
<div>The sort() function doesn&#8217;t support objects, and arrays are often a pain. I eventually came across a pretty simple way of getting around this. Using comparables for sorting the objects. So I went ahead and created a polygon class for storing all the coordinates in, creating a large array of that for the buffer, then sorting it using comparable. It ended up technically being xyzBuffering, since x, y, and z are all playing a factor in the buffer. In an isometric rendering, the camera is simply at (1,1,1) pointed towards (0,0,0), so I added together the mean (average) x, y, and z of a coordinate to represent it&#8217;s depth.</p>
<div>without zbuffering (CLICK):</div>
</div>
<div><a href="http://bluethen.files.wordpress.com/2009/12/withoutzbuffer.gif"><img class="alignnone size-thumbnail wp-image-33" style="border:0 initial initial;" title="withoutZBuffer" src="http://bluethen.files.wordpress.com/2009/12/withoutzbuffer.gif?w=150" alt="" width="150" height="150" /></a></div>
<div><a href="http://bluethen.files.wordpress.com/2009/12/withoutzbuffer.gif"></a></div>
<div>With zbuffering (CLICK):</div>
<div><a href="http://bluethen.files.wordpress.com/2009/12/withzbuffer1.gif"><img class="alignnone size-thumbnail wp-image-35" title="withZBuffer" src="http://bluethen.files.wordpress.com/2009/12/withzbuffer1.gif?w=150" alt="" width="150" height="150" /></a></div>
<div></div>
<div></div>
<div></div>
<div>I have a lot more planned for the game. It&#8217;ll probably take me months, if not one or two years, to complete. I&#8217;m willing to take however long to make the game though. I will not give up, even if it takes me 10+ hours to complete a simple function, or 3+ days to get a formula to work.</div>
<div>

</div>
 <img src="http://82.30.70.163/BlueThen/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=37" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://82.30.70.163/BlueThen/wordpress/2009/12/chase/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
