Autor Beitrag
Passi077
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: So 16.04.06 14:33 
Hi,

ich bin gerade dabei eine PartikelEngine zu programmieren. Das Ganze soll objektorientiert geschehen.

Dazu habe ich 2 Klassen erstellt: cParticleEffekt und cParticle:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
type cParticle=class
   private
     thePosX, thePosY: real;

     procedure setVelocity(pVelocity: Velocity3f);
     procedure Kill();
end;

type cParticleEffekt=class
  private
    theMaxParticleCount: integer;
    theTime: real;

    particle: array of cParticle;

  public
    procedure Calculate(t: real);
    procedure addParticle(pIndex, pPreset: integer);

    constructor create(pMaxParticles: integer);

  end;


Nun muss ich zwischen diesen beiden Klassen eine bidirektionale Beziehung aufbauen, damit

a) die Klasse cParticleEffekt auf die einzelnen Partikel zugreifen kann und diese berechnen kann
b) die Klasse cParticle Zugriff auf Variablen der Klasse cParticleEffekt hat, welche sich global auf alle Partikel auswirken

Leider bin ich damit überfordert. Ich wollte die Klasse cParticle von der cParticleEffekt Klasse abhängig machen und habe das Ganze so modelliert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
type cParticle=class
   private
     thePosX, thePosY: real;
    ParticleEffekt: cParticleEffekt;   

     procedure setVelocity(pVelocity: Velocity3f);
     procedure Kill();

     constructor create(pParticleEffekt: cParticleEffekt); 
end;

type cParticleEffekt=class
  private
    theMaxParticleCount: integer;
    theTime: real;

    particle: array of cParticle;  

  public
    procedure Calculate(t: real);
    procedure addParticle(pIndex, pPreset: integer);

    constructor create(pMaxParticles: integer);

  end;


Jetzt kennt die Klasse cParticle aber natürlich den Datentyp cParticleEffekt noch nicht.. wenn ich das Ganze umdrehe im Code, dann kennt eben die Klasse cParticleEffekt den DAtentyp cParticle nicht, und das ist mein Problem.

Wie muss ich das korrekt modellieren, damit es realisierbar ist?

Danke + Grüße
Passi


Edit, Problem gelöst:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
type 

  cParticleEffekt = class; 
  
  cParticle = class 
  private 
    thePosX, thePosY: real; 
    ParticleEffekt: cParticleEffekt; 

    procedure setVelocity(pVelocity: Velocity3f); 
    procedure Kill(); 

    constructor create(pParticleEffekt: cParticleEffekt); 
  end; 

// type <-- das darf hier nicht stehen 

  cParticleEffekt = class 
  private 
    theMaxParticleCount: integer; 
    theTime: real; 

    particle: array of cParticle; 

  public 
    procedure Calculate(t: real); 
    procedure addParticle(pIndex, pPreset: integer); 

    constructor create(pMaxParticles: integer); 

  end;
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Di 18.04.06 07:44 
Tipp: Klassen und Typen sollten mit einem T anfangen :wink:

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!