<?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 DevBlog &#187; macro</title>
	<atom:link href="http://gushh.net/blog/?tag=macro&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://gushh.net/blog</link>
	<description>This blog is about software, electronics engineering and game development.</description>
	<lastBuildDate>Tue, 24 Jan 2012 00:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Macro Templates, by example.</title>
		<link>http://gushh.net/blog/macro-templates-by-example/</link>
		<comments>http://gushh.net/blog/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[<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>
<g:plusone href='http://gushh.net/blog/macro-templates-by-example/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/macro-templates-by-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Randomize Array &#8211; A Flexible hard-coded macro</title>
		<link>http://gushh.net/blog/randomize-array-a-flexible-hard-coded-macro/</link>
		<comments>http://gushh.net/blog/randomize-array-a-flexible-hard-coded-macro/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 16:13:40 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[fill]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[pb]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[randomize]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/2009/06/13/pb-randomize-array-a-flexible-hard-coded-macro/</guid>
		<description><![CDATA[Tired of writing the same &#8220;randomize array&#8221; routines over and over?, just snap this little macro and register them as you see fit. A guard should be put to avoid double registrations (although the compiler will complain about this anyway &#8212; I suggest registering right after you include this, since you already know what you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>Tired of writing the same &#8220;randomize array&#8221; routines over and over?, just snap this little macro and register them as you see fit. A guard should be put to avoid double registrations (although the compiler will complain about this anyway &#8212; I suggest registering right after you include this, since you already know what you&#8217;re going to need&#8230; )</p>
<p>Code:<br />
<a href="http://gushh.net/dev/?file=pb/randomizearray.pb" target="_blank"> http://gushh.net/dev/?file=pb/randomizearray.pb</a></p>
<p>Examples:<br />
<a href="http://gushh.net/dev/?file=pb/randomizearray_test.pb" target="_blank"> http://gushh.net/dev/?file=pb/randomizearray_test.pb</a></p>
<p>Simple, right?</p>
<p>A need for both a debug / format (to string) and random fills for string arrays is present, but I&#8217;m not in the need of them at the moment. Do request if you need them though.</p>
<p>Cheers.</p>
<g:plusone href='http://gushh.net/blog/randomize-array-a-flexible-hard-coded-macro/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/randomize-array-a-flexible-hard-coded-macro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A fast vector library for purebasic.</title>
		<link>http://gushh.net/blog/a-fast-vector-library-for-purebasic/</link>
		<comments>http://gushh.net/blog/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>
<g:plusone href='http://gushh.net/blog/a-fast-vector-library-for-purebasic/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/a-fast-vector-library-for-purebasic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: gushh.net @ 2012-02-09 06:58:58 by W3 Total Cache -->
