Gorilla.Particle Unit Reference

Core particle structure for the particle system.

TGorillaParticle

The particle record structure containing all properties of a single particle.

Unit: Gorilla.Particle

Type: Record

Record Fields

Id

Id: Integer;

Unique identifier for each particle instance. Automatically assigned on creation.

Position

Position: TPoint3D;

Current 3D world position of the particle.

Usage:

LParticle^.Position := Point3D(0, 10, 0);

Normal

Normal: TPoint3D;

Normal vector, used internally for camera facing direction. Typically set to view direction.

Velocity

Velocity: TPoint3D;

Movement vector applied each frame. Defines particle direction and speed.

Usage:

// Move upward at 5 units/second
LParticle^.Velocity := Point3D(0, -5, 0);

Color

Color: TAlphaColorF;

RGBA color of the particle in float format (0.0 - 1.0 range).

Usage:

LParticle^.Color := TAlphaColorF.Create(1.0, 0.5, 0.0, 1.0);  // Orange

Size

Size: Single;

Current size of the particle in pixels or world units.

Angle

Angle: Single;

Rotation angle in degrees.

Weight

Weight: Single;

Particle weight, affects gravity and other force influencers.

Age

Age: Single;

Current age of the particle in seconds. Automatically updated each frame.

Read-only: Modified internally by emitter.

Life

Life: Single;

Total lifetime of the particle in seconds. Particle is destroyed when Age >= Life.

Growth

Growth: Single;

Size change per frame. Positive values grow, negative values shrink.

Usage:

LParticle^.Growth := -0.5;  // Shrink by 0.5 units per frame

Data

Data: Pointer;

Custom user data pointer. Used internally by physics influencer to store physics body reference.

Class Methods

Create

class function Create(): PGorillaParticle; static;

Creates and initializes a new particle instance.

Returns: Pointer to new particle

Usage:

var
  LParticle: PGorillaParticle;
begin
  LParticle := TGorillaParticle.Create();
  try
    LParticle^.Position := Point3D(0, 0, 0);
  finally
    Dispose(LParticle);
  end;
end;

Note: Usually particles are managed by emitters. Manual creation is rarely needed.

Instance Methods

GetDeltaTime

function GetDeltaTime(): Single;

Returns normalized particle age (0.0 to 1.0).

Returns: Age / Life ratio

Usage:

var
  LProgress: Single;
begin
  LProgress := LParticle^.GetDeltaTime();
  // 0.0 = just born, 0.5 = halfway, 1.0 = expired
end;

GetEyeDistance

function GetEyeDistance(const APosition: TPoint3D): Single;

Calculates distance from particle to specified position (typically camera).

Parameters:

  • APosition - Reference position (usually camera position)

Returns: Distance in world units

Usage:

var
  LDist: Single;
begin
  LDist := LParticle^.GetEyeDistance(Camera.Position.Point);
end;

Operators

Equal (=)

class operator Equal(A, B: TGorillaParticle): Boolean;

Compares two particles by position.

NotEqual (<>)

class operator NotEqual(A, B: TGorillaParticle): Boolean;

Checks if two particles have different positions.

GreaterThan (>)

class operator GreaterThan(A, B: TGorillaParticle): Boolean;

Compares particles by Z-depth. Used for sorting.

LessThan (<)

class operator LessThan(A, B: TGorillaParticle): Boolean;

Compares particles by Z-depth. Used for sorting.

TGorillaParticleList

TGorillaParticleList = TList<PGorillaParticle>;

List type for managing particle collections.

Examples

Manual Particle Creation

var
  LParticle: PGorillaParticle;
begin
  LParticle := TGorillaParticle.Create();
  try
    LParticle^.Position := Point3D(0, 10, 0);
    LParticle^.Velocity := Point3D(0, -2, 0);
    LParticle^.Size := 32;
    LParticle^.Color := TAlphaColorF.Create(1, 1, 1, 1);
    LParticle^.Life := 5.0;  // 5 seconds
    LParticle^.Weight := 1.0;

    // Use particle...
  finally
    Dispose(LParticle);
  end;
end;

Particle Age Progress

procedure UpdateParticleColor(const AParticle: PGorillaParticle);
var
  LProgress: Single;
  LStartColor, LEndColor: TAlphaColorF;
begin
  LProgress := AParticle^.GetDeltaTime();

  LStartColor := TAlphaColorF.Create(TAlphaColorRec.Blue);
  LEndColor := TAlphaColorF.Create(TAlphaColorRec.Red);

  // Interpolate color based on age
  AParticle^.Color.R := LStartColor.R + (LEndColor.R - LStartColor.R) * LProgress;
  AParticle^.Color.G := LStartColor.G + (LEndColor.G - LStartColor.G) * LProgress;
  AParticle^.Color.B := LStartColor.B + (LEndColor.B - LStartColor.B) * LProgress;
end;

Vertex Attributes

The particle system repurposes standard vertex attributes for extended functionality:

Attribute Purpose Particle Field
a_Position Position Position
a_Normal Velocity Normal
a_Color0 Current color Color
a_TexCoord0 Texture/atlas offset -
a_Binormal Size, angle, weight Size, Angle, Weight
a_Tangent Age, lifetime, delta Age, Life

Note: This attribute repurposing allows particle data to be efficiently passed to shaders using existing vertex formats.

Platform Support

All Gorilla platforms supported.

See Also