<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Vector multiplication.</title>
		<link>http://www.allegro.cc/forums/view/591801</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 12 Jun 2007 16:26:31 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have gotten a problem.. I don&#39;t know 3d graphics. I made a 3d &quot;BALL&quot; of 20 polygons, with holes.. it is twisting well, each polygon has it&#39;s value, where in Z is it located, they are sorted, and in the new order, they are printed. But I know there is some other way to do it, also I would like to have each polygon 2 colors. (2 sides..)</p><p>Can some one please, explain me how is that possible, or refer me to some good tutorial? Thanks..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Fri, 08 Jun 2007 18:53:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A ball with 20 polygons? Is that an icosahedron (just friendly google it) you have there? </p><p>If by 2 colours you mean the outside and inside of the ball, you could do the following. For each polygon, calculate the normal vector. That is, define two sides of the polygon as vectors. When you calculate the cross product of the two vectors, you get a third vector, which is a normal to the polygon (a perpendicular vector - or line - to the polygon). If the angle between this vector and the vector from the polygon to your viewing point is over 90 degrees, you see the &quot;inner&quot; side of the polygon, otherwise you see the outer side. </p><p>If the whole set of polygons is a polyhedron, that is an approximation of a sphere, you can draw all backside polygons first, in any order, then all frontside polygons, in any order. Something like:
</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> <span class="n">20</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">2</td><td><span class="k2">{</span></td></tr><tr><td class="number">3</td><td>    <a href="http://www.allegro.cc/manual/polygon" target="_blank"><span class="a">polygon</span></a><span class="k3">&lt;</span>i&gt;.calculate_normal<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">4</td><td>    <a href="http://www.allegro.cc/manual/polygon" target="_blank"><span class="a">polygon</span></a><span class="k3">&lt;</span>i&gt;.calculate_angle_between_normal_and_viewer<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">5</td><td><span class="k2">}</span></td></tr><tr><td class="number">6</td><td><span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> <span class="n">20</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">7</td><td><span class="k2">{</span></td></tr><tr><td class="number">8</td><td>    <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/polygon" target="_blank"><span class="a">polygon</span></a><span class="k3">&lt;</span>i&gt;.said_angle <span class="k3">&gt;</span><span class="k3">=</span> M_PI<span class="k3">/</span><span class="n">2</span><span class="k2">)</span></td></tr><tr><td class="number">9</td><td>        <a href="http://www.allegro.cc/manual/polygon" target="_blank"><span class="a">polygon</span></a><span class="k3">&lt;</span>i&gt;.render<span class="k2">(</span>back_colour<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td><span class="k2">}</span></td></tr><tr><td class="number">11</td><td><span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> <span class="n">20</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">12</td><td><span class="k2">{</span></td></tr><tr><td class="number">13</td><td>    <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/polygon" target="_blank"><span class="a">polygon</span></a><span class="k3">&lt;</span>i&gt;.said_angle <span class="k3">&lt;</span> M_PI<span class="k3">/</span><span class="n">2</span><span class="k2">)</span></td></tr><tr><td class="number">14</td><td>        <a href="http://www.allegro.cc/manual/polygon" target="_blank"><span class="a">polygon</span></a><span class="k3">&lt;</span>i&gt;.render<span class="k2">(</span>front_colour<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

No sorting. And any holes you have in the front reveal the back side.</p><p>You need a vector class for this. And when picking the two vectors of a polygon, you have to be careful to pick them in same order, so that all normal vectors point out from the ball, not into the ball.</p><p>And the viewing point must be defined either as a point (in true perspective) or a direction (a vector will do) (in isometric perspective).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Fri, 08 Jun 2007 23:57:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks a lot for this explanation, but it doesn&#39;t help me..</p><p>I understand that three polygons, define (well, three but enough 2) vectors. I know what a vector is, in general (value with direction) but how would it look I have no idea.. a coord is float[4]- (x,y,z,1). matrix- float[x][x].</p><p>How should i define vector, and how should i fill in it?</p><p>Thanks..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Sun, 10 Jun 2007 01:34:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A vector is usually presented as:</p><p>a<b>i</b> + b<b>j</b> + c<b>k</b></p><p>where <b>i</b>, <b>j</b> and <b>k</b> are vectors along x-axis, y-axis and z-axis, respectively, all 1 unit long, so called unit vectors. When programming, and defining vectors as structs or classes, you just define the values of a, b and c, as floats.</p><p>So a vector struct looks quite like a coordinate struct!</p><p>One polygon of yours, say it&#39;s a triangle, has three vertices and three edges. Each vertex is defined by x-, y- and z-coordinate. Take two vertices and subtract one vertex coordinates from the other vertex coordinates respectively. Now you have the vector that goes from the first vertex to the other. Kind of. Do the same with another edge (and its two vertices, one of which is the same as in the first edge). Now you have two vectors and... <tt>goto my_first_post;</tt>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Sun, 10 Jun 2007 11:56:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks a lot. Second post makes everything much more clear to me now, though how to compute the normal vector (while have two vectors, which define a flat) I still don&#39;t understand.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (type568)</author>
		<pubDate>Tue, 12 Jun 2007 16:15:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Either learn vector maths or find a good vector class and learn how to use it.</p><p>The normal vector is the cross product of the two vectors that define the flat.</p><p>n = a x b</p><p>You get the cross product by creating the following matrix:</p><div class="source-code snippet"><div class="inner"><pre><span class="k3">|</span> i  j  k  <span class="k3">|</span>
<span class="k3">|</span> xa ya za <span class="k3">|</span>
<span class="k3">|</span> xb yb zb <span class="k3">|</span>
</pre></div></div><p>

...and calculate the determinant of it. You end up in (something)i + (something)j + something(k), which is the normal vector, the length of which is not interesting.<br /><a href="http://en.wikipedia.org/wiki/Determinant">Look...</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Tue, 12 Jun 2007 16:26:31 +0000</pubDate>
	</item>
</rss>
