<?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>GuShH&#039;s Development Blog &#187; vec3</title>
	<atom:link href="http://gushh.net/blog/tag/vec3/feed/" rel="self" type="application/rss+xml" />
	<link>http://gushh.net/blog</link>
	<description>This blog is about software, electronics and game development.</description>
	<lastBuildDate>Wed, 08 Sep 2010 03:02:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Macro Templates, by example.</title>
		<link>http://gushh.net/blog/2009/07/13/macro-templates-by-example/</link>
		<comments>http://gushh.net/blog/2009/07/13/macro-templates-by-example/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 16:46:50 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[object factory]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[vec3]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=114</guid>
		<description><![CDATA[Heres an example of what I call &#8220;macro templates&#8221; in PureBasic. A template encapsulates certain functionality, allowing you to dynamically generate the code in a flexible manner. This example implements a bare-bones n-vector library using a structure and a static array: Macro Vector_Register&#40; _n, _type &#41; &#160; Structure VECTOR#_n#_type vector._type&#91;_n&#93; EndStructure &#160; Procedure._type Vector#_n#_type#_Add&#40; *r.VECTOR#_n#_type, [...]]]></description>
			<content:encoded><![CDATA[<!-- AdSense Now! V1.95 -->
<!-- Post[count: 3] -->
<div class="adsense adsense-leadin" style="text-align:center;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-2462949361920197";
/* 468x15, created 4/6/10 */
google_ad_slot = "8315313616";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>Heres an example of what I call &#8220;macro templates&#8221; in PureBasic. A template encapsulates certain functionality, allowing you to dynamically generate the code in a flexible manner.</p>
<p>This example implements a bare-bones n-vector library using a structure and a static array:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Macro</span> Vector_Register<span style="color: #000066;">&#40;</span> _n, _type <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Structure</span> VECTOR#_n#_type
		vector._type<span style="color: #000066;">&#91;</span>_n<span style="color: #000066;">&#93;</span>
	<span style="color: #000066; font-weight: bold;">EndStructure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Add<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>r.VECTOR#_n#_type, <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066;">*</span>r<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">+</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Subtract<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>r.VECTOR#_n#_type, <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066;">*</span>r<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">-</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Divide<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>r.VECTOR#_n#_type, <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">&lt;&gt;</span> <span style="color: #CC0000;">0.0</span> <span style="color: #000066; font-weight: bold;">And</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">&lt;&gt;</span> <span style="color: #CC0000;">0.0</span>
				<span style="color: #000066;">*</span>r<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">/</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Multiply<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>r.VECTOR#_n#_type, <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066;">*</span>r<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">*</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_DotProduct<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">Define</span>._type result
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
			result <span style="color: #000066;">+</span> <span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">*</span> <span style="color: #000066;">*</span>b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span> <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> result
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Length<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>v.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">Sqr</span><span style="color: #000066;">&#40;</span> Vector#_n#_type#_DotProduct<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>v, <span style="color: #000066;">*</span>v <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>._type Vector#_n#_type#_Distance<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>a.VECTOR#_n#_type, <span style="color: #000066;">*</span>b.VECTOR#_n#_type <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.VECTOR#_n#_type temp
		Vector#_n#_type#_Subtract<span style="color: #000066;">&#40;</span> temp, <span style="color: #000066;">*</span>a, <span style="color: #000066;">*</span>b <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> Vector#_n#_type#_Length<span style="color: #000066;">&#40;</span> temp <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Procedure</span>.s Vector#_n#_type#_Debug<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>v.VECTOR#_n#_type, Decimals.i<span style="color: #000066;">=</span>#PB_Default <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i i
		<span style="color: #000066; font-weight: bold;">Define</span>.s tmp <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;[&quot;</span>
		<span style="color: #000066; font-weight: bold;">For</span> i<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> _n<span style="color: #000066;">-</span><span style="color: #CC0000;">1</span>
			tmp <span style="color: #000066;">+</span> <span style="color: #0000ff;">StrF</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>v<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span>i<span style="color: #000066;">&#93;</span>, Decimals.i <span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">If</span> i <span style="color: #000066;">&lt;&gt;</span> _n<span style="color: #000066;">-</span><span style="color: #CC0000;">1</span>
				tmp <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;, &quot;</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
		tmp <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;]&quot;</span>
		<span style="color: #000066; font-weight: bold;">Debug</span> tmp
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> tmp
	<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndMacro</span></pre></div></div>

<p>It might look strange/complicated at first, but once you read it you&#8217;ll realize it&#8217;s fairly simple.</p>
<p>Let&#8217;s see the usage of this particular template:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;">Vector_Register<span style="color: #000066;">&#40;</span><span style="color: #CC0000;">3</span>, f <span style="color: #000066;">&#41;</span>	<span style="color: #ff0000; font-style: italic;">; Register a float &quot;vec3&quot;.</span>
<span style="color: #000066; font-weight: bold;">Define</span>.VECTOR3f a,b,c	<span style="color: #ff0000; font-style: italic;">; Define a few vectors with the new structure.</span>
&nbsp;
a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">10.0</span>
a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">20.0</span>
a<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">30.0</span>
&nbsp;
b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">100.0</span>
b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">200.0</span>
b<span style="color: #000066;">\</span>vector<span style="color: #000066;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #000066;">&#93;</span> <span style="color: #000066;">=</span> <span style="color: #CC0000;">300.0</span>
&nbsp;
Vector3f_Add<span style="color: #000066;">&#40;</span>c, a, b<span style="color: #000066;">&#41;</span>	<span style="color: #ff0000; font-style: italic;">; c = a + b</span>
Vector3f_Debug<span style="color: #000066;">&#40;</span>c<span style="color: #000066;">&#41;</span>	<span style="color: #ff0000; font-style: italic;">; show each element using the debug output.</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Debug</span> Vector3f_DotProduct<span style="color: #000066;">&#40;</span> a, b <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">Debug</span> Vector3f_Length<span style="color: #000066;">&#40;</span> a <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">Debug</span> Vector3f_Distance<span style="color: #000066;">&#40;</span> a, b <span style="color: #000066;">&#41;</span></pre></div></div>

<p>Cool, huh?. And you can define any amount of elements with any basic type.</p>
<p>Of course we sacrificed speed for flexibility. In those cases where we have to define n-vectors, this would be an ideal solution. For everything else, I suggest a specific library, such as my <a href="http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/" target="_blank">vec3</a> macro lib.</p>
<p>Using this principle you can abstract almost anything, within reason. One good example is my <a href="http://gushh.net/blog/2009/05/03/object-factory-for-purebasic/" target="_blank">object factory</a> template.  Ideally one would have arrays, lists, etc. Implemented in this very same way, in such case the possibilities would be endless and you&#8217;d be able to define dynamic lists/arrays inside structures, etc.</p>
<p>I strongly advice you to implement at least one of those templates, even if it&#8217;s just for an exercise.</p>
<p>Having the extra tools can&#8217;t hurt!</p>
<p>Cheers.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2009/08/05/average-template/" rel="bookmark" class="crp_title">Average template</a></li><li><a href="http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/" rel="bookmark" class="crp_title">A fast vector library for purebasic.</a></li><li><a href="http://gushh.net/blog/2009/05/10/vec3-and-easyobject-libraries-updated/" rel="bookmark" class="crp_title">VEC3 and EasyObject Libraries updated.</a></li><li><a href="http://gushh.net/blog/2009/01/25/updated-the-vec3-lib-major-overhaul/" rel="bookmark" class="crp_title">Updated the vec3 lib, major overhaul.</a></li><li><a href="http://gushh.net/blog/2009/08/28/structuring-libraries-basic-design-tips/" rel="bookmark" class="crp_title">Structuring libraries, basic design tips.</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2009/07/13/macro-templates-by-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VEC3 and EasyObject Libraries updated.</title>
		<link>http://gushh.net/blog/2009/05/10/vec3-and-easyobject-libraries-updated/</link>
		<comments>http://gushh.net/blog/2009/05/10/vec3-and-easyobject-libraries-updated/#comments</comments>
		<pubDate>Sun, 10 May 2009 20:44:37 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[atan2]]></category>
		<category><![CDATA[curve]]></category>
		<category><![CDATA[EasyObject]]></category>
		<category><![CDATA[find angle]]></category>
		<category><![CDATA[interpolation]]></category>
		<category><![CDATA[object factory]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[turret]]></category>
		<category><![CDATA[vec3]]></category>
		<category><![CDATA[vector library]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=71</guid>
		<description><![CDATA[Today I updated both VEC3 and EasyObject, the download links remain the same. http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/ VEC3 got angle helpers (now you can easily find the angle between two vec3, etc) as well as a curve function to smoothly interpolate variables (you can see it in action in one of the new examples where an enemy turret [...]]]></description>
			<content:encoded><![CDATA[<p>Today I updated both VEC3 and EasyObject, the download links remain the same.</p>
<p><a href="http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/">http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/</a></p>
<p>VEC3 got angle helpers (now you can easily find the angle between two vec3, etc) as well as a curve function to smoothly interpolate variables (you can see it in action in one of the new examples where an enemy turret slowly aims toward the player).</p>
<p><a href="http://gushh.net/blog/2009/05/03/object-factory-for-purebasic/">http://gushh.net/blog/2009/05/03/object-factory-for-purebasic/</a></p>
<p>EasyObject now allows you to send a user variable on all iterators. New example provided (particles)</p>
<p>Cheers!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2009/01/25/updated-the-vec3-lib-major-overhaul/" rel="bookmark" class="crp_title">Updated the vec3 lib, major overhaul.</a></li><li><a href="http://gushh.net/blog/2009/07/13/macro-templates-by-example/" rel="bookmark" class="crp_title">Macro Templates, by example.</a></li><li><a href="http://gushh.net/blog/2009/05/03/object-factory-for-purebasic/" rel="bookmark" class="crp_title">An efficient and simple object factory for PureBasic</a></li><li><a href="http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/" rel="bookmark" class="crp_title">A fast vector library for purebasic.</a></li><li><a href="http://gushh.net/blog/2009/08/28/structuring-libraries-basic-design-tips/" rel="bookmark" class="crp_title">Structuring libraries, basic design tips.</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2009/05/10/vec3-and-easyobject-libraries-updated/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Updated the vec3 lib, major overhaul.</title>
		<link>http://gushh.net/blog/2009/01/25/updated-the-vec3-lib-major-overhaul/</link>
		<comments>http://gushh.net/blog/2009/01/25/updated-the-vec3-lib-major-overhaul/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 10:37:31 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Libraries]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[coordinate]]></category>
		<category><![CDATA[cross product]]></category>
		<category><![CDATA[dot product]]></category>
		<category><![CDATA[endpoint]]></category>
		<category><![CDATA[fmod]]></category>
		<category><![CDATA[isometric]]></category>
		<category><![CDATA[lerp]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[quadratic curve]]></category>
		<category><![CDATA[transformation]]></category>
		<category><![CDATA[vec2]]></category>
		<category><![CDATA[vec3]]></category>
		<category><![CDATA[vector math]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=49</guid>
		<description><![CDATA[The VEC3 lib was updated today, I haven&#8217;t had time to put the newer versions as they were developed so I&#8217;m just uploading the latest version right now. A small change-log can be found at the header of the source. Same link as before: VEC3_MACRO.PBI Or you can download the package: VEC3_MACRO.ZIP New functionality as seen [...]]]></description>
			<content:encoded><![CDATA[<p>The VEC3 lib was updated today, I haven&#8217;t had time to put the newer versions as they were developed so I&#8217;m just uploading the latest version right now. A small change-log can be found at the header of the source.</p>
<p>Same link as before: <a href="http://gushh.net/dev/?file=pb/vec3_macro.pbi" target="_blank">VEC3_MACRO.PBI</a></p>
<p>Or you can download the package: <a href="http://gushh.net/dls/vec3_macro.zip" target="_blank">VEC3_MACRO.ZIP</a></p>
<p><a href="http://gushh.net/dls/vec3_macro.zip"><span id="more-49"></span><br />
</a></p>
<p>New functionality as seen on the change-log:</p>
<blockquote><p>24/01/2009: Added min, max. Fixed Lerp.</p>
<p>18/01/2009: Fixed structure, made FMOD compliant with VEC3_TYPE. Refactored FastSine() and PIWRAP().</p>
<p>12/01/2009: Optimized/Fixed the PIWRAP macro with FMOD. Added resolution switch For the quadratic curve.</p>
<p>11/01/2009: Added wrap, clamp, lerp, string. Fixed some bugs. Refactored the vec3 structure. Added approximation method for sine and cosine functions.</p>
<p>10/01/2009: Library created.</p></blockquote>
<p> </p>
<p>I think I got carried away a little, but it proves to be a useful library for quick prototyping (at least that&#8217;s what I use it for). I&#8217;ll write a few examples with a small drawing framework perhaps by next week if I have time for it. Some of the things that are left to do include angle and coordinate helpers, which also means isometric transformation for 3d points, projections, etc.</p>
<p>As it stands right now, you could prototype almost any type of game/application without having to code most of the trivial stuff (such as, the vector code, provided by the library!).</p>
<p>Cheers.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2009/05/10/vec3-and-easyobject-libraries-updated/" rel="bookmark" class="crp_title">VEC3 and EasyObject Libraries updated.</a></li><li><a href="http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/" rel="bookmark" class="crp_title">A fast vector library for purebasic.</a></li><li><a href="http://gushh.net/blog/2009/07/13/macro-templates-by-example/" rel="bookmark" class="crp_title">Macro Templates, by example.</a></li><li><a href="http://gushh.net/blog/2009/09/05/automatic-declare-tool/" rel="bookmark" class="crp_title">Declar&#8217;em! &#8211; Automatic declaration of procedures.</a></li><li><a href="http://gushh.net/blog/2009/06/13/randomize-array-a-flexible-hard-coded-macro/" rel="bookmark" class="crp_title">Randomize Array &#8211; A Flexible hard-coded macro</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2009/01/25/updated-the-vec3-lib-major-overhaul/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A fast vector library for purebasic.</title>
		<link>http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/</link>
		<comments>http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 17:03:31 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Libraries]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[resident]]></category>
		<category><![CDATA[sqrt]]></category>
		<category><![CDATA[sse2]]></category>
		<category><![CDATA[vec2]]></category>
		<category><![CDATA[vec3]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=24</guid>
		<description><![CDATA[I recently required some vector functions to prototype a game idea in PureBasic, however there is no such thing as a built-in vector library and any of the existent community code was buggy to say the least (no offense but it&#8217;s old, ugly code that you&#8217;ll find anywhere else). The reason for this library is [...]]]></description>
			<content:encoded><![CDATA[<p>I recently required some vector functions to prototype a game idea in PureBasic, however there is no such thing as a built-in vector library and any of the existent community code was buggy to say the least (no offense but it&#8217;s old, ugly code that you&#8217;ll find anywhere else).</p>
<p>The reason for this library is quite simple, and so is the library itself. you can either include it or install the resource file and start using it right away. After taking a quick look at the source, you&#8217;ll soon familiarize with it&#8217;s naming convention; there is no need to write any documentation for this type of code, since it&#8217;s basic vector math. However a test source is included for your delight.</p>
<p>You can find the source in here: <a href="http://gushh.net/dev/?file=pb/vec3_macro.pbi" target="_blank">http://gushh.net/dev/?file=pb/vec3_macro.pbi</a><br />
And some ugly test code in here: <a href="http://gushh.net/dev/?file=pb/vec3_macro_test.pb" target="_blank">http://gushh.net/dev/?file=pb/vec3_macro_test.pb</a></p>
<p>Or, you can get &#8220;the whole package&#8221; from here: <a href="http://gushh.net/dls/vec3_macro.zip">http://gushh.net/dls/vec3_macro.zip</a></p>
<p>Using this library is as easy as&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Define</span>.VEC3 a, b, c
VEC3_SET<span style="color: #000066;">&#40;</span> a, <span style="color: #CC0000;">0.1</span>, <span style="color: #CC0000;">0.2</span>, <span style="color: #CC0000;">0.3</span> <span style="color: #000066;">&#41;</span>
VEC3_SET<span style="color: #000066;">&#40;</span> b, <span style="color: #CC0000;">0.4</span>, <span style="color: #CC0000;">0.5</span>, <span style="color: #CC0000;">0.6</span> <span style="color: #000066;">&#41;</span>
VEC3_ADD<span style="color: #000066;">&#40;</span> a, b, c <span style="color: #000066;">&#41;</span>
VEC3_DEBUG3<span style="color: #000066;">&#40;</span> a, b, c <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; display the vectors in the debug console.</span></pre></div></div>

<p> <br />
<span id="more-24"></span></p>
<p>I mention &#8220;so-called fast&#8221; because it&#8217;s relatively fast, however not as fast as a pure sse2+ implementation would be &#8211; although we remain &#8220;as fast as we can&#8221; without breaking code readability and maintainability at all. This is also 100% cross-platform and as fast as it gets with the current compiler. &#8220;Macrofobics&#8221; could disagree but it&#8217;s their loss.</p>
<p>Some might argue that using a &#8220;fast sqrt&#8221; would be a good thing, but I disagree. You don&#8217;t really need this at all now a days. Also, any implementation of the fast sqrt in PB would not benefit from much speed increase at all, if any you&#8217;ll ruin code readability over a little bit of speed while giving away precision and portability.</p>
<p>That said, feel free to modify as you see fit &#8211; But please share your findings with the community.</p>
<p>If there is a need for a VEC2 lib, I&#8217;ll gladly release it. Remember, you don&#8217;t need a point library / class at all, a vector library can indeed be used for points and it is recommended; cuts unecesarry redundant code and makes your life easier. Perhaps a purist OOP coder would disagree, but I don&#8217;t care.</p>
<p>Have fun with vectors!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2009/07/13/macro-templates-by-example/" rel="bookmark" class="crp_title">Macro Templates, by example.</a></li><li><a href="http://gushh.net/blog/2009/05/10/vec3-and-easyobject-libraries-updated/" rel="bookmark" class="crp_title">VEC3 and EasyObject Libraries updated.</a></li><li><a href="http://gushh.net/blog/2009/01/25/updated-the-vec3-lib-major-overhaul/" rel="bookmark" class="crp_title">Updated the vec3 lib, major overhaul.</a></li><li><a href="http://gushh.net/blog/2009/07/16/wikipedia-entries-mostly-biased/" rel="bookmark" class="crp_title">Wikipedia entries, mostly biased.</a></li><li><a href="http://gushh.net/blog/2010/08/14/autocomplete-library/" rel="bookmark" class="crp_title">AutoComplete Library</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2009/01/09/a-fast-vector-library-for-purebasic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
