- unit Engine;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, glBitmap, Particle, DGLOpenGL;
- type
- TForm1 = class(TForm)
- private
- { Private-Deklarationen }
- public
- { Public-Deklarationen }
- end;
- TFire = class (TObject)
- protected
- Container : TContainer;
- Particle : TParticle;
- EmissionTime : Integer;
- FireTex : TglBitmap2D;
- public
- constructor Create;
- procedure Render;
- procedure Advance(aTime : Integer);
- destructor Destroy; override;
- end;
- var
- Form1: TForm1;
- implementation
- ============================>{$R *.dfm} <==================== HIER, DER HAT GEFEHLT!!
- const
- START_LIVESPAN = 1000;
- EMISSION_RATE = 20;
- PARTICLES_PER_EMISSION = 10;
- constructor TFire.Create();
- begin
- inherited;
- FireTex := TglBitmap2d.Create('Fire.bmp');
- FireTex.GenTexture();
- Container := TContainer.Create(600);
- end;
- procedure TFire.Advance(aTime : Integer);
- var i: Integer;
- begin
- INC(EmissionTime, aTime);
- while EmissionTime > EMISSION_RATE do
- begin
- with Particle do
- begin
- Position.X := Random(20)/100-0.1;
- Position.Y := Random(5) /100;
- Position.Z := Random(5) /100;
- Geschwindigkeit.X := Random(60)/100-0.3;
- Geschwindigkeit.Y := Random(80)/100+0.2;
- Geschwindigkeit.Z := Random(40)/100-0.2;
- Farbe.R := 1;
- Farbe.G := Random * 0.7;
- Farbe.B := Random * 0.25;
- LebensZeit := START_LIVESPAN;
- for i:=0 to PARTICLES_PER_EMISSION do
- begin
- Position.X := Position.X + Random(10)/100-0.05;
- Position.Y := Position.Y + Random(5) /100;
- Geschwindigkeit.X := Geschwindigkeit.X + Random(4)/100-0.02;
- Geschwindigkeit.Y := Geschwindigkeit.Y + Random(6)/100+0.03;
- Container.Add(Particle);
- end;
- DEC(EmissionTime, EMISSION_RATE);
- end;
- end;
- Container.Advance(aTime);
- end;
- procedure TFire.Render();
- var i: Integer;
- Saettigung: Single;
- begin
- for i:=0 to Container.NumParticles do
- begin
- with Container.Particles[i] do
- begin
- if Lebenszeit > 0 then
- begin
- if Alter > 100 then Saettigung := 1 - Alter/START_LIVESPAN
- else Saettigung := Alter/100;
- glPushMatrix();
- glColor4f (Farbe.R , Farbe.G , Farbe.B , Saettigung/2);
- glTranslatef(Position.X, Position.Y, Position.Z);
- FXBillBoardBegin;
- glBegin(GL_QUADS);
- glTexCoord2f(1,0);
- glVertex3f( 0.05,-0.05,0);
- glTexCoord2f(0,0);
- glVertex3f(-0.05,-0.05,0);
- glTexCoord2f(0,1);
- glVertex3f(-0.05, 0.05,0);
- glTexCoord2f(1,1);
- glVertex3f( 0.05, 0.05,0);
- glEnd();
- FXBillBoardEnd;
- glPopMatrix();
- end;
- end;
- end;
- end;
- destructor TFire.Destroy();
- begin
- Container.Free;
- inherited;
- end;
- end.