<?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>Freya.no &#187; sample</title>
	<atom:link href="http://wp.freya.no/tag/sample/feed/" rel="self" type="application/rss+xml" />
	<link>http://wp.freya.no</link>
	<description>Knowledge is power</description>
	<lastBuildDate>Mon, 06 Feb 2012 19:56:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A few boost::format examples</title>
		<link>http://wp.freya.no/2011/03/a-few-boostformat-examples/</link>
		<comments>http://wp.freya.no/2011/03/a-few-boostformat-examples/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 22:03:12 +0000</pubDate>
		<dc:creator>kent</dc:creator>
				<category><![CDATA[c++]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[sample]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=970</guid>
		<description><![CDATA[I always forget how to use boost::format when I need it. So, here are a few samples from when I did remember. Only need is to include the proper boost header. No compile of any of the boost libraries is necessary. The source is also available in subversion (webclient) (subversion checkout). The output should be: [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I always forget how to use boost::format when I need it. So, here are a few samples from when I did remember.</p>
<p>Only need is to include the proper boost header. No compile of any of the boost libraries is necessary.</p>
<p>The source is also available in subversion (<a href="http://wp.freya.no/websvn/listing.php?repname=Public&amp;path=%2Fsamples%2Fboost-format%2F" target="_blank">webclient</a>) (<a href="http://wp.freya.no/svn/samples/boost-format/" target="_blank">subversion checkout</a>).</p>
<pre class="brush: cpp; title: ; notranslate">

// build with make or:
//
// g++ -I../../boost_1_46_0 fmt.cpp
//

#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;boost/format.hpp&gt;

using namespace std;
using namespace boost;

int main()
{
    stringstream ss;

    int year    = 2011;
    int month   = 3;
    int day     = 11;
    int hour    = 12;
    int minute  = 1;
    double seconds= 23.35;
    double epoch  = 1231234567890.35;

    // Fill with whitespace, right align
    ss &lt;&lt; format(&quot;#1.0 %4i %4i %4i\n&quot;) % year % month % day;
    // Output: #1.0 2011    3   11

    // Fill with whitespace, left align
    ss &lt;&lt; format(&quot;#1.1 %-4i %-4i %-4i\n&quot;) % year % month % day;
    // Output: #1.1 2011 3    11

    // Fill with zero (pad)
    ss &lt;&lt; format(&quot;#2.0 %04i %04i %04i\n&quot;) % year % month % day;
    // Output: #2.0 2011 0003 0011

    // Floating point precision
    ss &lt;&lt; format(&quot;#3.0 %11.2f\n&quot;) % seconds;
    // Output: #3.0       23.35

    // Floating point precision with zero-fill (zero pad)
    ss &lt;&lt; format(&quot;#4.0 %011.2f\n&quot;) % seconds;
    // Output: #4.0 00000023.35

    // Left aligned string literal with 30+20 columns
    ss &lt;&lt; format(&quot;#5.0 %-30s%-20s\n&quot;) % &quot;LEFT ALIGNED 1&quot; % &quot;LEFT ALIGNED 2&quot;;
    // Output: #5.0 LEFT ALIGNED 1                LEFT ALIGNED 2

    // Right aligned string literal
    ss &lt;&lt; format(&quot;#6.0 %30s%20s\n&quot;) % &quot;RIGHT ALIGNED 1&quot; % &quot;RIGHT ALIGNED 2&quot;;
    // Output: #6.0                RIGHT ALIGNED 1     RIGHT ALIGNED 2

    cout &lt;&lt; ss.str();

    return 0;
}
</pre>
<p>The output should be:</p>
<pre class="brush: plain; title: ; notranslate">
#1.0 2011    3   11
#1.1 2011 3    11
#2.0 2011 0003 0011
#3.0       23.35
#4.0 00000023.35
#5.0 LEFT ALIGNED 1                LEFT ALIGNED 2
#6.0                RIGHT ALIGNED 1     RIGHT ALIGNED 2
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=970" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2011%2F03%2Fa-few-boostformat-examples%2F&amp;title=A%20few%20boost%3A%3Aformat%20examples" id="wpa2a_6"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2011/03/a-few-boostformat-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Sphere-Sphere Collision Detection and Collision Response</title>
		<link>http://wp.freya.no/3d-math-and-physics/simple-sphere-sphere-collision-detection-and-collision-response/</link>
		<comments>http://wp.freya.no/3d-math-and-physics/simple-sphere-sphere-collision-detection-and-collision-response/#comments</comments>
		<pubDate>Sat, 13 Jan 2007 00:33:31 +0000</pubDate>
		<dc:creator>kent</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Interessant]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[collision detection]]></category>
		<category><![CDATA[collision response]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[sample]]></category>

		<guid isPermaLink="false">http://wp.freya.no:8081/simple-sphere-sphere-collision-detection-and-collision-response/</guid>
		<description><![CDATA[Collision Detection To determine if two spheres are colliding, we take the sum of the radiuses and compare it with the length from the centers of the spheres. If the lenght is smaller than the sum of the radiuses, we have a collision. Difference vector (the length is the distance between those two spheres): Then [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<h4>Collision Detection</h4>
<p>To determine if two spheres are colliding, we take the sum of the radiuses and compare it with the length from the centers of the spheres. If the lenght is smaller than the sum of the radiuses, we have a collision.</p>
<p>Difference vector (the length is the distance between those two spheres):<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_1ad4fecfcbffb16bf5374a5bd74ee47d.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{d} = s1.pos - s2.pos" title="vec{d} = s1.pos - s2.pos"/></p>
<p>Then the length is computed:<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_edce18b53884d387f286b8274e05fb5f.png" style="vertical-align:-6.5px; display: inline-block ;" alt="distance = vec{d}.length = sqrt{vec{d}.x^2 + vec{d}.y^2 + vec{d}.z^2}" title="distance = vec{d}.length = sqrt{vec{d}.x^2 + vec{d}.y^2 + vec{d}.z^2}"/></p>
<p>Sum of the radiuses:<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_0636561826ac95e5d00b58a58f3aca76.png" style="vertical-align:-6.5px; display: inline-block ;" alt="sumradius = s1.radius + s2.radius" title="sumradius = s1.radius + s2.radius"/></p>
<p>If distance&lt;sumradius the we have a collision to take care of.</p>
<h4>Collision Response</h4>
<p>This is the little more trickier part, but with some basics explained, it should be pretty straight forward.</p>
<p>First, find the vector which will serve as a basis vector (x-axis), in an arbiary direction. It have to be normalized to get realistic results.<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_ebd360c6605889a8139e404ef67b0136.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{x} = s1.pos - s2.pos" title="vec{x} = s1.pos - s2.pos"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_992.5_8bdda451a896c946571d5f23cf41b2ef.png" style="vertical-align:-7.5px; display: inline-block ;" alt="vec{x}.normalize()" title="vec{x}.normalize()"/></p>
<p>Then we calculate the x-direction velocity vector and the perpendicular y-vector.<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_11ec07179dadc6c6fe979f4619b239fb.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v1} = s1.vel" title="vec{v1} = s1.vel"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_978.5_349c47d18213b7a895a9909823302ed9.png" style="vertical-align:-21.5px; display: inline-block ;" alt="x1 = x.dot(vec{v1})" title="x1 = x.dot(vec{v1})"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_338d5e1941d266abb8c35093f09f0548.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v1x} = vec{x} * x1" title="vec{v1x} = vec{x} * x1"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_8a5b09bd06b4d142e3578eea62b121dd.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v1y} = vec{v1} - vec{v1x}" title="vec{v1y} = vec{v1} - vec{v1x}"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_293078dcca8e50c3566b72c90240d8ec.png" style="vertical-align:-6.5px; display: inline-block ;" alt="m1 = s1.mass" title="m1 = s1.mass"/></p>
<p>Same procedure for the other sphere.<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_df1d17eae325a0dbb1e60d9c0ec0441a.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{x} = vec{x}*-1" title="vec{x} = vec{x}*-1"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_24a3ea12480a0a0d9a2b9eac70d81719.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v2} = s2.vel" title="vec{v2} = s2.vel"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_978.5_a047e0b10c6be77b548ff3637566cf4b.png" style="vertical-align:-21.5px; display: inline-block ;" alt="x2 = vec{x}.dot(vec{v2})" title="x2 = vec{x}.dot(vec{v2})"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_2e88b35173b53531247925f1f0437b2d.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v2x} = vec{x} * x2" title="vec{v2x} = vec{x} * x2"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_a73913e9e491c7dd66c0a4cd328d3586.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v2y} = vec{v2} - vec{v2x}" title="vec{v2y} = vec{v2} - vec{v2x}"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_e9f38ad62dea050fa44d594c4cb2730b.png" style="vertical-align:-6.5px; display: inline-block ;" alt="m2 = s2.mass" title="m2 = s2.mass"/></p>
<p>Then we mix and play around with some of Newtons laws to obtain a formula for the speed (in vector format) after the collision.<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_980_0406a44cd44e4bfaa605e04a12b53018.png" style="vertical-align:-20px; display: inline-block ;" alt="s1.vel = vec{v1x}{(m1-m2)/(m1+m2)} + vec{v2x}{(2*m2)/(m1+m2)} + vec{v1y}" title="s1.vel = vec{v1x}{(m1-m2)/(m1+m2)} + vec{v2x}{(2*m2)/(m1+m2)} + vec{v1y}"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_980_0df4aac98b257531dc85729d713b47e8.png" style="vertical-align:-20px; display: inline-block ;" alt="s2.vel = vec{v1x}{(2*m1)/(m1+m2)} + vec{v2x}{(m2-m1)/(m1+m2)} + vec{v2y}" title="s2.vel = vec{v1x}{(2*m1)/(m1+m2)} + vec{v2x}{(m2-m1)/(m1+m2)} + vec{v2y}"/></p>
<p>And it actually works! <img src='http://wp.freya.no/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h4>Sample application:</h4>
<p><a href="http://wp.freya.no/websvn/listing.php?repname=Public&amp;path=%2Fopengl%2Fcollisiondetect%2F">Source code in subversion repository</a>.</p>
<p><img class="alignnone" title="Collision detection sample" src="http://wp.freya.no/websvn/filedetails.php?repname=Public&amp;path=%2Fopengl%2Fcollisiondetect%2Fsample.jpg" alt="" width="656" height="518" /></p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=49" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F3d-math-and-physics%2Fsimple-sphere-sphere-collision-detection-and-collision-response%2F&amp;title=Simple%20Sphere-Sphere%20Collision%20Detection%20and%20Collision%20Response" id="wpa2a_14"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/3d-math-and-physics/simple-sphere-sphere-collision-detection-and-collision-response/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

