<?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>96methods</title>
	<atom:link href="http://www.96methods.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.96methods.com</link>
	<description>The online space of Graham Blake</description>
	<lastBuildDate>Sat, 28 Jan 2012 19:54:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Three.js: Simple Collision Detection</title>
		<link>http://www.96methods.com/2012/01/three-js-simple-collision-detection/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=three-js-simple-collision-detection</link>
		<comments>http://www.96methods.com/2012/01/three-js-simple-collision-detection/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 19:54:27 +0000</pubDate>
		<dc:creator>gblake</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[three.js]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://www.96methods.com/?p=169</guid>
		<description><![CDATA[I&#8217;ve been spending some time trying to work out how to perform basic collision detection with the three.js library. After a combination of Googling, looking at the three.js source code and looking at the sample code on the three.js github &#8230; <a href="http://www.96methods.com/2012/01/three-js-simple-collision-detection/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending some time trying to work out how to perform basic collision detection with the three.js library. After a combination of Googling, looking at the three.js source code and looking at the sample code on the three.js github pages I&#8217;ve managed to get something working.</p>
<p>I found the best collision detection example at <a title="three.js repository on github" href="https://github.com/mrdoob/three.js/commit/6ad7cbb47bd4a0e441c744030a8a0e2e3f2edfd2" target="_blank">Mr.Doob&#8217;s three.js repository</a> on github. In fact that are a number of examples there. These examples use a couple of utility files, namely CollisionUtils.js and Collisions.js that can be found along with the example code. I&#8217;m pretty sure that I checked out the latest revision of the three.js code from github but the CollisionUtils.js and Collisions.js utility files that are available <a href="https://github.com/mrdoob/three.js/commit/6ad7cbb47bd4a0e441c744030a8a0e2e3f2edfd2" target="_blank">here</a> didn&#8217;t seem to come with it. I used these utility files in order to implement collision detection in my little exploration where they allowed me to use:</p>
<pre class="brush: jscript; title: ; notranslate">
THREE.Collisions.colliders.push(
	THREE.CollisionUtils.MeshOBB( cube ) );
</pre>
<p>Essentially this creates an Object Bounding Box (OBB) around a THREE.Mesh object (<em>cube</em> in this example) and adds it to a collision detection list (THREE.Collisions.colliders as defined in Collisions.js). The <em>MeshOBB()</em> method is defined in the CollisionUtils.js file. In my code I added a number of cuboid objects to my 3D scene and also added them to the collision detection list (using the code snippet above). My plan was to then determine if my moving 3D object, or character, had collided with any of these cuboids.</p>
<p>In order to determine if my moving character had collided with any of the other objects in the scene (the objects on the collision detection list) I used the THREE.Ray class. The following segment of code determines the position of a theoretical focal point of this ray (think beam of light) that lies somewhere in front of our character. As our character rotates the focal point rotates also.</p>
<p>I believe that the distance specified in the second argument to the THREE.Ray constructor essentially represents the direction in which the ray is to be sent. I&#8217;ve used a value of 1000 in this example but it could have been a much smaller value.</p>
<pre class="brush: jscript; title: ; notranslate">
// Using a little trigonometry calculate a point in
// space 1000 units in front of our character
var deltaX = Math.floor(Math.sin(mesh.rotation.y) * 1000);
var deltaZ = Math.floor(Math.cos(mesh.rotation.y) * 1000);

// Calculate where this collision focus point is in
// relation to our character position
var focusX = mesh.position.x - deltaX;
var focusZ = mesh.position.z - deltaZ;

// Fire a ray from the centre point of our character to the
// collision focus point
var ray = new THREE.Ray(mesh.position,
	new THREE.Vector3(focusX, 0, focusZ));

var c = THREE.Collisions.rayCastNearest( ray );

if(c &amp;&amp; c.distance &lt;= 50)
{
	console.log(c.distance);
	tween.stop();
}
</pre>
<p>The <em>rayCastNearest()</em> method is used to determine if the ray coincides with any of the objects that were added to the collision detection list that was populated earlier. If there is an object (or collider object as I&#8217;ve shown in the figure below) that the ray intersects then the object returned by the <em>rayCastNearest()</em> method includes a <em>distance</em>property that tells us the distance between position of our character and the collider object. In the code extract above I&#8217;ve specified a distance of &lt;= 50 as my character had a length of 100 and so 50 is the point at which the face of my character would potentially collide with any collider objects. If a collision occurs I stop the tweening update so that my character stops moving.</p>
<p><a href="http://www.96methods.com/wp-content/uploads/2012/01/collisiondetection01.png"><img class="aligncenter size-full wp-image-171" title="collisiondetection01" src="http://www.96methods.com/wp-content/uploads/2012/01/collisiondetection01.png" alt="Collision detection" width="247" height="207" /></a></p>
<p>Note: In the figure above I&#8217;m pretty sure that I should have shown the z-axis as -z.</p>
<p>Once I&#8217;ve actually produced a practical demonstration of this theory I will post again with an example.</p>
<h2>Finally</h2>
<p>I just wanted to provide some further links as I did a little bit of trawling on the net when I was first researching into collision detection. I&#8217;m not sure that I&#8217;m using the best technique but there still seems to be validity in the methods that I&#8217;ve used. I came across a <a title="Discussion on determining Ray direction" href="https://github.com/mrdoob/three.js/issues/960" target="_blank">discussion on the Mr.Doob github pages</a> where someone was unsure of how to find the direction for the THREE.Ray. The individual concerned did some searching themselves and came up with a slightly different method of determining the Ray direction than I did.</p>
<p>At one stage I was considering the use of the JigLibJS library as discussed on <a title="Three.js and JigLibJS" href="http://timothypoon.com/blog/2011/03/08/using-three-js-and-jiglibjs-together/" target="_blank">Tim Poon&#8217;s site</a>. Didn&#8217;t go down this road in the end but could be interesting.</p>
<p>Of course I also found the code examples that come with the three.js library fairly useful too.</p>
<div id="tweetbutton169" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.96methods.com%2F2012%2F01%2Fthree-js-simple-collision-detection%2F&amp;text=Three.js%3A%20Simple%20Collision%20Detection&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.96methods.com%2F2012%2F01%2Fthree-js-simple-collision-detection%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.96methods.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.96methods.com/2012/01/three-js-simple-collision-detection/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Three.js: Moving Objects</title>
		<link>http://www.96methods.com/2012/01/three-js-moving-objects/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=three-js-moving-objects</link>
		<comments>http://www.96methods.com/2012/01/three-js-moving-objects/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 11:53:43 +0000</pubDate>
		<dc:creator>gblake</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[three.js]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://www.96methods.com/?p=85</guid>
		<description><![CDATA[Thought that I should write another post about my discoveries with the Three.js library as my last post was written sometime before Christmas. Having said that I didn&#8217;t make much progress with my Three.js investigations over the Christmas and New &#8230; <a href="http://www.96methods.com/2012/01/three-js-moving-objects/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Thought that I should write another post about my discoveries with the Three.js library as my last post was written sometime before Christmas. Having said that I didn&#8217;t make much progress with my Three.js investigations over the Christmas and New Year period. Quite a bit of time was spent pondering how to best implement an Object Orientated Programming approach with my JavaScript work.</p>
<p>In the end I elected to use the MooTools library; actually I&#8217;m only using the Class definition of that library so far. I&#8217;m just rather unimpressed with how classes, sorry reference types, are defined in JavaScript. Certainly when compared to how easily and seemingly naturally this is done with other modern languages. There seem to be a number of different techniques, or patterns, in use by the JavaScript community but in the end I decided to just use MooTools. I think that my main reason for electing to use the MooTools library was due to my desire to find out how to distinguish between private and public class members in JavaScript. I was doing some Googling one day and found something about how to define private class members with MooTools. I know this can be done without resorting to the use of a framework but sometimes I just want to get on with things and not worry about the boring details. Note to self: have a good look at the underlying principles of reference types in JavaScript sometime, e.g. the use of prototype.</p>
<p>So, I&#8217;ve been playing with a bit more of the Three.js library, been using the <a title="tween.js" href="https://github.com/sole/tween.js" target="_blank">Tween.js library</a> to perform some very simple movement and the <a title="require.js" href="http://requirejs.org/" target="_blank">Require.js library</a> to bring everything together in a structured way.</p>
<p>Using the require.js library allows me to have just a single &lt;script&gt; tag in my HTML that references my main JavaScript file, namely main.js.</p>
<h2>Managing JavaScript Files with require.js</h2>
<p>Here&#8217;s the HTML.  The main point of interest here is the &lt;script&gt; tag I think. I&#8217;ve added some buttons to control the movement of the 3D object that I&#8217;ll discuss in a bit. I&#8217;m not going to apologise for the lack of styling and the ugly buttons; but I am sorry about that! In future posts I will attempt to make things a little tidier.</p>
<pre class="brush: xml; title: main.html; notranslate">
&lt;!doctype html&gt;
&lt;html lang=&quot;en&quot;&gt;
	&lt;head&gt;
		&lt;title&gt;A moving shape - Made with three.js&lt;/title&gt;
		&lt;meta charset=&quot;utf-8&quot;&gt;
	&lt;/head&gt;
	&lt;body&gt;

		&lt;div id=&quot;container&quot;&gt;&lt;/div&gt;
		&lt;div&gt;
			&lt;input type=&quot;button&quot; id=&quot;fwdbtn&quot; value=&quot;FWD&quot;/&gt;
			&lt;input type=&quot;button&quot; id=&quot;rotateleftbtn&quot; value=&quot;ROTATE LEFT&quot;/&gt;
			&lt;input type=&quot;button&quot; id=&quot;rotaterightbtn&quot; value=&quot;ROTATE RIGHT&quot;/&gt;
		&lt;/div&gt;

		&lt;script data-main=&quot;js/main&quot; src=&quot;js/require.js&quot;&gt;&lt;/script&gt;

	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Next is the JavaScript. Firstly is my main.js file that creates the 3D scene, adds objects to the scene and assigns event handlers to the buttons that were defined in the HTML previously. The first point of interest is the use of the <em>require()</em> function (line 1 in the main.js file shown below). I&#8217;m not going to discuss the details of the require.js library, suffice to say that this line ensures that the Character.js, Tween.js, RequestAnimationFrame.js, three.js and jquery.js dependency files are loaded before the inner function is executed. I&#8217;ve found that the use of the require.js library has given me the ability to place JavaScript code in smaller files rather than one large file and means that I don&#8217;t have to place numerous &lt;script&gt; tags in my HTML. There are many other benefits to using the require.js and I urge you to take a look at it.</p>
<h2>Animating</h2>
<p>I&#8217;ve attempted to place all code that deals with my movable object, or character as I have called it, in its own JavaScript file, Character.js. The Character.js file contains the definition of the Character class that is instantiated on line 4 below. Below this a little jQuery is used to bind methods of the Character class to click events on the buttons.</p>
<pre class="brush: jscript; title: main.js; notranslate">
require(['96methods/Character', 'libraries/Tween', 'libraries/RequestAnimationFrame', 'libraries/Three', 'jquery'], function(Character) {

	var camera, scene, renderer;
	var character = new Character();

	// Add some button click event handlers:
	$(&quot;#rotateleftbtn&quot;).bind('click', character.rotateCharacterLeft);
	$(&quot;#rotaterightbtn&quot;).bind('click', character.rotateCharacterRight);
	$('#fwdbtn').bind('click', character.forwardCharacter);

	// Initialise and then animate the 3D scene!
	init();
	animate();
</pre>
<p>Following this is the <em>init()</em> method again as I&#8217;ve used previously in other posts (and in fact seems almost like the three.js standard). The key diferences between this version and what I did previously are rotating the camera so that it&#8217;s looking down upon the scene a little and using the <em>createCharacter()</em> method to add the &#8216;character&#8217; object to the scene. Again this method is defined in the Character.js file (see later in this post).</p>
<p>Then come the <em>animate()</em> and <em>render()</em> function calls to perform the scene update; again as I&#8217;ve described in my previous post. The key difference here is the addition of the <em>TWEEN.update()</em> method call (line 79). TWEEN is yet another JavaScript library that I&#8217;m using to give me tweening functionality. Essentially everytime the <em>animate()</em> function is called the character object&#8217;s update method is called to reposition my character.</p>
<pre class="brush: jscript; first-line: 15; title: ; notranslate">
	function init() {

		// Instantiate the 3D scene:
		scene = new THREE.Scene();

		// Instantiate an Orthographic camera this time.
		// The Left/Right/Top/Bottom values seem to be relative to the scene's 0, 0, 0 origin.
		// The best result seems to come if the overall viewable area is divided in 2 and
		// the Left &amp; Bottom values set to negative
		camera = new THREE.OrthographicCamera(
			window.innerWidth / -2, 	// Left
			window.innerWidth / 2,		// Right
			window.innerHeight / 2,		// Top
			window.innerHeight / -2,	// Bottom
			-2000,						// Near clipping plane
			1000 );						// Far clipping plane

		// Set the camera position so that it's up top and looking down:
		camera.position.y = 100;
		// Rotate around the x-axis by -45 degrees:
		camera.rotation.x -= 45 * (Math.PI/ 180);

		// Add the camera to the scene:
		scene.add(camera);

		// Define a cylinder object, well a cone anyway:
		cylinder = new THREE.Mesh(
			new THREE.CylinderGeometry(25,	// Radius top
				100,						// Radius bottom
				100,						// Height
				25,							// Number of segments in circumference (i.e. how smooth)
				5,							// Number of segments high
				false						// Open ended
			),
			new THREE.MeshBasicMaterial( {color: 0x372AFF} )
		);
		// Position it slightly to the right of the scene...
		cylinder.position.x = 400;
		// ...and add it to the scene:
		scene.add(cylinder);

		// Define our character shape and location within the scene:
		character.createCharacter(0, 0);
		// Add it to the stage:
		scene.add(character.getMesh());

		// Instantiate the renderer
		renderer = new THREE.CanvasRenderer();
		// .. and set it's size:
		renderer.setSize(window.innerWidth, window.innerHeight);

		// Place the renderer into the HTML (inside the #container div):
		$('#container').append(renderer.domElement);

	}

	function animate() {
		// Defined in the RequestAnimationFrame.js file, this function means that the
		// animate function is called upon timeout:
		requestAnimationFrame( animate );

		render();

		// Update the character position
		TWEEN.update();
	}

	function render() {

		// *** Update the scene ***
		renderer.render(scene, camera);
	}
});
</pre>
<p>As mentioned earlier, I&#8217;m trying to place all of the code that handles my moveable object in the character.js file, and therefore in my Character class.</p>
<p>There&#8217;s more require.js magic here to define my character module and specify the dependencies for this module, i.e. the three.js, mootools-core-1.4.2.js and Tween.js files. Once these files have been loaded a new instance of the Class object is returned (and thus available to the main.js file). Details of how the Class function works can be found in the MooTools documentation (see links later in this post).</p>
<p>Firstly a number of private member variables are declared and initialised then, to differentiate between private members and public members, the class is &#8216;appended&#8217; to (at line 24 of character.js) specifying the public methods.</p>
<p>The <em>getMesh()</em> and <em>setMesh()</em> accessor methods are simply used to get/set the mesh data that is encapsulated within the Character class.</p>
<p>The <em>createCharacter()</em> method is responsible for instantiating the mesh for the character and setting its initial position in the 3D scene.</p>
<pre class="brush: jscript; title: character.js; notranslate">
// 96methods/Character.js

// Character class definition

define(['libraries/three', 'libraries/mootools-core-1.4.2', 'libraries/Tween'], function() {

	return new Class(function() {

		// Private members
		var mesh = null;
		var width = 25, height = 25, length = 100;

		var tween = null;

		var currentAngle = { angle: 0 };
		var targetAngle = { angle: 45 };

		var currentZPos = { zPos: 0 };
		var targetZPos = { zPos: 100 };

		var actualAngle = 0;
		var actualZPos = 0;

		Object.append(this, {
			// Getters/setters
			getMesh: function() { return mesh; },
			setMesh: function(value) { mesh = value; },

			// Methods
			createCharacter: function(xpos, ypos) {
				mesh = new THREE.Mesh(
					new THREE.CubeGeometry(width, height, length),
					new THREE.MeshBasicMaterial( { color: 0x121212} ) // Material
				);

				mesh.position.x = xpos;
				mesh.position.z = ypos;
				mesh.position.y = 0;
			},
</pre>
<p>The <em>forwardCharacter()</em>, <em>rotateCharacterLeft()</em> and <em>rotateCharacterRight()</em> methods are bound to the buttons in the HTML and are responsible for controlling the movement of the character (ok it&#8217;s an oblong and not a well defined character but I&#8217;m taking small steps at a time here) when the buttons are clicked. If we focus on the <em>rotateCharacterLeft()</em> method:</p>
<pre class="brush: jscript; first-line: 40; title: ; notranslate">
			rotateCharacterLeft: function(event) {

				// Reset angle info:
				actualAngle = 0;
				currentAngle = { angle: 0 };

				// Define the tween along with the update function:
				tween = new TWEEN.Tween(currentAngle)
					.to(targetAngle, 1000)
					.onUpdate(function() {

						// Calculate the difference between current angle and where we want to be:
						var difference = Math.abs(currentAngle.angle - actualAngle);
						actualAngle = currentAngle.angle;

						// Rotate about Y:
						mesh.rotation.y += difference * (Math.PI / 180);
					})
					.start();
			},
</pre>
<p>The tween variable is assigned an instance of the Tween class; again see the Tween.js library (links a little later in this post). The argument to the Tween class&#8217;s constructor, currentAngle in this case, specifies the variable that will be used to track the current state of the animation as time progresses. The <em>to()</em> method then takes the target state and the time in milliseconds that the animation should take. In my example I&#8217;ve set the duration to 1000 milliseconds or 1 second. The <em>onUpdate()</em> method allows us to specify a callback function that is called when the <em>TWEEN.update()</em> method is called (see the <em>animate()</em> method of main.js shown earlier). In the case of the <em>rotateCharacterLeft()</em> method example the angle will be updated until it reaches the target angle of 45 degrees. Each time the callback function is called we calculate the difference between the current angle as determined by the tween and the actual angle the character is positioned at and move the character by this difference. The end result is that the character object rotates by 45 degrees in 1 second.</p>
<p>Here&#8217;s the remainder of the character.js file. The main point of interest here is in the <em>forwardCharacter()</em> method where the <em>translateZ()</em> method is used to move the character object, rather than rotating it.</p>
<pre class="brush: jscript; first-line: 60; title: ; notranslate">
			rotateCharacterRight: function(event) {

				// Reset angle info:
				actualAngle = 0;
				currentAngle = { angle: 0 };

				// Define the tween along with the update function:
				tween = new TWEEN.Tween(currentAngle)
					.to(targetAngle, 1000)
					.onUpdate(function() {

						// Calculate the difference between current angle and where we want to be:
						var difference = Math.abs(currentAngle.angle - actualAngle);
						actualAngle = currentAngle.angle;

						// Rotate about Y:
						mesh.rotation.y -= difference * (Math.PI / 180);
					})
					.start();
			},

			forwardCharacter: function(event) {

				// Reset z-pos info:
				actualZPos= 0;
			 	currentZPos = { zPos: 0 };

			 	tween = new TWEEN.Tween(currentZPos)
			 		.to(targetZPos, 1000)
			 		.onUpdate(function() {
						// Calculate the difference between current frame number and where we want to be:
						var difference = Math.abs(currentZPos.zPos - actualZPos);
						actualZPos = currentZPos.zPos;

						// Moving in -Z direction:
						mesh.translateZ(-difference);
			 		})
			 		.start();
			}

		}); // End of Object.append

	});
});
</pre>
<h2>Summary</h2>
<p>I&#8217;ve uploaded an <a title="Moving Object Demo" href="http://www.96methods.com/wp-content/plugins/scripts/2012/01/Main.html" target="_blank">example of the movable object</a> to demonstrate the code discussed in this post. One of my colleagues pointed out to me recently that none of my examples worked in IE. I think this is because of the issues with Canvas on earlier versions of IE.</p>
<p>I also appreciate that the graphics that these brief examples reveal are far from being attractive. Ok, so they are ugly and primitive (yep, quite literally primitive)! I hope that, in future posts, that will be resolved. At the moment I&#8217;m just happy to be playing around with the technology and recording my discoveries.</p>
<p>I decided with this post to place links mostly at the end of the piece. The silly idea was to tempt people to read the whole post before clicking on links and leaving my site.</p>
<p>Full details of the require.js library can be found at the <a title="require.js" href="http://requirejs.org/" target="_blank">require.js site</a>. I recall that I initially heard about this library on the excellent <a title="Think Vitamin" href="http://thinkvitamin.com/code/javascript/organize-your-code-with-requirejs/" target="_blank">Think Vitamin</a> site.</p>
<p>I happened across a <a title="keetology.com" href="http://keetology.com/blog/2009/07/23/up-the-moo-herd-iii-its-classy-not-classic" target="_blank">post by Mark Joseph Obcena</a> whilst searching for information on how best to implement private methods in JavaScript. This then led me to begin using the <a title="mootools" href="http://mootools.net/" target="_blank">MooTools framework</a>. I also came across <a title="David Walsh Blog" href="http://davidwalsh.name/mootools-requirejs" target="_blank">David Walsh&#8217;s post</a> about the combination of require.js and MooTools that you may find interesting reading. <a title="MooTools API Documentation" href="http://mootools.net/docs/core" target="_blank">Documentation for the MooTools framework</a> is also a good starting point.</p>
<p>The tween.js code can be found on <a title="tween.js" href="https://github.com/sole/tween.js" target="_blank">github</a>. I found out about this library/engine at the <a title="Learning Three.js" href="http://learningthreejs.com/blog/2011/08/17/tweenjs-for-smooth-animation/" target="_blank">Learning Three.js</a> site. I&#8217;ve recently found another <a title="gskinner tween.js" href="http://tweenjs.com/" target="_blank">tweening library by gskinner</a>. I may need to look into this one at some point in the future.</p>
<p>If you&#8217;ve found this post useful or if you&#8217;ve constructive comments please add a comment or send me an email to let me know. It&#8217;s sometimes nice to know if anyone out there in web land finds any of this stuff useful.</p>
<div id="tweetbutton85" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.96methods.com%2F2012%2F01%2Fthree-js-moving-objects%2F&amp;text=Three.js%3A%20Moving%20Objects&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.96methods.com%2F2012%2F01%2Fthree-js-moving-objects%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.96methods.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.96methods.com/2012/01/three-js-moving-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pastry</title>
		<link>http://www.96methods.com/2012/01/pastry/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pastry</link>
		<comments>http://www.96methods.com/2012/01/pastry/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 14:11:35 +0000</pubDate>
		<dc:creator>gblake</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.96methods.com/?p=93</guid>
		<description><![CDATA[Saturday morning. Now Saturday afternoon. Procrastinating by looking at things on the interwebs. Telling myself that I&#8217;m doing research. Came across a post by Keir Whitaker about one of his many projects: The Pastry Box Project. Looks interesting so thought &#8230; <a href="http://www.96methods.com/2012/01/pastry/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Saturday morning. Now Saturday afternoon. Procrastinating by looking at things on the interwebs. Telling myself that I&#8217;m doing research. Came across a post by <a href="http://keirwhitaker.com/">Keir Whitaker</a> about one of his many projects: <a href="http://www.the-pastry-box-project.net/">The Pastry Box Project</a>.</p>
<p>Looks interesting so thought that I&#8217;d share.</p>
<div id="tweetbutton93" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.96methods.com%2F2012%2F01%2Fpastry%2F&amp;text=Pastry&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.96methods.com%2F2012%2F01%2Fpastry%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.96methods.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.96methods.com/2012/01/pastry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three.js: Moving the Camera</title>
		<link>http://www.96methods.com/2011/12/three-js-moving-the-camera/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=three-js-moving-the-camera</link>
		<comments>http://www.96methods.com/2011/12/three-js-moving-the-camera/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 19:08:03 +0000</pubDate>
		<dc:creator>gblake</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.96methods.com/?p=78</guid>
		<description><![CDATA[My previous post took a look at the three.js 3D JavaScript engine. I&#8217;ve made some simple embellishments since that last post. I&#8217;ve worked out how to implement an orthographic camera rather than a PerspectiveCamera and how to move the camera &#8230; <a href="http://www.96methods.com/2011/12/three-js-moving-the-camera/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My <a title="The Three.js Library" href="http://www.96methods.com/2011/12/the-three-js-library/">previous post</a> took a look at the <a href="&quot;https://github.com/mrdoob/three.js">three.js</a> 3D JavaScript engine. I&#8217;ve made some simple embellishments since that last post.</p>
<p>I&#8217;ve worked out how to implement an <a href="http://http://en.wikipedia.org/wiki/Orthographic_projection">orthographic</a> camera rather than a PerspectiveCamera and how to move the camera within the scene while ensuring that the camera is still pointing (or focused) on the centre of the scene.</p>
<p>I&#8217;ve simply taken the code from the last post and made some changes to it.</p>
<p>Here is my <a title="cubedemo01" href="http://www.96methods.com/wp-content/plugins/scripts/2011/12/cubedemo01.html" target="_blank">cube and cylinder example</a>.</p>
<p>Here&#8217;s the HTML:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!doctype html&gt;
&lt;html lang=&quot;en&quot;&gt;
	&lt;head&gt;
		&lt;title&gt;A moving camera - Made with three.js&lt;/title&gt;
		&lt;meta charset=&quot;utf-8&quot;&gt;
	&lt;/head&gt;
	&lt;body&gt;

		&lt;div id=&quot;container&quot;&gt;&lt;/div&gt;

		&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
		&lt;script src=&quot;js/Three.js&quot;&gt;&lt;/script&gt;
		&lt;script src=&quot;js/RequestAnimationFrame.js&quot;&gt;&lt;/script&gt;
		&lt;script src=&quot;cubedemo01.js&quot;&gt;&lt;/script&gt;

	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>No appreciable change since last time.</p>
<p>Here&#8217;s the JavaScript. Comments in the code to aid understanding.</p>
<p>I came across the RequestAnimationFrame function while looking at a three.js <a href="http://http://creativejs.com/tutorials/three-js-part-1-make-a-star-field/#1">tutorial on the CreativeJS site</a>. Details about <a href="http://http://paulirish.com/2011/requestanimationframe-for-smart-animating/">RequestAnimationFrame can be found on Paul Irish&#8217;s site</a>.</p>
<pre class="brush: jscript; title: ; notranslate">
var camera, scene, renderer;
var cube, cylinder;

init();
animate();

function init() {

	var numberOfSegments = 1;

	// Instantiate the 3D scene:
	scene = new THREE.Scene();

	// Instantiate an Orthographic camera this time.
	// The Left/Right/Top/Bottom values seem to be relative to the scene's 0, 0, 0 origin.
	// The best result seems to come if the overall viewable area is divided in 2 and
	// the Left &amp; Bottom values set to negative
	camera = new THREE.OrthographicCamera(
		window.innerWidth / -2, 	// Left
		window.innerWidth / 2,		// Right
		window.innerHeight / 2,		// Top
		window.innerHeight / -2,	// Bottom
		-2000,						// Near clipping plane
		1000 );						// Far clipping plane

	// Set the camera position so that it's not on top of our object in the scene:
	camera.position.y = 100;

	// Add the camera to the scene:
	scene.add(camera);

	// Define a Cylinder object
	cylinder = new THREE.Mesh(
		new THREE.CylinderGeometry(25,	// Radius top
			100,						// Radius bottom
			100,						// Height
			25,							// Number of segments in circumference (i.e. how smooth)
			5,							// Number of segments high
			false						// Open ended
		),
		new THREE.MeshBasicMaterial( {color: 0x372AFF} )
	);
	cylinder.position.x = 400;

	scene.add(cylinder);

	// Define the cube object
	cube = new THREE.Mesh(
		new THREE.CubeGeometry(200, 200, 200,
			numberOfSegments, numberOfSegments, numberOfSegments), // Cube geometry
		new THREE.MeshBasicMaterial( { color: 0x373737} ) // Material
	);

	// Add the cube to the scene:
	scene.add(cube);

	// Instantiate the renderer
	renderer = new THREE.CanvasRenderer();
	// .. and set it's size:
	renderer.setSize(window.innerWidth, window.innerHeight);

	// Place the renderer into the HTML (inside the #container div):
	$('#container').append(renderer.domElement);

}

function animate() {
	// Defined in the RequestAnimationFrame.js file, this function means that the
	// animate function is called upon timeout:
	requestAnimationFrame( animate );

	render();
}

function render() {

	// *** Update the scene ***

	// Set the camera to always point to the centre of our scene, i.e. at vector 0, 0, 0
	camera.lookAt( scene.position );

	// Move the camera in a circle with the pivot point in the centre of this circle...
	// ...so that the pivot point, and focus of the camera is on the centre of our scene.
	var timer = new Date().getTime() * 0.0005;

	camera.position.x = Math.floor(Math.cos( timer ) * 200);
	camera.position.z = Math.floor(Math.sin( timer ) * 200);

	renderer.render(scene, camera);
}
</pre>
<p>More posts to come on this topic I hope as I dig into the Three.js engine a little further.</p>
<p>&nbsp;</p>
<div id="tweetbutton78" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.96methods.com%2F2011%2F12%2Fthree-js-moving-the-camera%2F&amp;text=Three.js%3A%20Moving%20the%20Camera&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.96methods.com%2F2011%2F12%2Fthree-js-moving-the-camera%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.96methods.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.96methods.com/2011/12/three-js-moving-the-camera/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Three.js Library</title>
		<link>http://www.96methods.com/2011/12/the-three-js-library/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-three-js-library</link>
		<comments>http://www.96methods.com/2011/12/the-three-js-library/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 19:44:40 +0000</pubDate>
		<dc:creator>gblake</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[three.js]]></category>

		<guid isPermaLink="false">http://www.96methods.com/?p=48</guid>
		<description><![CDATA[I&#8217;ve been taking a look at the three.js JavaScript library recently. Well, 3D engine I suppose. Essentially it allows the implementation of 3D graphics within the browser using no plug-ins but just JavaScript in a modern browser. When it comes &#8230; <a href="http://www.96methods.com/2011/12/the-three-js-library/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been taking a look at the <a href="&quot;https://github.com/mrdoob/three.js">three.js</a> JavaScript library recently. Well, 3D engine I suppose. Essentially it allows the implementation of 3D graphics within the browser using no plug-ins but just JavaScript in a modern browser.</p>
<p>When it comes to the rendering of the 3D imagery there is the choice of three renderers: Canvas, SVG and WebGL. There seem to be a number of issues surrounding the WebGL renderer at this point in time, centred around security issues. The WebGL renderer uses the local Graphics Processing Unit (GPU) and I believe this is where the security breach could take place. Currently there is no support for WebGL in Internet Explorer.</p>
<p>Anyway, I decided to have a play around with Three.js in the hope that I could use it in my future projects. My main concern at the moment is lack of documentation. It&#8217;s coming, but at the moment a lot of experimentation is required or a lot of online searching. The github repository does have a lot of excellent code examples but the code needs to be dissected in order to gain an understanding of what is going on.</p>
<p>I managed to put together a <em>very</em> simple example that shows a blue cube. Not terribly exciting, ok not at all exciting in any way, but it&#8217;s a beginning. Here is my <a href="http://www.96methods.com/wp-content/plugins/scripts/2011/11/cubedemo.html" title="cubedemo" target="_blank">blue box example</a>.</p>
<p>Here&#8217;s the HTML:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!doctype html&gt;
&lt;html lang=&quot;en&quot;&gt;
	&lt;head&gt;
		&lt;title&gt;A Cube made with three.js&lt;/title&gt;
		&lt;meta charset=&quot;utf-8&quot;&gt;
	&lt;/head&gt;
	&lt;body&gt;

		&lt;div id=&quot;container&quot;&gt;&lt;/div&gt;

		&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
		&lt;script src=&quot;js/Three.js&quot;&gt;&lt;/script&gt;
		&lt;script src=&quot;js/RequestAnimationFrame.js&quot;&gt;&lt;/script&gt;
		&lt;script src=&quot;cubedemo.js&quot;&gt;&lt;/script&gt;

	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The main items of note here are the &#8216;container&#8217; div, used to contain the 3D image, and the &lt;script&gt; tag that references the Three.js library. I&#8217;ve dumped all of my JavaScript code into its own file, cubedemo.js.</p>
<p>The first little bit of JavaScript code defines some variables to represent the 3D scene, the camera, the renderer and cube. I then call 2 functions <em>init()</em> and <em>render()</em>. The <em>init()</em> function will set-up the scene and the <em>render()</em> function will be responsible for rendering. Nothing too exciting. </p>
<pre class="brush: jscript; title: ; notranslate">
var camera, scene, renderer;
var cube;

init();
render();
</pre>
<p>Next comes the declaration of the <em>init()</em> function.</p>
<pre class="brush: jscript; first-line: 7; title: ; notranslate">
function init() {

	var numberOfSegments = 3;

	// Instantiate the 3D scene:
	scene = new THREE.Scene();

	// Instantiate the camera
	camera = new THREE.PerspectiveCamera(
		70, //FoV
		window.innerWidth / window.innerHeight, // Aspect ratio
		1, // Near clipping plane
		1000 // Far clipping plane
	);

	// Set the camera position so that it's not on top of our object in the scene:
	camera.position.z = 500;

	// Add the camera to the scene:
	scene.add(camera);

	// Define the cube object
	cube = new THREE.Mesh(
		new THREE.CubeGeometry(200, 200, 200,
			numberOfSegments, numberOfSegments, numberOfSegments), // Cube geometry
		new THREE.MeshBasicMaterial( { color: 0x372AFF} ) // Material
	);

	// Add the cube to the scene:
	scene.add(cube);

	// Instantiate the renderer
	renderer = new THREE.CanvasRenderer();
	// .. and set it's size:
	renderer.setSize(window.innerWidth, window.innerHeight);

	// Place the renderer into the HTML (inside the #container div):
	$('#container').append(renderer.domElement);

}
</pre>
<p>I&#8217;m hoping that the comments in the code make this function relatively self explanatory. First I create a new 3D scene.</p>
<p>I then set-up the camera which has the same aspect ratio as the area in which I&#8217;m going to display the 3D image and has a Field of View (Fov) of 70. I understand that the FoV is measured in degrees. I&#8217;ve not really totally sure of the near/far clipping plane values at this point in time, e.g. what the units of measurement are. I set the camera&#8217;s z-position to 500 so that the camera is not in the same position in the scene as our cube will be. I then add the camera to the scene.</p>
<p>Next I define a cube 200 units square, made up of 3 segments in each direction, and with a simple coloured skin or mesh. I then also add the cube object to the scene.</p>
<p>Then I create an instance of the <em>CanvasRenderer</em>, set its size so that it will fill the entire window, and add the <em>renderer</em> object to the HTML by using a little bit of jQuery magic to append it to my <em>#container</em> div.</p>
<p>Finally comes my <em>render()</em> function.</p>
<pre class="brush: jscript; first-line: 48; title: ; notranslate">
function render() {

	// *** Update the scene ***

	// Rotate the cube so that we can appreciate the 3D nature...
	// radians = degrees * (PI/180)

	// Rotate the cube 45 degress through the x axis (need to convert to radians):
	cube.rotation.y = 45 * (Math.PI/ 180);
	// Rotate the cube 45 degrees through the y axis (need to convert to radians):
	cube.rotation.x = 45 * (Math.PI/ 180);		

	renderer.render(scene, camera);
}
</pre>
<p>This piece of code simply rotates my cube object so that we aren&#8217;t simply viewing it from the side, and so that we can appreciate its 3D nature, and then renders the scene.</p>
<p>More posts to come on this topic I hope as I dig into the Three.js engine a little further.</p>
<div id="tweetbutton48" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.96methods.com%2F2011%2F12%2Fthe-three-js-library%2F&amp;text=The%20Three.js%20Library&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.96methods.com%2F2011%2F12%2Fthe-three-js-library%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.96methods.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.96methods.com/2011/12/the-three-js-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Web App Shall I (attempt to write) Today?</title>
		<link>http://www.96methods.com/2011/11/what-web-app-shall-i-attempt-to-write-today/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=what-web-app-shall-i-attempt-to-write-today</link>
		<comments>http://www.96methods.com/2011/11/what-web-app-shall-i-attempt-to-write-today/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 18:09:20 +0000</pubDate>
		<dc:creator>gblake</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.96methods.com/?p=30</guid>
		<description><![CDATA[I found an interesting post on Dan Zambonini&#8217;s site today all about finding inspiration for web app creation. He also provided a link to theinternetwishlist that may prove useful. Tweet]]></description>
			<content:encoded><![CDATA[<p>I found an interesting <a href="http://danzambonini.com/web-app-ideas-where-to-find-inspiration/">post on Dan Zambonini&#8217;s site</a> today all about finding inspiration for web app creation.</p>
<p>He also provided a link to <a href="http://theinternetwishlist.com/">theinternetwishlist</a> that may prove useful.</p>
<div id="tweetbutton30" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.96methods.com%2F2011%2F11%2Fwhat-web-app-shall-i-attempt-to-write-today%2F&amp;text=What%20Web%20App%20Shall%20I%20%28attempt%20to%20write%29%20Today%3F&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.96methods.com%2F2011%2F11%2Fwhat-web-app-shall-i-attempt-to-write-today%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.96methods.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.96methods.com/2011/11/what-web-app-shall-i-attempt-to-write-today/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SVG-edit</title>
		<link>http://www.96methods.com/2011/11/svg-edit/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=svg-edit</link>
		<comments>http://www.96methods.com/2011/11/svg-edit/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 13:45:22 +0000</pubDate>
		<dc:creator>gblake</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://www.96methods.com/?p=25</guid>
		<description><![CDATA[For some time now I&#8217;ve wanted to develop a set of classes, or a code library, to allow the drawing of simple, line-based images such as boxes, circles and polygons. I may have finally found a bit of a shortcut. &#8230; <a href="http://www.96methods.com/2011/11/svg-edit/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For some time now I&#8217;ve wanted to develop a set of classes, or a code library, to allow the drawing of simple, line-based images such as boxes, circles and polygons. I may have finally found a bit of a shortcut.</p>
<p>Initially I was planning to learn something about the Canvas object that gets partially branded as part of the HTML 5 specification. However this then shifted when I came across the Scalable Vector Graphics (SVG) language, or standard, or do I mean API. I began to look at the possibility of using the <a title="Raphaël JavaScript Library" href="http://raphaeljs.com">Raphaël JavaScript Library</a>, a small JavaScript library that enables the easy implementation of vector graphics, which I came across after a little Googling (or it may have been via the <a href="http://www.stackoverflow.com">Stack Overflow</a> site).</p>
<p>My plans have been on hold for a little while as I have been very busy at work, bringing work home with me or just too tired at the end of the working day to code in the evening, and I&#8217;ve also been looking at various JavaScript frameworks. However, I was reading something in my RSS feed earlier this week and came across an open source project. Actually it was an open source project that was quite irrelevant to what I wanted (it was the <a href="http://ace.ajax.org/">Ace code editor project</a>) but it led me to do a bit of searching to determine if there was an open source vector drawing application out there.</p>
<p>I came across the <a href="http://code.google.com/p/svg-edit/">SVG-edit</a> open source project which is a vector graphics editor for the web browser. A <a href="http://svg-edit.googlecode.com/svn/trunk/editor/svg-editor.html">demo of the SVG-edit editor</a> shows that it&#8217;s quite rich in features.</p>
<p>I downloaded the source code and began taking a brief look at it to determine if it was something that I could use for my own projects. The main vector drawing functionality of the editor seems to be situated in a single JavaScript file, namely svgcanvas.js. However a lot of useful features such as the implementation of selection handles, that appear when an object is selected thus allowed for rotation and scaling, are implemented in the main svg-edit.js file.</p>
<p>I&#8217;ve no doubt that this code would be an excellent starting point in developing a project that requires the ability to draw and manipulate vector graphics but effort would of course be needed to get one&#8217;s head into the code in order to extract the core functionality.</p>
<div id="tweetbutton25" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.96methods.com%2F2011%2F11%2Fsvg-edit%2F&amp;text=SVG-edit&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.96methods.com%2F2011%2F11%2Fsvg-edit%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.96methods.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.96methods.com/2011/11/svg-edit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving from Ruby on Rails to WordPress</title>
		<link>http://www.96methods.com/2011/11/moving-from-ruby-on-rails-to-wordpress/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=moving-from-ruby-on-rails-to-wordpress</link>
		<comments>http://www.96methods.com/2011/11/moving-from-ruby-on-rails-to-wordpress/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 19:40:48 +0000</pubDate>
		<dc:creator>gblake</dc:creator>
				<category><![CDATA[My Site]]></category>
		<category><![CDATA[site]]></category>

		<guid isPermaLink="false">http://www.96methods.com/?p=5</guid>
		<description><![CDATA[WordPress. I&#8217;ve installed it a number of times on a local machine running Apache web server. I&#8217;ve even installed it at my place of work . Played around a little bit, added some posts, but nothing more really. I gave &#8230; <a href="http://www.96methods.com/2011/11/moving-from-ruby-on-rails-to-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>WordPress. I&#8217;ve installed it a number of times on a local machine running Apache web server. I&#8217;ve even installed it at my place of work . Played around a little bit, added some posts, but nothing more really.</p>
<p>I gave my blog a very minor update in recent months where, essentially, I merely played around with the HTML and CSS a little. I was going to add more flourishes to the site but didn&#8217;t get around to it. I toyed with the idea of moving the site to the WordPress platform. The previous incarnation of this site had Ruby on Rails (RoR) running in the backend, code that I hand-crafted myself. It seemed far easier to just make some tweaks to the existing site than to begin learning to how to change the style of a WordPress-hosted site. I knew that WordPress would have features that I could use that would save me many hours of trying to code myself in RoR but the idea of wasting time trying to work out how to produce my own WordPress theme just did not appeal.</p>
<p>Well, I&#8217;ve recently been forced into a slight re-think. I realised several days ago that my RoR site had gone down. Ruby was reporting a server-side error. I decided to raise a helpdesk ticket with my hosting company only to find that I&#8217;d received an email from the host weeks before reporting that my site had been compromised. I followed the advice that they gave but of course the site was still down. I continued to raise the helpdesk ticket thinking that just a server re-boot was required. The response that came back pointed out that the operating system running on the servers had been upgraded and that, to cut a long story short, I&#8217;d have to upgrade my RoR install.</p>
<p>I&#8217;ve not been developing sites with RoR for quite a long time now. It seemed like I would have to get my head back into RoR again so that I could perform the upgrade that was required. I couldn&#8217;t be bothered with all of the hassle to be frank.</p>
<p>That&#8217;s why I&#8217;m now reverting to using WordPress. Of course it will give me much more functionality than my old site did even if it does mean that I&#8217;ve got to work out how to create a new WordPress theme. I think in the longer term it will be beneficial and a useful learning exercise.</p>
<p>I backed-up my old blog database with the intention of porting all of the old blog posts to WordPress. That now seems like a bit of a tedious task. I&#8217;m sure that no-one is going to miss that old content. Well, except for me that is. So I may resurrect some of those posts in the future.</p>
<p>The feeling that I had when I realised that my site was down was rather unexpected. In fact it didn&#8217;t come straight-away but when I realised that, potentially, it would be down for a while. It&#8217;s not that my site had any actual traffic to speak of. Maybe just the fact that I&#8217;d written some posts and that &#8216;voice&#8217; had been cut-off.</p>
<div id="tweetbutton5" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fwww.96methods.com%2F2011%2F11%2Fmoving-from-ruby-on-rails-to-wordpress%2F&amp;text=Moving%20from%20Ruby%20on%20Rails%20to%20WordPress&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fwww.96methods.com%2F2011%2F11%2Fmoving-from-ruby-on-rails-to-wordpress%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://www.96methods.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://www.96methods.com/2011/11/moving-from-ruby-on-rails-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

