<?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>Randy Bennett&#039;s Portfolio</title>
	<atom:link href="http://www.orangutangular.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.orangutangular.com</link>
	<description></description>
	<lastBuildDate>Mon, 07 Sep 2009 20:38:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Charged Particles (Revamped)</title>
		<link>http://www.orangutangular.com/charged-particles-revamped/</link>
		<comments>http://www.orangutangular.com/charged-particles-revamped/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 20:30:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=965</guid>
		<description><![CDATA[
 








 I optimized/prettied up my charged particles demo.  Click links for details. 


 Summary of Changes 


  I revisited my Charged Particles Simulation (original project listed below) with the intention of applying some things I have learned since its creation.  The biggest change is that it now uses an actual point-sprite-based [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center; "><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693" >
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693">
<p><a href="http://www.orangutangular.com/wp-content/uploads/CP_2500.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/CP_2500-300x215.jpg" alt="CP_2500" title="CP_2500" width="392" height="300" class="alignleft size-medium wp-image-972" /></a></p>
<p></br></p>
<p style = "font-size: 12pt; color:#FFFFFF;"> I optimized/prettied up my charged particles demo.  Click links for details. </p>
</table>
<p></br></p>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X5710');return false;" style="color:#55BBFF;"> Summary of Changes </a></strong><br />
</p>
<div id="X5710" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px; color:#FFFFFF;">  I revisited my Charged Particles Simulation (original project listed below) with the intention of applying some things I have learned since its creation.  The biggest change is that it now uses an actual point-sprite-based particle system to represent each charged particle.  So instead of a cube made of 24 vertices that needs to be lit, there is now a particle system of 20 point sprites that use additive blending to create a cool animated electric charge look.  Each point sprite is rendered using HLSL.
</p>
<p style="font-size: 12pt; margin-left: 50px; color:#FFFFFF;">  With this new, more efficient system, I was able to extend the max number of charged particles from 1000 to 2000 (2000 charged particles means 2000 * 20 = 40,000 point sprites), suggesting that the bottleneck was indeed on the graphics side as opposed to the physics side.
</p>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X1344');return false;" style="color:#55BBFF;"> Programming Features </a></strong><br />
</p>
<div id="X1344" style="display: none; background: transparent;">
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>Physics: </strong> Realistic Sphere-Sphere Collision Detection/Reaction, Conservation of Momentum, Coulomb&#8217;s Law, Vector Class, Matrix Class
</li>
<li style="margin-left:50pt;font-size:12pt; color:#FFFFFF;"><strong>Graphics: </strong> DirectX Primitives, DirectX Matrix Transformations, Alpha Blending
</li>
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>Data Structures: </strong> 3D array of Linked Lists Manages the Efficient Comparison of Particles
</li>
<li style="margin-left:50pt;font-size:12pt; color:#FFFFFF;"><strong>User Interface: </strong> Mouse Controlled 3D Camera with Rotation and Zoom
</li>
</div>
<p><strong style="font-size: 12pt;"> <a href="#" onclick="xcollapse('X2415');return false;" style="color:#55BBFF;"> Code Samples </a></strong><br />
</p>
<div id="X2415" style="display: none; background: transparent;">
<ul>
<li>
<strong style="font-size: 12pt; color:#FFFFFF;"> Sphere-Sphere Collision Response </strong></p>
<div style="font-size:11pt; color:#FFFFFF;">
<p>The following code is a function which is called whenever two sphere&#8217;s collide in 3D space.  It receives as arguments an array of Spheres (also referred to as point masses), a 3D Vector representing the distance between the two spheres, a double containing the amount of time which has passed since the last frame, and the indexes of the two colliding point masses within the pt_Masses array.</p>
<p>Nothing is returned, however the two spheres receive new velocities based on their initial velocities, relative positions, masses, and coefficients of restitution (elasticity). </p>
<p>Also note that, if the spheres are overlapping, they are each moved apart by half of the distance between them so that they are barely touching.</p>
</div>
<p><a href='http://www.orangutangular.com/wp-content/uploads/chargedparticlescollisioncode.zip' style = "color:#55BBFF;">ChargedParticlesCollisionCode.zip</a></p>
<p><a href="#" onclick="xcollapse('X8276');return false;" style = "color:#55BBFF;"> View Code </a><br />
</p>
<table id = "X8276" style="display: none; border: 1px solid #FFFFFF; padding: 10px; color:#000000; background-color: #FFFFFF;" border="0">
<tbody>
<tr >
<td >
<pre style="font-size: 8pt; font-family: consolas; width:573px;">

// FUNCTION HandleCollision() : Handles collisions between spheres
void HandleCollision(POINT_MASS pt_Masses[], Vector3D_d &#038;separationDistance, double &#038;changeInTime, int i, int j)
{
	// Create a unit length vector representing the angle of collision:
	Vector3D_d unitNormal = separationDistance;
	unitNormal.normalize();

	// Find the new velocities of both objects based off of their velocities prior to collision:
	double velocity_1 = pt_Masses[i].getLinearVelocity().dotProduct(unitNormal);
	double velocity_2 = pt_Masses[j].getLinearVelocity().dotProduct(unitNormal);

	// Calculate the average elasticity between the two spheres:
	double average_E = ( pt_Masses[i].getElasticity() + pt_Masses[j].getElasticity() ) / 2;

	// Use the equations for elastic collision response to calculate the final velocities:
	double finalVelocity_1 = ( ( ( pt_Masses[i].getMass() -
								( average_E * pt_Masses[j].getMass() ) ) * velocity_1 ) +
								( (1 + average_E) * pt_Masses[j].getMass() * velocity_2 ) ) /
								( pt_Masses[i].getMass() + pt_Masses[j].getMass() );
	double finalVelocity_2 = ( ( ( pt_Masses[j].getMass() -
								( average_E * pt_Masses[i].getMass() ) ) * velocity_2 ) +
								( (1 + average_E) * pt_Masses[i].getMass() * velocity_1 ) ) /
								( pt_Masses[i].getMass() + pt_Masses[j].getMass() );

	pt_Masses[i].setLinearVelocity( (finalVelocity_1 - velocity_1) * unitNormal + pt_Masses[i].getLinearVelocity() );
	pt_Masses[j].setLinearVelocity( (finalVelocity_2 - velocity_2) * unitNormal + pt_Masses[j].getLinearVelocity() );

	// If point masses are overlapping, back them up so that they are barely touching:
	double minDistance = pt_Masses[i].getBoundingSphereRadius() + pt_Masses[j].getBoundingSphereRadius();
	double overlapDistance = minDistance - separationDistance.getNorm();

	pt_Masses[i].setLocation( pt_Masses[i].getLocation() + ( 0.5 * unitNormal * overlapDistance) );
	pt_Masses[j].setLocation( pt_Masses[j].getLocation() + (-0.5 * unitNormal * overlapDistance) );
}
</pre>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X2250');return false;" style="color:#55BBFF;"> Screenshots  </a></strong><br />
</p>
<div id="X2250" style="display: none; background: transparent;">
<div id="attachment_975" class="wp-caption alignleft" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/CP_CloseUp.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/CP_CloseUp-300x257.jpg" alt="Electrifying" title="CP_CloseUp" width="300" height="257" class="size-medium wp-image-975" /></a><p class="wp-caption-text">Electrifying</p></div>
<div id="attachment_966" class="wp-caption alignright" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/CP_3Color.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/CP_3Color-300x218.jpg" alt="3 types of particles here" title="CP_3Color" width="300" height="257" class="size-medium wp-image-966" /></a><p class="wp-caption-text">3 types of particles here</p></div>
</div>
</div>
</table>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/charged-particles-revamped/feed/</wfw:commentRss>
		<slash:comments>2106</slash:comments>
		</item>
		<item>
		<title>Exchange Simulator Tool</title>
		<link>http://www.orangutangular.com/exchange-simulator-tool/</link>
		<comments>http://www.orangutangular.com/exchange-simulator-tool/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 17:54:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=929</guid>
		<description><![CDATA[
 








 Exchange Simulator is a tool I created to assist in the design process of a game I am working on.  It was developed in C# using Windows Forms.  Please open the links below to learn more. 



 Summary  

 This tool is used to determine the outcome of an exchange [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center;"><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693">
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693">
<p><a href="http://www.orangutangular.com/wp-content/uploads/ExchangeSim.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/ExchangeSim-300x262.jpg" alt="ExchangeSim" title="ExchangeSim" width="392" height="342" class="alignleft size-medium wp-image-931" /></a></p>
<p></br></p>
<p style = "font-size: 12pt;"> Exchange Simulator is a tool I created to assist in the design process of a game I am working on.  It was developed in C# using Windows Forms.  Please open the links below to learn more. </p>
</table>
<p></br></p>
<p><strong style="font-size: 12pt;"><br />
<a href="#" onclick="xcollapse('X1903');return false;" style="color:#55BBFF;"> Summary </a></strong> </a></p>
<div id="X1903" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px;"> This tool is used to determine the outcome of an exchange of resources between two CPU-controlled &#8220;actors&#8221;.  For both actors, the user may select the race, personality type, and number of each resource possessed by that actor.  Then, by clicking the &#8220;Request to Trade&#8221; button, one actor will make an intelligent offer to the other actor attempting to maximize the value of the trade.  If the other actor accepts the offer, then a &#8220;Decision Matrix&#8221; is created which determines whether each actor will defect and ambush the other during the trade, or cooperate and exchange the agreed upon resources.
</p>
<p style="font-size: 12pt; margin-left: 50px;"> Much of the displayed numerical data serves to verify to the user that the underlying code is performing correctly.  The outcome of an interaction allows the designer to see if certain exchanges are going as one would expect.
</p>
</div>
<p><strong style="font-size: 12pt;"><br />
<a href="#" onclick="xcollapse('X9091');return false;" style="color:#55BBFF;"> Programming Features </a></strong><br />
</a><br />
</p>
<div id="X9091" style="display: none; background: transparent;">
<li style="margin-left:50pt; font-size:12pt;"><strong> Windows Forms UI: </strong> Many standard Forms Controls are used such as Buttons, List Boxes, Combo Boxes, Labels, Text Boxes, Check Boxes, Radio Buttons, and Menus.
</li>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</table>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/exchange-simulator-tool/feed/</wfw:commentRss>
		<slash:comments>2387</slash:comments>
		</item>
		<item>
		<title>Vertex Displacement and Normal Calculation in the Vertex Shader</title>
		<link>http://www.orangutangular.com/run-time-vertex-displacement-and-normal-calculation-in-the-vertex-shader/</link>
		<comments>http://www.orangutangular.com/run-time-vertex-displacement-and-normal-calculation-in-the-vertex-shader/#comments</comments>
		<pubDate>Mon, 04 May 2009 22:10:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=847</guid>
		<description><![CDATA[
 








 This Shader Demo performs run-time vertex displacement and normal calculation on a surface.  The effect is programmed in HLSL, and the API code is in C# using the XNA Game Library.  Please open the links below to learn more. 


 Summary 


  This program demonstrates run-time vertex displacement and normal [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center;"><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693">
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693">
<p><a href="http://www.orangutangular.com/wp-content/uploads/pebblesbulgeup.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/pebblesbulgeup-300x201.jpg" alt="pebblesbulgeup" title="pebblesbulgeup" width="392" height="320" class="alignleft size-full wp-image-849" /></a></p>
<p></br></p>
<p style = "font-size: 12pt;"> This Shader Demo performs run-time vertex displacement and normal calculation on a surface.  The effect is programmed in HLSL, and the API code is in C# using the XNA Game Library.  Please open the links below to learn more. </p>
</table>
<p></br></p>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X5341');return false;" style="color:#55BBFF;"> Summary </a></strong><br />
</p>
<div id="X5341" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px;">  This program demonstrates run-time vertex displacement and normal calculation in the vertex shader.  During the program&#8217;s initialization a flat surface is created with a variable vertex resolution.  More vertices gives better looking results.  Inside the vertex shader the &#8220;Witch of Agnesi&#8221; function [ y = (8a^3) / (x^2 + 4a^2) ] is used to determine the surface displacement.However, it uses the distance from the vertex (x,z) to the origin (0,0) as the independent variable, instead of just using x.  The partial derivatives of the &#8220;Witch of Agnesi&#8221; function are hard-coded into the shader code and are used to calculate the normal, tangent, and binormal of each vertex on the graphics card during run-time.This allows the &#8220;bulge&#8221; in this demo to move up and down while maintaining correct diffuse and specular lighting.  </p>
<p>Note: the pebble texture and normal map were downloaded from TurboSquid.com.
</p>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X6334');return false;" style="color:#55BBFF;"> Code Sample </a><br />
</p>
<div id="X6334" style="display: none; background: transparent;">
<ul>
<li> <strong style="font-size: 12pt;"> Vertex Displacement and Normal Calculation in the Vertex Shader </strong>
<p><a href='http://www.orangutangular.com/wp-content/uploads/image-magnifier-demo-30.zip' style="color:#55BBFF;">image-magnifier-demo-30.zip</a></p>
<p><a style="color: #55bbff;" onclick="xcollapse('X6030');return false;" href="#"> View Code </a></p>
<table id="X6030" style="display: none; border: 1px solid #FFFFFF; padding: 10px; color:#000000; background-color: #FFFFFF;" border="0">
<tbody>
<tr >
<td >
<div style="font-size:11pt;">
<p>// This is the HLSL effect which creates the displacement and calculates the new normals, tangents, and binormals.<br />
// It then renders the scene using a directional light, specular highlights, a normal map, and a texture.</p>
<p>float4&#215;4 World;<br />
float4&#215;4 View;<br />
float4&#215;4 Projection;</p>
<p>float Ambient;<br />
float3 LightDirection;<br />
float3 CameraPosition;<br />
float SpecularPower;<br />
float3 LightStrength;</p>
<p>float BulgeWidth;			// width of the &#8220;bulge&#8221; displacement<br />
float BulgeHeight;			// height of the &#8220;bulge&#8221; displacement</p>
<p>Texture Image;<br />
sampler ImageSampler = sampler_state { texture = < Image >;<br />
	magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR;<br />
	AddressU = wrap; AddressV = wrap; };</p>
<p>Texture NormalMap;<br />
sampler NormalMapSampler = sampler_state { texture = < NormalMap >;<br />
	magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR;<br />
	AddressU = wrap; AddressV = wrap; };</p>
<p>struct VertexShaderInput<br />
{<br />
    float4 Position		:	POSITION0;<br />
	float3 Normal		:	NORMAL0;<br />
	float2 TexCoord		:	TEXCOORD0;<br />
};</p>
<p>struct VertexShaderOutput<br />
{<br />
	float4 Position		:	POSITION0;<br />
	float2 TexCoord		:	TEXCOORD0;<br />
	float3 LightDirT	:	TEXCOORD1;<br />
	float3 EyeDirection :	TEXCOORD2;<br />
};</p>
<p>void calcSurfaceHeightNormTanBinorm(float x, float z, out float y, out float3 normal, out float3 tangent, out float3 biNormal)<br />
{<br />
    // Use the &#8220;Witch of Agnesi&#8221; function [ y = (8a^3) / (x^2 + 4a^2) ] to determine the surface displacement<br />
     // However, use the distance from the vertex (x,z) to the origin (0,0) as the independent variable, instead of just using x.</p>
<p>    float dist = sqrt(x*x + z*z) / BulgeWidth;		// dist = distance from vertex to origin. Multiplying by BulgeWidth serves to widen the &#8220;bulge&#8221;<br />
    float bW_sqrd = pow(BulgeWidth, 2);<br />
    float h = BulgeHeight;</p>
<p>    // Determine height by using the &#8220;Witch of Agnesi&#8221; function, but using dist as the independent variable<br />
    y = 8*(h*h*h) / (dist*dist + 4*h*h);			</p>
<p>	// Use partial derivatives of &#8220;Witch of Agnesi&#8221; Curve to caluculate normal<br />
    normal.x = (-16 * h*h*h * x/bW_sqrd) / pow(((x*x + z*z)/bW_sqrd + 4*h*h), 2);<br />
    normal.z = (-16 * h*h*h * z/bW_sqrd) / pow(((x*x + z*z)/bW_sqrd + 4*h*h), 2);<br />
    normal.y = 1.0f;<br />
    normal = normalize(normal);</p>
<p>    // Use partial derivative dy/dx, holding z constant, to calculate tangent<br />
    tangent.x = 1.0f;<br />
    tangent.z = 0.0f;<br />
    tangent.y = (-16 * h*h*h * bW_sqrd*x) / pow( (bW_sqrd*(x*x + z*z) + 4*h*h), 2);<br />
    tangent = normalize(tangent);</p>
<p>    // Use cross product of normal and tangent to calculate biNormal<br />
    biNormal = cross(normal, tangent);<br />
}</p>
<p>VertexShaderOutput VertexShaderFunction(VertexShaderInput input)<br />
{<br />
    VertexShaderOutput output = (VertexShaderOutput)0;</p>
<p>    // Calculate the displaced height for this vertex as well as it&#8217;s new normal, tangent, and binormal<br />
    float3 normal, tangent, biNormal;<br />
    calcSurfaceHeightNormTanBinorm(input.Position.x, input.Position.z, input.Position.y, normal, tangent, biNormal);		// (y, normal, tangent, and biNormal are out parameters)</p>
<p>    float4 worldPosition = mul(input.Position, World);<br />
    float4 viewPosition = mul(worldPosition, View);<br />
    output.Position = mul(viewPosition, Projection);</p>
<p>	// Use normal, tangent, and biNormal to create a tangentToObject matrix<br />
	float3&#215;3 tangentToObject;<br />
	tangentToObject[0] = normalize(biNormal);<br />
	tangentToObject[1] = normalize(tangent);<br />
	tangentToObject[2] = normalize(normal);</p>
<p>	float3&#215;3 tangentToWorld = mul(tangentToObject, World);					// Create a tangentToWorld matrix to be used for tangent-space lighting</p>
<p>	output.LightDirT = mul(tangentToWorld, LightDirection);					// Take LightDirection from world to tangent space</p>
<p>	float3 worldEyeDirection = normalize(worldPosition &#8211; CameraPosition);<br />
	output.EyeDirection = mul(tangentToWorld, worldEyeDirection);			// Take worldEyeDirection from world to tangent space</p>
<p>	output.TexCoord = input.TexCoord;</p>
<p>    return output;<br />
}</p>
<p>float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0<br />
{<br />
	// Original Color:<br />
	float4 texColor = tex2D(ImageSampler, input.TexCoord);</p>
<p>	// Shading Contribution:<br />
	float3 normalFromNormalMap = tex2D(NormalMapSampler, input.TexCoord);<br />
    float3 normalT = (normalFromNormalMap &#8211; 0.5f) * 2.0f;<br />
    float shading = max(dot(-normalize(normalT), normalize(input.LightDirT)), 0);<br />
    shading *= LightStrength;</p>
<p>	// Specular Contribution:<br />
	float specular = 0.0f;<br />
	float3 reflection = -reflect(normalize(input.LightDirT), normalT);<br />
	specular = max(dot(normalize(reflection), normalize(input.EyeDirection)), 0);<br />
	specular = pow(specular, SpecularPower);<br />
	specular *= LightStrength;</p>
<p>	// Final Output Color:<br />
	float4 outColor = float4(0,0,0,1);<br />
    outColor.xyz = texColor * (Ambient + shading) + specular;<br />
    return outColor;<br />
}</p>
<p>technique Technique1<br />
{<br />
    pass Pass1<br />
    {<br />
        VertexShader = compile vs_2_0 VertexShaderFunction();<br />
        PixelShader = compile ps_2_0 PixelShaderFunction();<br />
    }<br />
}
</p></div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/run-time-vertex-displacement-and-normal-calculation-in-the-vertex-shader/feed/</wfw:commentRss>
		<slash:comments>2335</slash:comments>
		</item>
		<item>
		<title>Normal Map</title>
		<link>http://www.orangutangular.com/normal-map/</link>
		<comments>http://www.orangutangular.com/normal-map/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 05:39:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=420</guid>
		<description><![CDATA[
 








 This Shading Demo is an assignment I completed for a course called DirectX Programming.  The effect is programmed in High Level Shader Language (HLSL).  The main program is coded in C++ using DirectX 9.0.  Please open the links below to learn more. 


 Summary 


  This program applies a [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center;"><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693">
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693">
<p><a href="http://www.orangutangular.com/wp-content/uploads/normalmap_1.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/normalmap_1.jpg" alt="normalmap_1" title="normalmap_1" width="392" height="320" class="alignleft size-full wp-image-423" /></a></p>
<p></br></p>
<p style = "font-size: 12pt;"> This Shading Demo is an assignment I completed for a course called DirectX Programming.  The effect is programmed in High Level Shader Language (HLSL).  The main program is coded in C++ using DirectX 9.0.  Please open the links below to learn more. </p>
</table>
<p></br></p>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X8835');return false;" style="color:#55BBFF;"> Summary </a></strong><br />
</p>
<div id="X8835" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px;">  This program applies a brick-like normal map to a cube.  Although the cube is represented as only twelve triangles in memory, the normal map shader creates the illusion that it is much more detailed.  This effect is possible because the shader can process each pixel and adjust that pixel&#8217;s color based on the direction that light is shining upon it and the normal map texture being applied.
</p>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X6343');return false;" style="color:#55BBFF;"> Code Sample </a><br />
</p>
<table id = "X6343" style="display: none; border: 1px solid #FFFFFF; padding: 10px; color:#000000; background-color: #FFFFFF;" border="0" width="693">
<tbody>
<tr >
<td >
<div style="font-size:11pt;">
<p>// This is the HLSL effect file which creates the normal map effect</p>
<p>uniform extern float4&#215;4 WorldViewProj : WOLRDVIEWPROJECTION;<br />
uniform extern float4&#215;4 World : WORLD;<br />
uniform extern float3 gLightDir;</p>
<p>texture2D gDiffuseTexture;<br />
texture2D NormalMap;</p>
<p>sampler2D SAMPLER0 = sampler_state {<br />
	texture = (gDiffuseTexture);<br />
	MinFilter = Linear;<br />
	MagFilter = Linear;<br />
	MipFilter = Linear;<br />
	AddressU = Wrap;<br />
	AddressV = Wrap;<br />
	mipmaplodbias = 0.0;<br />
};</p>
<p>sampler2D SAMPLER1 = sampler_state {<br />
	texture = (NormalMap);<br />
	MinFilter = Linear;<br />
	MagFilter = Linear;<br />
	MipFilter = Linear;<br />
	AddressU = Wrap;<br />
	AddressV = Wrap;<br />
	mipmaplodbias = 0.0;<br />
};</p>
<p>struct VS_OUTPUT<br />
{<br />
	float4 position 	: POSITION;<br />
	float3 normal 		: TEXCOORD0;<br />
	float3 lightDirection 	: TEXCOORD1;<br />
	float2 uv 		: TEXCOORD2;<br />
};</p>
<p>VS_OUTPUT VSMain<br />
(<br />
	float4 inPosition  : POSITION,<br />
	float3 inNormal    : NORMAL,<br />
	float3 inBitangent : BINORMAL,<br />
	float2 inUv		   : TEXCOORD1<br />
)<br />
{<br />
	VS_OUTPUT Out = (VS_OUTPUT)0;</p>
<p>	float3 bitangent  = mul(inBitangent, World);<br />
	float3 normal 	  = mul(inNormal, World);<br />
	float3 tangent	  = cross(bitangent, normal);<br />
	float3&#215;3 rotation = float3&#215;3(tangent, bitangent, normal);</p>
<p>	Out.position = mul(inPosition, WorldViewProj);<br />
	Out.normal   = normalize(mul(inNormal, World));<br />
	Out.uv	     = inUv;<br />
	Out.lightDirection = mul(rotation, gLightDir);</p>
<p>	return Out;<br />
} </p>
<p>float4 PSMain( VS_OUTPUT In ) : COLOR<br />
{<br />
	// Sample the normal from the tangent-space normal map<br />
	float3 normal = tex2D(SAMPLER1, In.uv).xyz;</p>
<p>	// Unbias = convert from range [0,1] to range [-1,1]<br />
	normal = normal * 2.0 &#8211; 1.0;</p>
<p>	float nDotL = -1*dot(normal, In.lightDirection);<br />
	return float4(nDotL.xxx * tex2D(SAMPLER0, In.uv), 1);<br />
}</p>
<p>technique TransformTechnique<br />
{<br />
	pass P0<br />
	{<br />
		vertexShader = compile vs_2_0 VSMain();<br />
		pixelShader  = compile ps_2_0 PSMain();<br />
	}<br />
}
</p></div>
</td>
</tr>
</tbody>
</table>
</div>
</table>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/normal-map/feed/</wfw:commentRss>
		<slash:comments>1001</slash:comments>
		</item>
		<item>
		<title>Specular Shading and Environment Reflection Map</title>
		<link>http://www.orangutangular.com/specular-shading-and-environment-map/</link>
		<comments>http://www.orangutangular.com/specular-shading-and-environment-map/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 04:10:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=412</guid>
		<description><![CDATA[
 








 This Shading Demo is an assignment I completed for a course called DirectX Programming.  The effects are programmed in High Level Shader Language (HLSL).  The main program is coded in C++ using DirectX 9.0.  Please open the links below to learn more. 


 Summary 


 Two effects are demonstrated here: [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center;"><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693">
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693">
<p><a href="http://www.orangutangular.com/wp-content/uploads/speclightenvmap_3.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/speclightenvmap_3-1024x826.jpg" alt="speclightenvmap_3" title="speclightenvmap_3" width="392" height="320" class="alignleft size-large wp-image-674" /></a></p>
<p></br></p>
<p style = "font-size: 12pt;"> This Shading Demo is an assignment I completed for a course called DirectX Programming.  The effects are programmed in High Level Shader Language (HLSL).  The main program is coded in C++ using DirectX 9.0.  Please open the links below to learn more. </p>
</table>
<p></br></p>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X10044');return false;" style="color:#55BBFF;"> Summary </a></strong><br />
</p>
<div id="X10044" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px;"> Two effects are demonstrated here: Specular Lighting and an Environment Reflection Map.  The obsidian cube has the specular lighting effect, which gives it the shiny look.  The other cube has the environment reflection map giving it the appearance that it is mirrored.  The effect is more dramatic when the cubes are seen moving.
</p>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X7881');return false;" style="color:#55BBFF;"> Code Sample </a><br />
</p>
<table id = "X7881" style="display: none; border: 1px solid #FFFFFF; padding: 10px; color:#000000; background-color: #FFFFFF;" border="0" width="693">
<tbody>
<tr >
<td >
<div style="font-size:11pt;">
<p>// This is the HLSL effect file which creates the Specular Lighting effect</p>
<p>uniform extern float4&#215;4 WorldViewProj : WOLRDVIEWPROJECTION;<br />
uniform extern float4&#215;4 World : WORLD;<br />
uniform extern float3 gEyePosition;<br />
uniform extern float3 gLightDir;</p>
<p>texture2D gNormalMap;</p>
<p>sampler2D normalMap = sampler_state{<br />
	texture = (gNormalMap);<br />
};</p>
<p>struct VS_OUTPUT<br />
{<br />
        float4 position			: POSITION;<br />
        float3 normal			: TEXCOORD0;<br />
        float2 uv				: TEXCOORD1;<br />
        float3 lightDirection	: TEXCOORD2;<br />
        float3 eyeDirection		: TEXCOORD3;<br />
};</p>
<p>VS_OUTPUT VSMain<br />
(<br />
        float4 inPosition : POSITION,<br />
        float3 inNormal   : NORMAL,<br />
        float3 inTangent   : TANGENT,<br />
        float2 inUv       : TEXCOORD0<br />
)<br />
{<br />
        VS_OUTPUT Out = (VS_OUTPUT)0;</p>
<p>        float3 tangent   =	mul(inTangent, World);<br />
        float3 normal    =	mul(inNormal, World);<br />
        float3 bitangent =	cross(tangent, normal);</p>
<p>        float3&#215;3 worldToTangent = float3&#215;3(tangent, bitangent, normal);</p>
<p>        Out.position = mul(inPosition, WorldViewProj);<br />
        Out.normal	 = normalize(mul(inNormal, World));<br />
        Out.uv       = inUv;<br />
        Out.lightDirection = mul(gLightDir, worldToTangent);</p>
<p>        float3 objectSpaceEyeDir = ( inPosition &#8211; gEyePosition).xyz;<br />
        float3 worldSpaceEyeDir = mul( objectSpaceEyeDir, (float3&#215;3)World );<br />
        Out.eyeDirection = mul(worldSpaceEyeDir, worldToTangent);</p>
<p>        return Out;<br />
}</p>
<p>float4 PSMain( VS_OUTPUT In ) : COLOR<br />
{<br />
        //sample the normal from the tangent-space normal map<br />
        float3 normal = tex2D(normalMap, In.uv);</p>
<p>        //Unbias = convert from range 0.0 to 1.0<br />
        //to range -1.0 to 1.0<br />
        normal = normal * 2.0 &#8211; 1.0;</p>
<p>        float3 eyeDirection = normalize(In.eyeDirection);<br />
        float3 reflection = reflect(eyeDirection, normal);<br />
        float rDotL = saturate(dot(reflection, In.lightDirection ));<br />
        float specularity = 8.0;<br />
        float specular = pow(rDotL, specularity );</p>
<p>        return float4(specular.xxx, 1);<br />
}</p>
<p>technique TransformTechnique<br />
{<br />
        pass P0<br />
        {<br />
                vertexShader = compile vs_2_0 VSMain();<br />
                pixelShader  = compile ps_2_0 PSMain();<br />
        }<br />
} </p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</table>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/specular-shading-and-environment-map/feed/</wfw:commentRss>
		<slash:comments>2087</slash:comments>
		</item>
		<item>
		<title>Eat Your Words</title>
		<link>http://www.orangutangular.com/eat-your-words/</link>
		<comments>http://www.orangutangular.com/eat-your-words/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 03:41:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=406</guid>
		<description><![CDATA[
 








 Eat Your Words is a game I made in a Computer Science 2 course at Front Range Community College.  It is a Console-Based Game programmed in C++.  Please open the links below to learn more. 


 Gameplay Summary 


 Eat Your Words is a cross between Tetris and a Word Search. [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center;"><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693">
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693">
<p><a href="http://www.orangutangular.com/wp-content/uploads/eatyourwords_1.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/eatyourwords_1.jpg" alt="eatyourwords_1" title="eatyourwords_1" width="392" height="320" class="alignleft size-full wp-image-409" /></a></p>
<p></br></p>
<p style = "font-size: 12pt; color:#FFFFFF;"> Eat Your Words is a game I made in a Computer Science 2 course at Front Range Community College.  It is a Console-Based Game programmed in C++.  Please open the links below to learn more. </p>
</table>
<p></br></p>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X5785');return false;" style="color:#55BBFF;"> Gameplay Summary </a></strong><br />
</p>
<div id="X5785" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px; color:#FFFFFF;"> Eat Your Words is a cross between Tetris and a Word Search.  You are given blocks of letters to rotate and then drop down.  The object of the game is to stack your blocks in such a way as to form English words.  When a word is formed it is highlighted and then removed.  Also if a definition for the word is available then it is provided, thus allowing the player to strengthen her vocabulary while she plays.  When a word is removed, any blocks which are now unsupported fall until they have some support (either by the &#8220;ground&#8221; or by another block).  Points are scored according to the length of your word and the rarity of the letters in your word.  Once a given amount of words have been made, points are tallied and the game ends.
</p>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X3448');return false;" style="color:#55BBFF;"> Programming Features </a></strong><br />
</p>
<div id="X3448" style="display: none; background: transparent;">
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>Gameplay: </strong> Recursive Algorithm determines which blocks are unsupported, Real-Time Keyboard Input
</li>
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>Data Structures: </strong> Hash Table stores English Words/Definitions
</li>
<li style="margin-left:50pt;font-size:12pt; color:#FFFFFF;"><strong>User Interface: </strong> Formatted Console Output, Menu navigation
</li>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X732');return false;" style="color:#55BBFF;"> Code Sample </a><br />
</p>
<table id = "X732" style="display: none; border: 1px solid #FFFFFF; padding: 10px; color:#000000; background-color: #FFFFFF;" border="0" width="693">
<tbody>
<tr >
<td >
<div style="font-size:11pt;">
COMING SOON
</div>
</td>
</tr>
</tbody>
</table>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X5172');return false;" style="color:#55BBFF;"> Screenshots   </a></strong><br />
</p>
<div id="X5172" style="display: none; background: transparent;">
<div id="attachment_507" class="wp-caption alignleft" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/eatyourwordstitle.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/eatyourwordstitle-300x255.jpg" alt="Different options for gameplay" title="eatyourwordstitle" width="300" height="255" class="size-medium wp-image-507" /></a><p class="wp-caption-text">Different options for gameplay</p></div>
<div id="attachment_508" class="wp-caption alignleft" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/eatyourwords_2.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/eatyourwords_2-300x255.jpg" alt="Two words in one" title="eatyourwords_2" width="300" height="255" class="size-medium wp-image-508" /></a><p class="wp-caption-text">Two words in one</p></div>
</div>
</div>
</table>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/eat-your-words/feed/</wfw:commentRss>
		<slash:comments>2005</slash:comments>
		</item>
		<item>
		<title>Safety Last</title>
		<link>http://www.orangutangular.com/safety-last/</link>
		<comments>http://www.orangutangular.com/safety-last/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 03:29:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=397</guid>
		<description><![CDATA[
 








 Safety Last is a game I worked on with a team of UAT students.  It was developed in Adobe Flash using ActionScript 2.0.  Please open the links below to learn more. 


 Gameplay Summary 


 Safety Last is a series of wacky mini-games involving airplane safety and lack thereof.  The [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center;"><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693">
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693">
<p><a href="http://www.orangutangular.com/wp-content/uploads/safetylasttitle.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/safetylasttitle.jpg" alt="safetylasttitle" title="safetylasttitle" width="392" height="320" class="alignleft size-full wp-image-398" /></a></p>
<p></br></p>
<p style = "font-size: 12pt; color:#FFFFFF;"> Safety Last is a game I worked on with a team of UAT students.  It was developed in Adobe Flash using ActionScript 2.0.  Please open the links below to learn more. </p>
</table>
<p></br></p>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X986');return false;" style="color:#55BBFF;"> Gameplay Summary </a></strong><br />
</p>
<div id="X986" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px;color:#FFFFFF;"> Safety Last is a series of wacky mini-games involving airplane safety and lack thereof.  The games artists and designers modeled the games art after the unique art style of airplane safety pamphlets.  It should be noted that only two out of the eight planned mini-games were completed and so Safety Last, as presented here, is technically only a Demo.  However the framework of the game, which I designed and programmed, is complete.  It includes a completed menu and level selection system, as well as a template of code to use in the creation of future Safety Last mini-games.
</p>
<p style="font-size: 12pt; margin-left: 50px;color:#FFFFFF;"> The first mini-game consists of strapping together a seat belt for a little girl by using the keyboard.  The belt buckles are sensitive though and obtain momentum when you nudge them, and the girl periodically swipes the belts away.  Thus the game requires patience and precise control.
</p>
<p style="font-size: 12pt; margin-left: 50px;color:#FFFFFF;"> In the second mini-game you must place an oxygen mask over a man&#8217;s face before the plane fills with smoke.  The mask will always face towards the mouse pointer.  When the mouse is clicked air will shoot out of the mask away from the mouse pointer, thus propelling the mask towards the pointer.  The player must guide the mask over the man&#8217;s head gently while avoiding falling luggage.  When the mask is secured the player has won.
</p>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X3815');return false;" style="color:#55BBFF;"> Programming Features </a></strong><br />
</p>
<div id="X3815" style="display: none; background: transparent;">
<li style="margin-left:50pt; font-size:12pt;color:#FFFFFF;"><strong>Gameplay: </strong> MovieClip Hit-Testing
</li>
<li style="margin-left:50pt; font-size:12pt;color:#FFFFFF;"><strong>Physics: </strong> Spring Physics, Gravity, Momentum, Force Vectors
</li>
<li style="margin-left:50pt;font-size:12pt;color:#FFFFFF;"><strong>User Interface: </strong> Scrollable Level Selection Menu, Load/Play Sound Effects
</li>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X1188');return false;" style="color:#55BBFF;"> Code Samples </a><br />
</p>
<table id = "X1188" style="display: none; border: 1px solid #FFFFFF; padding: 10px; color:#000000; background-color: #FFFFFF;" border="0" width="693">
<tbody>
<tr >
<td >
<div style="font-size:11pt;">
COMING SOON
</div>
</td>
</tr>
</tbody>
</table>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X2713');return false;" style="color:#55BBFF;"> Screenshots   </a></strong><br />
</p>
<div id="X2713" style="display: none; background: transparent;color:#FFFFFF;">
<div id="attachment_470" class="wp-caption alignleft" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/safetylastlevel_1.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/safetylastlevel_1-300x245.jpg" alt="Buckle the belt before time runs out!" title="safetylastlevel_1" width="300" height="245" class="size-medium wp-image-470" /></a><p class="wp-caption-text">Buckle the belt before time runs out!</p></div>
<div id="attachment_472" class="wp-caption alignright" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/safetylastlevel_2.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/safetylastlevel_2-300x245.jpg" alt="Get that mask on!" title="safetylastlevel_2" width="300" height="245" class="size-medium wp-image-472" /></a><p class="wp-caption-text">Get that mask on!</p></div>
<div id="attachment_469" class="wp-caption alignleft" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/safetylastlevelselect.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/safetylastlevelselect-300x245.jpg" alt="Choose a mini-game" title="safetylastlevelselect" width="300" height="245" class="size-medium wp-image-469" /></a><p class="wp-caption-text">Choose a mini-game</p></div>
</div>
</div>
</table>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/safety-last/feed/</wfw:commentRss>
		<slash:comments>2025</slash:comments>
		</item>
		<item>
		<title>Ricochet</title>
		<link>http://www.orangutangular.com/ricochet/</link>
		<comments>http://www.orangutangular.com/ricochet/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 02:55:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=389</guid>
		<description><![CDATA[
 






Ricochet is a game I developed for a course at UAT called Game Programming in C++.  It was developed in C++ using the Allegro Game Library.  Please open the links below to learn more.

 Gameplay Summary 

Ricochet is a 2D, tile-based, turn-based strategy game.  Players may choose from two character classes [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center;"><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693">
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693"><a href="http://www.orangutangular.com/wp-content/uploads/ricochet_1.jpg"><img class="alignleft size-full wp-image-390" title="ricochet_1" src="http://www.orangutangular.com/wp-content/uploads/ricochet_1.jpg" alt="ricochet_1" width="392" height="320" /></a></p>
<p style="font-size: 12pt; color:#FFFFFF;">Ricochet is a game I developed for a course at UAT called Game Programming in C++.  It was developed in C++ using the Allegro Game Library.  Please open the links below to learn more.</p>
</table>
<p><strong style="font-size: 12pt;"><a onclick="xcollapse('X4601');return false;" href="#" style="color:#55BBFF;"> Gameplay Summary </a></strong></p>
<div id="X4601" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px; color:#FFFFFF;">Ricochet is a 2D, tile-based, turn-based strategy game.  Players may choose from two character classes and then go head to head or face off against a challenging AI opponent.  Each turn, a player may move a certain amount of spaces and perform an attack.  The Shooter character class shoots a projectile which can ricochet off of walls multiple times.  The Bomber character class throws bombs over walls causing radial damage to a nearby opponent.  Players collect upgrades as they play which boost various player stats including Life, Attack Power, Armor, Speed, and Special Attack.  Special Attack upgrades a player&#8217;s given weapon, either allowing for more Ricochets per Shot or more Bounces per Bomb.  Players play until one of them reaches zero hit points, at which point the match is over and a new one may begin.</p>
</div>
<p><strong style="font-size: 12pt;"><a onclick="xcollapse('X1321');return false;" href="#" style="color:#55BBFF;"> Programming Features </a></strong></p>
<div id="X1321" style="display: none; background: transparent;">
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>Gameplay: </strong> Customizable Recursive Random Map Generator, Pre-Fire Ricochet Calculation and Display, Line-Line-Segment Collision Detection</li>
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>AI: </strong> Recursive AI Algorithm for CPU Opponent, Pre-Game Map Analysis Algorithm</li>
<li style="margin-left:50pt;font-size:12pt; color:#FFFFFF;"><strong>Graphics: </strong> Allegro Game Library, Animated Sprite Class, Drawing Lines To Buffers</li>
</div>
<p><strong style="font-size: 12pt;"> <a onclick="xcollapse('X2076');return false;" href="#" style="color:#55BBFF;"> Code Samples </a></strong></p>
<div id="X2076" style="display: none; background: transparent;">
<ul>
<li> <strong style="font-size: 12pt; color:#FFFFFF;"> Random Tile Map Generation Using Recursion </strong>
<div style="font-size:11pt; color:#FFFFFF;">
<p>The following code creates a random tile map using recursion.  createRandomMap() is called from main() or some other function.  It first defaults the tile map to all wall tiles, and then calls the recursive function, createRandomHall().  createRandomHall() creates a straght hall of open tiles, one tile at a time.  After creating each tile, there is a chance that createRandomHall() will call itself, giving the current tile as the new start tile, and using a new random direction.  When the parent hall is returned to it will continue growing until a given max length is reached, another open tile is reached, or the edge of the map is reached.  Thus, the map grows like a tree, with each hall being a branch, until a given number of open tiles have been created.</p>
<p>Additionally, there are three key parameters which may be customized when generating a random map: The maximum length of a hall, the number of open tiles, and the map density which controls how often a new hall will branch off.</p>
</div>
<p><a style="color: #55bbff;" href='http://www.orangutangular.com/wp-content/uploads/ricochetrandommapcode.zip'>RicochetRandomMapCode.zip</a></p>
<p><a style="color: #55bbff;" onclick="xcollapse('X9385');return false;" href="#"> View Code </a></p>
<table id="X9385" style="display: none; border: 1px solid #FFFFFF; padding: 10px; color:#000000; background-color: #FFFFFF;" border="0">
<tbody>
<tr>
<td>
<pre style="font-size: 8pt; font-family: consolas; width:573px;">

const int MAX_HALL_LENGTH 6	// Maximum length a given hall may grow to during random map creation
const int NUM_OPEN_TILES 100	// Number of non-wall tiles in a given random map
const int MAP_DENSITY 16	// Determines chance of a new hall branching off during random map creation.
const bool ADD_OUTER_RING_TO_MAP true	// Whether or not an outer ring of open tiles should be added to a map

/* . . . */

// FUNCTION clearLevel() :  clears every tile in mapArray[][] to a wall tile.
void clearLevel()
{
	// clear level to blanks
	int x, y;
	for (x = 0; x < NUM_COLS; x++)
		for (y = 0; y < NUM_ROWS; y++)
			mapArray[x][y] = 'W';
}

// FUNCTION createRandomMap() : Creates a random tile map.
void createRandomMap()
{
	// mapNumber serves as an ID for the map being generated.
	mapNumber++;

	do
	{
		// tileCounter will hold the number of open tiles which have been created
		tileCounter = 0;	

		// make every tile a wall tile to start.
		clearLevel();		

		// generate a random tile and direction to begin "branching out" from
		int startX = 1 + rand()%(NUM_COLS - 1);
		int startY = 1 + rand()%(NUM_ROWS - 1);
		int startDir = rand()%4;

		// initial call to recursive function:
		createRandomHall(startX, startY, startDir); 

	// if NUM_OPEN_TILES of open tiles were not created, then try again
	}while(tileCounter != NUM_OPEN_TILES);

	// Add an outer ring of open tiles for better map design
	if(ADD_OUTER_RING_TO_MAP) { addOuterRingToMap(); }
}

// FUNCTION createRandomHall() : Recursively creates the random halls that make up a map.
// PARAMS : startX and startY are where a given hall will begin, startDir is the direction it will "move" in
void createRandomHall(int startX, int startY, int startDir)
{
	int randNum = 0;
	int randTileType = 0;	// used to choose a random collectible upgrade to place on certain tiles.
	int curX = startX;
	int curY = startY;
	int curDir = startDir;
	int hallLength = 0;

	while( tileCounter < NUM_OPEN_TILES )
	{
		// if the hall hasn't extended too far, and the current tile is a wall tile and is not on the outer edge of the map...
		if( (hallLength < MAX_HALL_LENGTH) &#038;&#038; (mapArray[curX][curY] == 'W') &#038;&#038;
			!( curX <= 0 || curX >= NUM_COLS-1 || curY <= 0 || curY >= NUM_ROWS-1 ) )
		{
			if(tileCounter == 0) { mapArray[curX][curY] = '+'; }	// assign Player 1 start position
			else if(tileCounter == NUM_OPEN_TILES-1) { mapArray[curX][curY] = '-'; }// assign Player 2 start position
			else
			{
				if(tileCounter%20 == 5)	// 1 in 20 chance of placing a collectible upgrade at current tile
				{
					randTileType = 1 + rand()%5;	// choose random upgrade
					mapArray[curX][curY] = char(int('0') + randTileType);	// assign upgrade to this tile
				}
				else
					mapArray[curX][curY] = ' ';	// otherwise tile is open without a collectible upgrade
			}
			tileCounter++; hallLength++;

			randNum = rand()%MAP_DENSITY;	// make random integer between 0 and MAP_DENSITY
			// if randNum is between 1 and 4, then branch off
			switch(randNum) {
						// branch NORTH
				case 1:	if(curDir != NORTH) { createRandomHall(curX, curY-1, NORTH); }		break;						// branch EAST
				case 2:	if(curDir != EAST)  { createRandomHall(curX+1, curY, EAST);	 }		break;						// branch SOUTH
				case 3:	if(curDir != SOUTH) { createRandomHall(curX, curY+1, SOUTH); }		break;						// branch WEST
				case 4:	if(curDir != WEST)  { createRandomHall(curX-1, curY, WEST);	 }		break;
				default: break;
			}

			// if randNum was 5 or higher, or we have returned from a recursive call, we now continue down 				this hall in the same direction.
			switch(curDir) {
				case NORTH: curY--;	break;
				case EAST:  curX++;	break;
				case SOUTH: curY++;	break;
				case WEST:  curX--;	break;
			}
		}
		else { break; }
	}

	return;
}

// FUNCTION addOuterRingToMap() : Adds an outer ring of open tiles for better map design
void addOuterRingToMap()
{
	int x = 0, y = 0;
	for(x = 1; x < NUM_COLS-1; x++)
	{
		if(mapArray[x][1] == 'W')	// if tile is a wall (and not a start position or collectible upgrade)...
			mapArray[x][1] = ' ';	// make it an open tile
		if(mapArray[x][NUM_ROWS-2] == 'W')
			mapArray[x][NUM_ROWS-2] = ' ';
	}
	for(y = 1; y < NUM_ROWS-1; y++)
	{
		if(mapArray[1][y] == 'W')
			mapArray[1][y] = ' ';
		if(mapArray[NUM_COLS-2][y] == 'W')
			mapArray[NUM_COLS-2][y] = ' ';
	}
}
</pre>
</td>
</tr>
</tbody>
</table>
</div>
<p><strong style="font-size: 12pt;"><a onclick="xcollapse('X6235');return false;" href="#" style="color:#55BBFF;"> Screenshots </a></strong></p>
<div id="X6235" style="display: none; background: transparent; color:#FFFFFF;">COMING SOON</div>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/ricochet/feed/</wfw:commentRss>
		<slash:comments>2135</slash:comments>
		</item>
		<item>
		<title>Flocking 3D</title>
		<link>http://www.orangutangular.com/flocking-3d/</link>
		<comments>http://www.orangutangular.com/flocking-3d/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 02:19:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Project]]></category>
		<category><![CDATA[Add new tag]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=378</guid>
		<description><![CDATA[
 








 Flocking 3D is a simulation I developed for a course at UAT called Artificial Life Programming.  It was developed in C++ using DirectX 9.0.  Please open the links below to learn more. 



 Simulation Summary 


 This Flocking Simulation is an example of an Agent-Based Model.  An agent-based model is [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center;"><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693">
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693">
<p><a href="http://www.orangutangular.com/wp-content/uploads/flocking3d_3.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/flocking3d_3-1024x640.jpg" alt="flocking3d_3" title="flocking3d_3" width="392" height="280" class="alignleft size-large wp-image-381" /></a></p>
<p></br></p>
<p style = "font-size: 12pt;"> Flocking 3D is a simulation I developed for a course at UAT called Artificial Life Programming.  It was developed in C++ using DirectX 9.0.  Please open the links below to learn more. </p>
</table>
<p></br><br />
<strong style="font-size: 12pt;"><br />
<a href="#" onclick="xcollapse('X9');return false;" style="color:#55BBFF;"> Simulation Summary </a></strong><br />
</p>
<div id="X9" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px; color:#FFFFFF;"> This Flocking Simulation is an example of an Agent-Based Model.  An agent-based model is a simulation of entities acting and interacting according to their own self-contained rules.  Each agent (&#8221;Boids&#8221; as they are classically referred to as), follows three basic rules:</p>
<div style="font-size: 12pt; margin-left: 50px; color:#FFFFFF;">
   &nbsp;&nbsp;&nbsp;1. Separation &#8211; Avoid crowding nearby Boids<br />
   &nbsp;&nbsp;&nbsp;2. Alignment &#8211; Steer towards average heading of nearby Boids<br />
   &nbsp;&nbsp;&nbsp;3. Cohesion &#8211; Steer towards average position of nearby Boids
</div>
<p></br></p>
<div style="font-size: 12pt; margin-left: 50px; color:#FFFFFF;">
With these three rules alone, a random configuration of Boids will inevitably end up flocking together.  This is a classic example of complex behavior emerging from simple rules.
</div>
</p>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X6318');return false;" style="color:#55BBFF;"> Programming Features </a></strong><br />
</p>
<div id="X6318" style="display: none; background: transparent; color:#FFFFFF;">
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>Simulation: </strong> Torroidal Environment, Flocking Algorithm
</li>
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>Data Structures: </strong> 2D array of Linked Lists Manages the Efficient Comparison of &#8220;Boids&#8221; with eachother
</li>
<li style="margin-left:50pt;font-size:12pt; color:#FFFFFF;"><strong>Graphics: </strong> DirectX Primitives, DirectX Matrix Transformations
</li>
<li style="margin-left:50pt;font-size:12pt; color:#FFFFFF;"><strong>User Interface: </strong> Mouse Controlled 3D Camera with Rotation and Zoom
</li>
</div>
<p><strong style="font-size: 12pt;"> <a href="#" onclick="xcollapse('X5940');return false;" style="color:#55BBFF;"> Code Samples </a></strong><br />
</p>
<div id="X5940" style="display: none; background: transparent;">
<ul>
<li>
<strong style="font-size: 12pt; color:#FFFFFF;"> 3D Space Partitioning for Efficiency </strong></p>
<div style="font-size:11pt; color:#FFFFFF;">
<p>The following code is a function which is called once per frame.  It takes as arguments an array of Boids (where Boid is a class representing one of the birds) and a 2D array of doubly-linked lists of Boid pointers called boidCollection.  Here is a brief description of the function&#8217;s purpose: It organizes the array of Boids based on their current position in order to provide for extremely efficient comparisons between nearby Boids later on. </p>
<p>The boidCollection, being a 2D array, &#8220;maps&#8221; to the space in which the Boids are flying around.  The Boid&#8217;s position determines what index it will belong to within boidCollection. This way, when it comes time to check for collisions or other comparative operations, a Boid only needs to be compared to the Boids in it&#8217;s own partition of space or to those directly surrounding it, and those relevant Boids may be found by moving through the linked lists contained in the Boid&#8217;s corresponding boidCollection index and the Lists in the &#8220;surrounding&#8221; indexes.  The reason this function must be called once per frame is because a Boid is always moving and therefore its corresponding index in boidCollection will need to change whenever it crosses over to another partition of space.</p>
</div>
<p><a href='http://www.orangutangular.com/wp-content/uploads/flocking3dboidcollectioncode.zip' style = "color:#55BBFF;">Flocking3DboidCollectionCode.zip</a></p>
<p><a href="#" onclick="xcollapse('X5813');return false;" style = "color:#55BBFF;"> View Code </a><br />
</p>
<table id = "X5813" style=" display: none; border: 1px solid #FFFFFF; padding: 10px; color:#000000; background-color: #FFFFFF;" border="0">
<tbody>
<tr >
<td >
<pre style="font-size: 8pt; font-family: consolas; width:573px;">

// FUNCTION updateBoidCollection(): Called once every frame.  Reorganizes the
// boidCollection structure based on new positions of Boids.
void updateBoidCollection( Boid boidArray[],
                                       Array2D< DLinkedList< Boid* > > &#038;boidCollection )
{
	int oldXTile = 0;	// the X tile that the Boid was on in the previous frame
	int oldZTile = 0;	// the Z tile that the Boid was on in the previous frame
	int newXTile = 0;  // the X tile that the Boid will move to
	int newZTile = 0;  // the Z tile that the Boid will move to

	DListIterator< Boid* > crntBoid;	// an iterator that's used to move through every Boid in a given tile

	for( int i = 0; i < NUM_BOIDS; i++ )	// for all Boids:
	{
		// assign old tile and new tile
		oldXTile = boidArray[i].getXTile();
		oldZTile = boidArray[i].getZTile();
		newXTile = floor( ( boidArray[i].getXPos() + (0.5 * ROOM_LENGTH) ) / TILE_SIZE);
		newZTile = floor( ( boidArray[i].getZPos() + (0.5 * ROOM_WIDTH) ) / TILE_SIZE);

		// if old tile and new tile are not the same then boidCollection needs to reflect this change
		if( (newXTile != oldXTile) || (newZTile != oldZTile) )
		{
                        // assign iterator to the DLinkedList at new tile
			crntBoid = boidCollection.Get( oldXTile, oldZTile ).GetIterator();	

			// iterate through the list until you find the Boid
			while( crntBoid.Item()->getID() != boidArray[i].getID() &#038;&#038; crntBoid.Valid() )
			{
				crntBoid.Forth();
			}
			if( crntBoid.Valid() )
                       // if you found the Boid (which you should unless an error has occurred)...
			{
				// remove its node from the list
				boidCollection.Get( oldXTile, oldZTile ).RemoveWithoutDeleting(crntBoid);
			}
			else
			{
				cout << "Error in reading a DLinkedList.\n";
			}
			// append the Boid to the list at the new tile's location
			boidCollection.Get( newXTile, newZTile ).Append( &#038;boidArray[i] );
			boidArray[i].setXTile( newXTile );		// give Boid its new tile position
			boidArray[i].setZTile( newZTile );
		}
	}
}
</pre>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X3563');return false;" style="color:#55BBFF;"> Screenshots   </a></strong><br />
</p>
<div id="X3563" style="display: none; background: transparent;">
<div id="attachment_498" class="wp-caption alignleft" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/flocking3dtitle.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/flocking3dtitle-300x187.jpg" alt="The info and instructions" title="flocking3dtitle" width="300" height="187" class="size-medium wp-image-498" /></a><p class="wp-caption-text">The info and instructions</p></div>
<div id="attachment_502" class="wp-caption alignleft" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/flocking3d2.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/flocking3d2-300x187.jpg" alt="It begins in chaos" title="flocking3d2" width="300" height="187" class="size-medium wp-image-502" /></a><p class="wp-caption-text">It begins in chaos</p></div>
<div id="attachment_501" class="wp-caption alignleft" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/flocking3d_1.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/flocking3d_1-300x187.jpg" alt="Flocking patterns soon become apparent" title="flocking3d_1" width="300" height="187" class="size-medium wp-image-501" /></a><p class="wp-caption-text">Flocking patterns soon become apparent</p></div>
</div>
</div>
</table>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/flocking-3d/feed/</wfw:commentRss>
		<slash:comments>2693</slash:comments>
		</item>
		<item>
		<title>Charged Particles (original)</title>
		<link>http://www.orangutangular.com/charged-particles/</link>
		<comments>http://www.orangutangular.com/charged-particles/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 01:24:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Project]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.orangutangular.com/?p=355</guid>
		<description><![CDATA[
 








 Charged Particles is a simulation I developed for a course at UAT called Advanced Game Physics Programming.  It was developed in C++ using DirectX 9.0.  Please open the links below to learn more. 


 Simulation Summary 


 What happens when a thousand particles are given positive and negative charges proportional to [...]]]></description>
			<content:encoded><![CDATA[<p id="top" />
<p style="text-align: center; "><span style="font-family:Garamond;font-size:12pt;"><strong> </strong></span></p>
<div>
<table style="border-collapse: collapse; height: 56px;" border="0" width="693" >
<tbody>
<tr style="height: 102px;">
<td style="padding-left:120px;padding-right:120px;">
<table style="border-collapse: collapse; padding-left: 7px; padding-right: 7px; height: 6px;" border="0" width="693">
<p><a href="http://www.orangutangular.com/wp-content/uploads/chargedparticles_1.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/chargedparticles_1-1024x640.jpg" alt="chargedparticles_1" title="chargedparticles_1" width="392" height="280" class="alignleft size-large wp-image-363" /></a></p>
<p></br></p>
<p style = "font-size: 12pt; color:#FFFFFF;"> Charged Particles is a simulation I developed for a course at UAT called Advanced Game Physics Programming.  It was developed in C++ using DirectX 9.0.  Please open the links below to learn more. </p>
</table>
<p></br></p>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X4980');return false;" style="color:#55BBFF;"> Simulation Summary </a></strong><br />
</p>
<div id="X4980" style="display: none; background: transparent;">
<p style="font-size: 12pt; margin-left: 50px; color:#FFFFFF;"> What happens when a thousand particles are given positive and negative charges proportional to their mass and allowed to collide and interact in 3D?  Molecules are formed!  This simulation demonstrates this on a very rough level, allowing the user to tweak several parameters including the number of particles, what types of charges they have, and the ratio of the repelling force to the attracting force.  Under the right conditions an initial group of randomly distributed particles will coalesce, forming balls, strings, rings, and even strands which resemble the double helix structure found in our DNA!
</p>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X8017');return false;" style="color:#55BBFF;"> Programming Features </a></strong><br />
</p>
<div id="X8017" style="display: none; background: transparent;">
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>Physics: </strong> Realistic Sphere-Sphere Collision Detection/Reaction, Conservation of Momentum, Coulomb&#8217;s Law, Vector Class, Matrix Class
</li>
<li style="margin-left:50pt;font-size:12pt; color:#FFFFFF;"><strong>Graphics: </strong> DirectX Primitives, DirectX Matrix Transformations, Alpha Blending
</li>
<li style="margin-left:50pt; font-size:12pt; color:#FFFFFF;"><strong>Data Structures: </strong> 3D array of Linked Lists Manages the Efficient Comparison of Particles
</li>
<li style="margin-left:50pt;font-size:12pt; color:#FFFFFF;"><strong>User Interface: </strong> Mouse Controlled 3D Camera with Rotation and Zoom
</li>
</div>
<p><strong style="font-size: 12pt;"> <a href="#" onclick="xcollapse('X2034');return false;" style="color:#55BBFF;"> Code Samples </a></strong><br />
</p>
<div id="X2034" style="display: none; background: transparent;">
<ul>
<li>
<strong style="font-size: 12pt; color:#FFFFFF;"> Sphere-Sphere Collision Response </strong></p>
<div style="font-size:11pt; color:#FFFFFF;">
<p>The following code is a function which is called whenever two sphere&#8217;s collide in 3D space.  It receives as arguments an array of Spheres (also referred to as point masses), a 3D Vector representing the distance between the two spheres, a double containing the amount of time which has passed since the last frame, and the indexes of the two colliding point masses within the pt_Masses array.</p>
<p>Nothing is returned, however the two spheres receive new velocities based on their initial velocities, relative positions, masses, and coefficients of restitution (elasticity). </p>
<p>Also note that, if the spheres are overlapping, they are each moved apart by half of the distance between them so that they are barely touching.</p>
</div>
<p><a href='http://www.orangutangular.com/wp-content/uploads/chargedparticlescollisioncode.zip' style = "color:#55BBFF;">ChargedParticlesCollisionCode.zip</a></p>
<p><a href="#" onclick="xcollapse('X8276');return false;" style = "color:#55BBFF;"> View Code </a><br />
</p>
<table id = "X8276" style="display: none; border: 1px solid #FFFFFF; padding: 10px; color:#000000; background-color: #FFFFFF;" border="0">
<tbody>
<tr >
<td >
<pre style="font-size: 8pt; font-family: consolas; width:573px;">

// FUNCTION HandleCollision() : Handles collisions between spheres
void HandleCollision(POINT_MASS pt_Masses[], Vector3D_d &#038;separationDistance, double &#038;changeInTime, int i, int j)
{
	// Create a unit length vector representing the angle of collision:
	Vector3D_d unitNormal = separationDistance;
	unitNormal.normalize();

	// Find the new velocities of both objects based off of their velocities prior to collision:
	double velocity_1 = pt_Masses[i].getLinearVelocity().dotProduct(unitNormal);
	double velocity_2 = pt_Masses[j].getLinearVelocity().dotProduct(unitNormal);

	// Calculate the average elasticity between the two spheres:
	double average_E = ( pt_Masses[i].getElasticity() + pt_Masses[j].getElasticity() ) / 2;

	// Use the equations for elastic collision response to calculate the final velocities:
	double finalVelocity_1 = ( ( ( pt_Masses[i].getMass() -
								( average_E * pt_Masses[j].getMass() ) ) * velocity_1 ) +
								( (1 + average_E) * pt_Masses[j].getMass() * velocity_2 ) ) /
								( pt_Masses[i].getMass() + pt_Masses[j].getMass() );
	double finalVelocity_2 = ( ( ( pt_Masses[j].getMass() -
								( average_E * pt_Masses[i].getMass() ) ) * velocity_2 ) +
								( (1 + average_E) * pt_Masses[i].getMass() * velocity_1 ) ) /
								( pt_Masses[i].getMass() + pt_Masses[j].getMass() );

	pt_Masses[i].setLinearVelocity( (finalVelocity_1 - velocity_1) * unitNormal + pt_Masses[i].getLinearVelocity() );
	pt_Masses[j].setLinearVelocity( (finalVelocity_2 - velocity_2) * unitNormal + pt_Masses[j].getLinearVelocity() );

	// If point masses are overlapping, back them up so that they are barely touching:
	double minDistance = pt_Masses[i].getBoundingSphereRadius() + pt_Masses[j].getBoundingSphereRadius();
	double overlapDistance = minDistance - separationDistance.getNorm();

	pt_Masses[i].setLocation( pt_Masses[i].getLocation() + ( 0.5 * unitNormal * overlapDistance) );
	pt_Masses[j].setLocation( pt_Masses[j].getLocation() + (-0.5 * unitNormal * overlapDistance) );
}
</pre>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
</div>
<p><strong style="font-size: 12pt;"><a href="#" onclick="xcollapse('X8552');return false;" style="color:#55BBFF;"> Screenshots  </a></strong><br />
</p>
<div id="X8552" style="display: none; background: transparent;">
<div id="attachment_491" class="wp-caption alignleft" style="width: 310px"><a href="http://www.orangutangular.com/wp-content/uploads/chargedparticles_2.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/chargedparticles_2-300x187.jpg" alt="Some structures resemble the double helix" title="chargedparticles_2" width="300" height="187" class="size-medium wp-image-491" /></a><p class="wp-caption-text">Some structures resemble the double helix</p></div>
<a href="http://www.orangutangular.com/wp-content/uploads/chargedparticles_interface.jpg"><img src="http://www.orangutangular.com/wp-content/uploads/chargedparticles_interface-300x187.jpg" alt="A random initial configuration soon forms larger &quot;molecules&quot;" title="chargedparticles_interface" width="300" height="187" class="size-medium wp-image-493" /></a>
</div>
</div>
</table>
</td>
</tr>
</tbody>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.orangutangular.com/charged-particles/feed/</wfw:commentRss>
		<slash:comments>2353</slash:comments>
		</item>
	</channel>
</rss>

