Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Jul 08, 2025 21:11

Foren-Übersicht » Programmierung » Einsteiger-Fragen
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 2 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: ParticleTut
BeitragVerfasst: Sa Aug 26, 2006 13:05 
Offline
DGL Member

Registriert: So Aug 20, 2006 23:19
Beiträge: 564
Habe da mal ein Prob, das Tut hab ich durchgearbeitet und entstanden ist folgendes:

Engine.pas:
Code:
  1. unit Engine;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, glBitmap, Particle, DGLOpenGL;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.   private
  12.     { Private-Deklarationen }
  13.   public
  14.     { Public-Deklarationen }
  15.   end;
  16.  
  17. TFire = class (TObject)
  18.   protected
  19.     Container : TContainer;
  20.     Particle : TParticle;
  21.     EmissionTime : Integer;
  22.     FireTex : TglBitmap2D;
  23.   public
  24.     constructor Create;
  25.     procedure Render;
  26.     procedure Advance(aTime : Integer);
  27.     destructor Destroy; override;
  28. end;
  29.  
  30. var
  31.   Form1: TForm1;
  32.  
  33. implementation
  34. ============================>{$R *.dfm} <==================== HIER, DER HAT GEFEHLT!!
  35. const
  36.   START_LIVESPAN = 1000;
  37.   EMISSION_RATE = 20;
  38.   PARTICLES_PER_EMISSION = 10;
  39.  
  40. constructor TFire.Create();
  41. begin
  42.   inherited;
  43.   FireTex := TglBitmap2d.Create('Fire.bmp');
  44.   FireTex.GenTexture();
  45.   Container := TContainer.Create(600);
  46. end;
  47.  
  48. procedure TFire.Advance(aTime : Integer);
  49. var i: Integer;
  50. begin
  51.   INC(EmissionTime, aTime);
  52.   while EmissionTime > EMISSION_RATE do
  53.   begin
  54.     with Particle do
  55.     begin
  56.       Position.X        := Random(20)/100-0.1;
  57.       Position.Y        := Random(5) /100;
  58.       Position.Z        := Random(5) /100;
  59.       Geschwindigkeit.X := Random(60)/100-0.3;
  60.       Geschwindigkeit.Y := Random(80)/100+0.2;
  61.       Geschwindigkeit.Z := Random(40)/100-0.2;
  62.       Farbe.R           := 1;
  63.       Farbe.G           := Random * 0.7;
  64.       Farbe.B           := Random * 0.25;
  65.       LebensZeit        := START_LIVESPAN;
  66.  
  67.       for i:=0 to PARTICLES_PER_EMISSION do
  68.       begin
  69.         Position.X        := Position.X        + Random(10)/100-0.05;
  70.         Position.Y        := Position.Y        + Random(5) /100;
  71.         Geschwindigkeit.X := Geschwindigkeit.X + Random(4)/100-0.02;
  72.         Geschwindigkeit.Y := Geschwindigkeit.Y + Random(6)/100+0.03;
  73.         Container.Add(Particle);
  74.       end;
  75.       DEC(EmissionTime, EMISSION_RATE);
  76.     end;
  77.   end;
  78.   Container.Advance(aTime);
  79. end;
  80.  
  81. procedure TFire.Render();
  82. var i: Integer;
  83.     Saettigung: Single;
  84. begin
  85.   for i:=0 to Container.NumParticles do
  86.   begin
  87.     with Container.Particles[i] do
  88.     begin
  89.       if Lebenszeit > 0 then
  90.       begin
  91.         if Alter > 100 then Saettigung := 1 - Alter/START_LIVESPAN
  92.         else Saettigung := Alter/100;
  93.         glPushMatrix();
  94.         glColor4f  (Farbe.R   , Farbe.G   , Farbe.B   , Saettigung/2);
  95.         glTranslatef(Position.X, Position.Y, Position.Z);
  96.         FXBillBoardBegin;
  97.  
  98.         glBegin(GL_QUADS);
  99.           glTexCoord2f(1,0);
  100.           glVertex3f( 0.05,-0.05,0);
  101.           glTexCoord2f(0,0);
  102.           glVertex3f(-0.05,-0.05,0);
  103.           glTexCoord2f(0,1);
  104.           glVertex3f(-0.05, 0.05,0);
  105.           glTexCoord2f(1,1);
  106.           glVertex3f( 0.05, 0.05,0);
  107.         glEnd();
  108.         FXBillBoardEnd;
  109.         glPopMatrix();
  110.       end;
  111.     end;
  112.   end;
  113. end;
  114.  
  115. destructor TFire.Destroy();
  116. begin
  117.   Container.Free;
  118.   inherited;
  119. end;
  120.  
  121. end.
  122.  


und die Particle.pas:
Code:
  1. unit Particle;
  2.  
  3. interface
  4.  
  5. type
  6. TVektor = record
  7.   X : Single;
  8.   Y : Single;
  9.   Z : Single;
  10. end;
  11.  
  12. TFarbe = record
  13.   R : Single;
  14.   G : Single;
  15.   B : Single;
  16. end;
  17.  
  18. TParticle = record
  19.   Position        : TVektor;
  20.   Geschwindigkeit : TVektor;
  21.   Dichte          : Single;
  22.   Masse           : Single;
  23.   Groesse         : Single;
  24.   Farbe           : TFarbe;
  25.   Lebenszeit      : Integer;
  26.   Alter           : Integer;
  27. end;
  28.  
  29. TContainer = class (TObject)
  30.   protected
  31.     FNumParticles : Word; // Anzahl d. Particel
  32.     function GetSize : Word; // Auslesen der Größe
  33.   public
  34.     Particles : Array of TParticle; // Array aller Particel
  35.     property NumParticles                 : Word read FNumParticles;
  36.     property Size                         : Word read GetSize;
  37.  
  38.     constructor Create (aSize : Integer); overload;
  39.     function Add (aParticle : TParticle)  : Integer;
  40.     procedure Delete (aIndex : Integer);
  41.     procedure Advance (aTime : Integer);
  42.     function Clean                        : Word;
  43.     procedure Clear;
  44. end;
  45.  
  46. procedure FXBillBoardBegin;
  47. procedure FXBillBoardEnd;
  48.  
  49. implementation
  50.  
  51. uses Windows, DGLOpenGL;
  52.  
  53. procedure FXBillBoardBegin;
  54. var x, y : Byte;
  55.     Matrix : Array[0..15] of Single;
  56. begin
  57.   // Sichern der Matrix
  58.   glPushMatrix();
  59.   // Speichern der Matrix in der Variable
  60.   glGetFloatv(GL_MODELVIEW_MATRIX, @Matrix);
  61.   for x:=0 to 2 do
  62.     for y:=0 to 2 do
  63.       if x=y then Matrix[x*4+y] := 1
  64.       else Matrix[x*4+y]:=0;
  65.   glLoadMatrixF(@Matrix);
  66. end;
  67.  
  68. procedure FXBillBoardEnd;
  69. begin
  70.   glPopMatrix();
  71. end;
  72.  
  73. function TContainer.GetSize : Word;
  74. begin
  75.   Result := Length(Particles);
  76. end;
  77.  
  78. constructor TContainer.Create(aSize : Integer);
  79. begin
  80.   SetLength(Particles, aSize);
  81.   FNumParticles:=0;
  82. end;
  83.  
  84. function TContainer.Add(aParticle : TParticle) : Integer;
  85. begin
  86.   // Wenn Array voll, Aufräumen
  87.   if FNumParticles = Size-1 then Clean;
  88.   Particles[FNumParticles] := aParticle;
  89.  
  90.   if FNumParticles < Size-1 then INC(FNumParticles);
  91.  
  92.   result := FNumParticles;
  93. end;
  94.  
  95. procedure TContainer.Delete(aIndex : Integer);
  96. begin
  97.   Particles[aIndex].Lebenszeit := 0;
  98. end;
  99.  
  100. procedure TContainer.Advance(aTime : Integer);
  101. var i : Integer;
  102. begin
  103.   for i:=0 to FNumParticles-1 do
  104.   begin
  105.     with Particles[i] do
  106.     begin
  107.       Position.X := Position.X + Geschwindigkeit.X * aTime/1000;
  108.       Position.Y := Position.Y + Geschwindigkeit.Y * aTime/1000;
  109.       Position.Z := Position.Z + Geschwindigkeit.Z * aTime/1000;
  110.       Lebenszeit := Lebenszeit - aTime;
  111.       Alter      := Alter + aTime;
  112.     end;
  113.   end;
  114. end;
  115.  
  116. function TContainer.Clean : Word;
  117. var i, pos: Integer;
  118. begin
  119.   pos := 0;
  120.   for i:=0 to FNumParticles-1 do
  121.   begin
  122.     // Standartmäßig übertragen des Datensatzes
  123.     Particles[pos]:=Particles[i];
  124.  
  125.     // Nur wenn übertragenes Particle noch Lebenszeit hat,
  126.     // wird das Particel nicht vom nächsten überschrieben
  127.     if Particles[pos].Lebenszeit > 0 then INC(pos);
  128.   end;
  129.   // Anzahl gelöschter Particle
  130.   Result := FNumParticles - Pos;
  131.   // FNum (alte Anzahl Particle) wird mit Pos (neue Anzahl) überschrieben
  132.   FNumParticles :=  Pos;
  133. end;
  134.  
  135. procedure TContainer.Clear;
  136. begin
  137.   FNumParticles := 0;
  138. end;
  139.  
  140. end.
  141.  


Nun kommt allerdings das Problem:
"Im Projekt Feuer.exe ist eine Exeption der Klasse EResNotFound aufgetreten. Meldung 'Ressource TForm wurde nicht gefunden' Prozess wurde angehalten. Mit einzelner Anwendung oder Start fortsetzen."

Das Formular existiert und ich weiß nich, warums nich läuft. Dass am ende OpenGl noch nich initalisiert ist etc. weiss ich, aber erstmal sollte das Prog ja auch so laufen


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Aug 26, 2006 14:34 
Offline
DGL Member

Registriert: So Aug 20, 2006 23:19
Beiträge: 564
Vielen Dank an Jonas!!
Fehler ist oben eingefügt :oops:


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 2 Beiträge ] 
Foren-Übersicht » Programmierung » Einsteiger-Fragen


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 8 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.007s | 14 Queries | GZIP : On ]