<?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>HiddenTao &#187; 3D</title>
	<atom:link href="http://www.hiddentao.com/archives/tag/3d/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hiddentao.com</link>
	<description>software, websites, mobile, technology</description>
	<lastBuildDate>Mon, 30 Aug 2010 21:08:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>3D demo</title>
		<link>http://www.hiddentao.com/archives/2010/01/20/3d-demo/</link>
		<comments>http://www.hiddentao.com/archives/2010/01/20/3d-demo/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 12:23:24 +0000</pubDate>
		<dc:creator>ram</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.hiddentao.com/?p=726</guid>
		<description><![CDATA[A while back I decided to write a simple 3D graphics engine in Java after being inspired by Daniel Tebbutt&#8217;s Bedlam solver. Essentially I wanted to show a cube like his but with the added ability to split it apart so that you could see how the pieces fit together. As I got going with [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I decided to write a simple 3D graphics engine in Java after being inspired by <a href="http://danieltebbutt.com/bedlam.html" class="link-external">Daniel Tebbutt&#8217;s Bedlam solver</a>. Essentially I wanted to show a cube like his but with the added ability to split it apart so that you could see how the pieces fit together. As I got going with this I was enjoying it so much I put aside the puzzle algorithm and just started adding more 3D rendering features.</p>

<p>Fast forward many hours of coding and here is a simple demo (click the image to launch it):
<span id="more-726"></span></p>

<p><a href="#" class="imglink" title="Launch demo (requires Java 1.5+)" onclick="window.open('http://www.hiddentao.com/downloads/kai/applet.html','_blank','status=0,toolbar=0,location=0,menubar=0,scrollbars=0,directories=0,resizable=0,width=670,height=500')">
<img src="http://farm3.static.flickr.com/2770/4289736971_b0f35bc880.jpg" />
</a></p>

<p><em>The demo consists of 3 separate scenes. You can switch between by simply clicking in the window. Further mouse and keyboard controls are listed in the demo window itself. Debug output from the demo is viewable in the Java applet console</em></p>

<p><strong>Architecture</strong></p>

<p>I&#8217;ve tried to use good object-oriented programming as much as possible throughout. For example, each scene is represented as a hierarchical scenegraph and a <a href="http://en.wikipedia.org/wiki/Visitor_pattern" rel="nofollow" class="liwikipedia">Visitor</a> model to perform rendering. The renderer itself is obtained from a <a href="http://en.wikipedia.org/wiki/Factory_pattern" rel="nofollow" class="liwikipedia">Factory</a> which allows for different types of renderers (OpenGL, DirectX, Software, etc.). As is standard practice with scenegraphs, a matrix stack is used to allow for model-level transformations independent to world-level transformations.</p>

<p>At the moment the only available renderer is software-based. But the architecture allows for OpenGL or DirectX-based rendering to be added in future. I use the <code>Graphics2D.drawLine()</code> API call in Java to render the pixels. Everything else (e.g. z-buffer) is manually implemented. The engine supports wireframe-mode rendering and backface culling. There is a single source light in the scene whose direction can be modified (in the demo it&#8217;s always pointing forwards from the camera). The rasterizer currently uses flat shading &#8211; next would be to add <a href="http://en.wikipedia.org/wiki/Gouraud_shading" rel="nofollow" class="liwikipedia">Gouraud and Phong</a>, not to mention texturing.</p>

<p>3D rotation on world objects are performed using matrix multiplication. The camera is rotated using Quaternions since this made it simpler to use the <a href="http://www.devmaster.net/articles/viewing-systems/" class="link-external">UVN</a> camera model. The third scene in the demo above is animated; this is accomplished using a simple timer thread using which any number of events can be scheduled for execution at given time intervals.</p>

<p><strong>Performance</strong></p>

<p>When programming in Java it&#8217;s easy to not worry about memory usage and allocations since the garbage collector handles the freeing up of memory. But for graphics engines every allocation or garbage collection run will impact performance. So from the outset I&#8217;ve tried to pre-allocate memory where possible, by constructing temporary vectors and matrices for use during calculations later on. Thus, the vast majority of the matrix and vector multiplication which take place in the render loop don&#8217;t allocate any new memory when doing so.</p>

<p>However, when I finally started rendering things I found that the performance bottleneck was actually the rasterizer. The more polygons (triangles) that needed to be drawn and the larger they appeared on screen, the longer each frame took to render. Perhaps I can improve this by optimising the polygon order (e.g. render from farthest to nearest) and improving the raster algorithms. Eventually I want to switch to using OpenGL as the rendering system but since I&#8217;ve come so far with the software renderer it would be nice to see if I can improve it a bit more first.</p>

<p><strong>Download</strong></p>

<p>The engine code is licensed under the LGPL and is available <a href="http://www.hiddentao.com/code/3d-graphics/" class="liinternal">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hiddentao.com/archives/2010/01/20/3d-demo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple 3D graphics engine</title>
		<link>http://www.hiddentao.com/code/3d-graphics/</link>
		<comments>http://www.hiddentao.com/code/3d-graphics/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 09:22:48 +0000</pubDate>
		<dc:creator>ram</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.hiddentao.com/?page_id=717</guid>
		<description><![CDATA[This is a simple 3D graphics engine I&#8217;ve written in Java 1.5 using the Swing windowing toolkit and parts of the Java2D API. It supports the following features: Hierarchical scenegraph including Mesh, Rotation, Translation and Light nodes. Triangle primitives with helpers for building cubes UVN camera with orthographic or perspective projection Timer scheduler for animating [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple 3D graphics engine I&#8217;ve written in Java 1.5 using the Swing windowing toolkit and parts of the Java2D API. It supports the following features:</p>

<ul>
<li>Hierarchical scenegraph including <code>Mesh</code>, <code>Rotation</code>, <code>Translation</code> and <code>Light</code> nodes.</li>
<li>Triangle primitives with helpers for building cubes</li>
<li>UVN camera with orthographic or perspective projection</li>
<li>Timer scheduler for animating the scene.</li>
<li>Rendering system abstraction

<ul>
<li>Renderers follow <code>Visitor</code> design pattern</li>
</ul></li>
<li>Software-based renderer

<ul>
<li>Wireframe/flat shading</li>
<li>Simple directional light</li>
<li>Backface culling</li>
<li>Pixel-level z-buffer</li>
</ul></li>
<li>Customizable interaction (i.e. user input) handlers</li>
</ul>

<p>More information can be found in the <a href="http://www.hiddentao.com/archives/2010/01/20/3d-demo/" class="liinternal">original blog posting</a>.</p>

<h2 id="demo">Demo</h2>

<p><button onclick="window.open('http://www.hiddentao.com/downloads/kai/applet.html','_blank','status=0,toolbar=0,location=0,menubar=0,scrollbars=0,directories=0,resizable=0,width=670,height=500')">Launch demo (requires Java 1.5+)</button></p>

<h2 id="download">Download</h2>

<p>The source code for this engine is licensed under the <a href="http://www.gnu.org/copyleft/lesser.html" title="GNU Lesser General Public License" class="link-external">LGPL 3</a>.</p>

<p><a href="http://www.hiddentao.com/downloads/kai-engine.zip" class="lizip">Download source code</a>.</p>

<p>Build instructions can be found in <code>README.txt</code> in the download package.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hiddentao.com/code/3d-graphics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
