<?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>vi-kan.net &#187; Challenge</title>
	<atom:link href="http://blog.vi-kan.net/tag/challenge/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vi-kan.net</link>
	<description>{ TODO -oVegar : insert clever text here}</description>
	<lastBuildDate>Mon, 28 Nov 2011 17:05:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Particle-challenge part 2: OK – the math-part is a little bit hard…</title>
		<link>http://blog.vi-kan.net/2009/particle-challenge-part-2-ok-the-math-part-is-a-little-bit-hard/</link>
		<comments>http://blog.vi-kan.net/2009/particle-challenge-part-2-ok-the-math-part-is-a-little-bit-hard/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 22:35:18 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Particle]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/2009/particle-challenge-part-2-ok-the-math-part-is-a-little-bit-hard/</guid>
		<description><![CDATA[It’s summer. I’m 500 km from home, and I’m trying to find some time to continue on the particle-challenge.&#160; In the last post, I didn’t decide where to go next; The world, the particles or physics. After some thinking, I found the first one most important, and chose to read a little about how the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://xkcd.com/184/"><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="In fact, draw all your rotational matrices sideways. Your professors will love it! And then they&#39;ll go home and shrink." border="0" alt="Matrix Transformation" align="right" src="http://imgs.xkcd.com/comics/matrix_transform.png" width="400" height="152" /></a> It’s summer. I’m 500 km from home, and I’m trying to find some time to continue on the particle-challenge.&#160; In <a title="1st particle-challenge: Getting something unto the screen" href="http://blog.vi-kan.net/2009/1st-particle-challenge-getting-something-unto-the-screen/#more-55">the last post</a>, I didn’t decide where to go next; The world, the particles or physics. After some thinking, I found the first one most important, and chose to read a little about how the coordinate system in OpenGL works. It sounds simple enough, but after some coding, I really feel that I need more math skills to get control of this. I have now started to read ‘<a title="‘Beginning Math and Physics for Game Programmers’" href="http://my.safaribooksonline.com/0735713901" target="_blank">Beginning Math and Physics for Game Programmers</a>’ to see if I can get the hang of it.</p>
<p>I have started on a camera class, but can’t make it work quite like I want to. There ain&#8217;t much functionality in it yet, either. </p>
<p>The camera consist of three vectors: eye position, forward direction and up direction. In theory, the class should make a rotation-matrix from the forward and up vectors, and then translate the matrix by the eye vector. </p>
<p>For now, it uses gluLookAt( ) to do the transformations instead. The reason why is simply that <a title="StackOverflow: &quot;OpenGL: Help with camera transformation&quot;" href="http://stackoverflow.com/questions/1176782/opengl-help-with-camera-transformation" target="_blank">I can’t get the math to work</a>… I’ll have to look at it some more at a later time, but now, I want more particle-fun and less math-hassle.</p>
<p>A&#160; <a href="http://svn.vi-kan.net/particle/0.2/" target="_blank">snapshot of the code</a> is available.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/particle-challenge-part-2-ok-the-math-part-is-a-little-bit-hard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>1st particle-challenge: Getting something unto the screen</title>
		<link>http://blog.vi-kan.net/2009/1st-particle-challenge-getting-something-unto-the-screen/</link>
		<comments>http://blog.vi-kan.net/2009/1st-particle-challenge-getting-something-unto-the-screen/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 13:15:25 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Particle]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/2009/1st-particle-challenge-getting-something-unto-the-screen/</guid>
		<description><![CDATA[A couple of days ago, I took a challenge to show that making a particle engine is not that hard. I also stated that the first part of the challenge would be to get something unto the screen, and that is as far as I have come. I have enough code to emit particles unto [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.vi-kan.net/wp-content/uploads/2009/07/something.png"><img style="margin: 0px 0px 0px 5px; display: inline; border: 0px;" title="No firework, but it's something" src="http://blog.vi-kan.net/wp-content/uploads/2009/07/something_thumb.png" border="0" alt="No firework, but it's something" width="238" height="208" align="right" /></a>A couple of days ago, I took a <a title="The &quot;Particle-engines-is-not-that-hard'-challenge" href="http://blog.vi-kan.net/2009/the-“particle-engines-is-not-that-hard’-challenge/">challenge</a> to show that making a particle engine is not that hard. I also stated that the first part of the challenge would be to get something unto the screen, and that is as far as I have come. I have enough code to emit particles unto the screen, beautifully rendered as small triangles in various colors.</p>
<p>Well – its no firework, but it’s a start…</p>
<p>For those who are interested in the code, it’s available for  <a title="The code for particle challenge" href="http://svn.vi-kan.net/particle/0.1" target="_blank">download here</a>. The lib-folder contains two libraries that I use. First of all, there is the <a href="http://www.delphigl.com" target="_blank">Free Pascal OpenGL Headers</a> used for rendering. Second, there is a folder called ‘SDL’, which is a older version of the <a href="http://sourceforge.net/projects/decal/" target="_blank">Delphi Container and Algorithm Library</a> (DeCAL).  I started using it for many, many years ago, back when it was a commercial product. It was called Standard Delphi Library, but was renamed to avoid confusion with ‘<a title="Simple DirectMedia Library" href="http://www.libssld.org" target="_blank">Simple DirectMedia Library</a>’. I guess it’s time to find something else, and when I start using Delphi 2009, I will for sure.</p>
<p>So, how did I put something unto the screen?<span id="more-55"></span></p>
<p>I started off with a simple TParticle class with information about position, velocity, color, time to live and age.</p>
<pre class="brush: delphi; title: ;"> TParticle = class(TObject)
  public
    constructor Create;

    procedure Update(DeltaFrame: int64);

    property Position: TVector3D read FPosition write FPosition;
    property Velocity: TVector3D read FVelocity write FVelocity;

    property Color: TColorFA read FColor write FColor;

    property TimeToLive: int64 read FTimeToLive write FTimeToLive;
    property Age: int64 read GetAge;
    property Dead: boolean read FDead write FDead;
  end;</pre>
<p>Then followed a TParticleManager to hold all the particles.</p>
<pre class="brush: delphi; title: ;"> TParticleManager = class(TObject)
  public
    constructor Create;
    destructor Destroy; override;

    procedure AddEmitter(Emitter: TParticleEmitter);

    procedure ProcessFrame;

    property Particles: DArray read FPArticles;
  end;</pre>
<p>For each ‘game loop’, the particle manager will loop through all particles, destroying those that have lived their age, and telling the others to update them self. When calling Update( ) on the particle, it pass in the tickcount since update. This is to ensure a relatively smooth and natural movement even if the fps is not stable.</p>
<pre class="brush: delphi; title: ;"> procedure TParticleManager.ProcessFrame;
  var
    CurrentFrame: int64;
    FrameDelta: int64;
  begin
    CurrentFrame := GetTickCount;
    FrameDelta := CurrentFrame - FLastFrame;

    RemoveDeadParticles;
    EmittNewParticles(FrameDelta);
    ProcessParticles(FrameDelta);

    FLastFrame := CurrentFrame;
  end;</pre>
<p>It will also contain a list of TParticleEmitters. The particle emitter will get it’s chance to emit new particles once every loop. It is the emitters responsibility to give the new particles a initial position and velocity.</p>
<pre class="brush: delphi; title: ;"> TParticleEmitter = class(TObject)
  public
    constructor Create;
    procedure EmittParticles(TimeSinceLastFrame: int64; Particles: DArray);

    property ParticlesPrTick: extended read FParticlesPrTick write FParticlesPrTick;
  end;</pre>
<p>The rendering is separated into it’s own class, TRendrer. This class will to all the OpenGL initialization-stuff. It is given a list of objects to render, where each item must implement the IRenderItem interface. In this way, the rendrer do not need to know anything about what it renders. It just setup a place for the rendering to happend, and asks the item to draw it self.</p>
<pre class="brush: delphi; title: ;"> TRendrer = class(TObject)
  public
    constructor Create(AHandle: THandle);
    destructor Destroy; override;

    procedure Render(ItemsToRender: DArray);

    procedure HandleResize(NewSize: TRect);
  end;</pre>
<p>To make the particle able to render it self, I have made a sub class, TVisualParticle, which implements IRenderItem. For now, it just draws a small triangle in the particles color.</p>
<pre class="brush: delphi; title: ;">procedure TVisualParticle.Render;
begin
  glPushMatrix();
  glTranslatef(Position.x, Position.y, Position.z);

  glBegin(GL_TRIANGLES);
    glColor4f(Color.Red, Color.Green, Color.Blue, Color.Alpha);
    glVertex3f(-0.1,-0.1, 0);
    glVertex3f( 0.1,-0.1, 0);
    glVertex3f( 0.0, 0.1, 0);
  glEnd;

  glPopMatrix;
end;</pre>
<p>From here, there are a couple of things that needs improvements. I need to explore OpenGL a bit more to get control over ‘the world’ that the particles lives in. Maybe a camera-model or something is needed. I don’t know. I also need to look into ways of rendering a little more interesting particles then triangles… And then there are physics &#8211; particles should be able to react to gravity and other forces as well. I’m not sure where I will start though. Time will show…</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/1st-particle-challenge-getting-something-unto-the-screen/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The “Particle-engines-ain&#8217;t-that-hard’-challenge</title>
		<link>http://blog.vi-kan.net/2009/the-%e2%80%9cparticle-engines-is-not-that-hard%e2%80%99-challenge/</link>
		<comments>http://blog.vi-kan.net/2009/the-%e2%80%9cparticle-engines-is-not-that-hard%e2%80%99-challenge/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 15:35:55 +0000</pubDate>
		<dc:creator>Vegar</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Particle]]></category>

		<guid isPermaLink="false">http://blog.vi-kan.net/?p=46</guid>
		<description><![CDATA[The other day, a colleague and I where looking at a cool application, Machine Flow. It’s a visual development environment and interpreter for the programming language Machine Flow. The language it self is defined by small lua-scripts, which you visually connect together. The running of the program is illustrated by small marbles carrying data around. [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 5px; display: inline; border-top: 0px; border-right: 0px" title="particle firework" border="0" alt="particle firework" align="right" src="http://blog.vi-kan.net/wp-content/uploads/2009/07/image.png" width="235" height="240" /> The other day, a colleague and I where looking at a cool application, <a href="http://www.nitrogen.za.org/projectinfo.asp?id=38">Machine Flow</a>. It’s a visual development environment and interpreter for the programming language Machine Flow. The language it self is defined by small lua-scripts, which you visually connect together. The running of the program is illustrated by small marbles carrying data around. It&#8217;s quite fun to play with, and the source is open, so there should be one or two things to look at there to.</p>
<p>What caught my colleagues interest, was a small firework-effect when the development environment was cleared. So we started discussing it, and soon I was determined to show that it’s really not that hard to make such effects. Now, I have never before done anything like this before. I lack experience with both graphics programming and the necessary math/physics. But it can’t be that hard, can it?</p>
<p>Well, we&#8217;ll just have to wait and see, then. The first challenge will be to get something unto the screen, and than I can start look at how to make it look nice. I will try to steer away from available libraries and tutorials, and rather come up with something completely on my own. The visual part will require&#160; some reading though&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vi-kan.net/2009/the-%e2%80%9cparticle-engines-is-not-that-hard%e2%80%99-challenge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
