<?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>Todd Vanderlin &#187; cpp</title>
	<atom:link href="http://toddvanderlin.com/tag/cpp/feed/" rel="self" type="application/rss+xml" />
	<link>http://toddvanderlin.com</link>
	<description>Design &#38; Technology</description>
	<lastBuildDate>Tue, 27 Jul 2010 03:27:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Normals</title>
		<link>http://toddvanderlin.com/2009/09/normals/</link>
		<comments>http://toddvanderlin.com/2009/09/normals/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 23:36:45 +0000</pubDate>
		<dc:creator>Todd Vanderlin</dc:creator>
				<category><![CDATA[experiment]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[normals]]></category>
		<category><![CDATA[openframeworks]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[vectors]]></category>

		<guid isPermaLink="false">http://toddvanderlin.com/?p=1616</guid>
		<description><![CDATA[Finally got normals working for the height map. Brad helped me a ton with the math, thanks brad :). After making sure I had the right points its was pretty simple. Here is an example to calculate normals for a grid in OpenFrameworks. Obviously this can be applied to any other language. The image above ...]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/vanderlin/3945248323/" title="Normals Sphere by Vanderlin, on Flickr"><img src="http://farm4.static.flickr.com/3423/3945248323_769de53bca.jpg" width="500" height="313" alt="Normals Sphere" /></a><br />
Finally got normals working for the height map. Brad helped me a ton with the math, thanks brad :). After making sure I had the right points its was pretty simple. </p>
<p>Here is an example to calculate normals for a grid in OpenFrameworks. Obviously this can be applied to any other language.<br />
<img src="http://toddvanderlin.com/cms/wp-content/uploads/2009/09/grid.png" alt="grid" title="grid" /></p>
<p>The image above we have four points on a plane. We need three of those points:</p>
<div class="codesnip-container" >
<div class="cpp codesnip" style="font-family:monospace;">ofxVec3f p1<span class="br0">&#40;</span>x1, y1, z1<span class="br0">&#41;</span><span class="sy4">;</span><br />
ofxVec3f p2<span class="br0">&#40;</span>x2, y2, z2<span class="br0">&#41;</span><span class="sy4">;</span><br />
ofxVec3f p3<span class="br0">&#40;</span>x3, y3, z3<span class="br0">&#41;</span><span class="sy4">;</span></div>
</div>
<p>We now need a vector from p1 to p2 and p1 to p3.</p>
<div class="codesnip-container" >
<div class="cpp codesnip" style="font-family:monospace;">ofxVec3f v1 <span class="sy1">=</span> p1 <span class="sy2">-</span> p2<span class="sy4">;</span><br />
ofxVec3f v2 <span class="sy1">=</span> p1 <span class="sy2">-</span> p3<span class="sy4">;</span></div>
</div>
<p>We need the cross product of v1 and v2. This will give us our normal vector. Next we normalize that vector scale it and add p1.</p>
<div class="codesnip-container" >
<div class="cpp codesnip" style="font-family:monospace;">ofxVec3f normalVec <span class="sy1">=</span> v1.<span class="me1">cross</span><span class="br0">&#40;</span>v2<span class="br0">&#41;</span><span class="sy4">;</span><br />
normalVec.<span class="me1">normalize</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy4">;</span><br />
normalVec <span class="sy2">*</span><span class="sy1">=</span> <span class="nu16">50.0</span><span class="sy4">;</span><br />
normalVec <span class="sy2">+</span><span class="sy1">=</span> p1<span class="sy4">;</span></div>
</div>
<p>Now render from p1 to normal vector.</p>
<div class="codesnip-container" >
<div class="cpp codesnip" style="font-family:monospace;">ofSetColor<span class="br0">&#40;</span>255, 0, 0<span class="br0">&#41;</span><span class="sy4">;</span><br />
glVertex3f<span class="br0">&#40;</span>normalVec.<span class="me1">x</span>, normalVec.<span class="me1">y</span>, normalVec.<span class="me1">z</span><span class="br0">&#41;</span><span class="sy4">;</span><br />
glVertex3f<span class="br0">&#40;</span>p1.<span class="me1">x</span>, p1.<span class="me1">y</span>, p1.<span class="me1">z</span><span class="br0">&#41;</span><span class="sy4">;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://toddvanderlin.com/2009/09/normals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
