Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
particles [2020/11/06 13:51] – [Physics Particle Support] adminparticles [2020/11/06 14:04] admin
Line 48: Line 48:
 | a_Binormal | X = size, Y = angle, Z = weight | | a_Binormal | X = size, Y = angle, Z = weight |
 | a_Tangent | X = age, Y = life time, Z = delta time | | a_Tangent | X = age, Y = life time, Z = delta time |
 +===== Influencers =====
 +
 +Influencers are helper classes to manipulate particles at runtime.
 +
 ===== Physics Particle Support ===== ===== Physics Particle Support =====
  
 {{::particles3.jpg?nolink|}} {{::particles3.jpg?nolink|}}
 +
 +Our particles system can be linked to the physics system for particle collision detection.
 +In the following example we use the rain particle emitter as basis.
 +
 +<file pascal>
 +uses
 +  [...]
 +  Gorilla.Material.Particle,
 +  Gorilla.Particle.Emitter,
 +  Gorilla.Particle.Influencer,
 +  Gorilla.Particle.Rain,
 +  Gorilla.Particle.Spot,
 +  Gorilla.Physics,
 +  Gorilla.Physics.Q3.Body;
 +  
 +TForm1 = class(TForm)
 +  procedure FormCreate(Sender: TObject);
 +  protected
 +    FViewport : TGorillaViewport;
 +    FCamera : TGorillaCamera;
 +    FPhysics : TGorillaPhysicsSystem;
 +    FParticles : TGorillaRainParticleEmitter;
 +    FInfluencer : TGorillaPhysicsInfluencer;
 +    FSplashes : TGorillaSpotParticleEmitter;
 +    
 +    procedure DoOnGorillaPhysicsNotifyContact(const ABodyA, ABodyB : TQ3Body);
 +  [...]
 +end;
 +
 +[...]
 +
 +procedure TForm1.DoOnGorillaPhysicsNotifyContact(const ABodyA, ABodyB : TQ3Body);
 +begin
 +  // collision detected - create splashes on particle-sphere/box/terrain/mesh collision
 +  // not on particle-particle collision (too much)
 +  if (PTypeInfo(ABodyA.UserDataType) = TypeInfo(PGorillaParticle))
 +  and (PTypeInfo(ABodyB.UserDataType) = TypeInfo(PGorillaParticle)) then
 +    Exit;
 +
 +  if (PTypeInfo(ABodyA.UserDataType) = TypeInfo(PGorillaParticle)) then
 +    FSplashes.EmitParticle(
 +      PGorillaParticle(ABodyA.UserData)^.Position
 +      )
 +  else if (PTypeInfo(ABodyB.UserDataType) = TypeInfo(PGorillaParticle)) then
 +    FSplashes.EmitParticle(
 +      PGorillaParticle(ABodyB.UserData)^.Position
 +      );
 +end;
 +
 +procedure TForm1.FormCreate(Sender: TObject);
 +begin
 +  [...]
 +  
 +  // create physics system with contact callback function to display splashes
 +  FPhysics := TGorillaPhysicsSystem.Create(FViewport);
 +  FPhysics.OnBeginContact := DoOnGorillaPhysicsNotifyContact;
 +  
 +  // create rain particle emitter
 +  FParticles := TGorillaRainParticleEmitter.Create(FViewport);
 +  FParticles.Parent := FViewport;
 +  FParticles.Camera := FCamera;
 +  FParticles.EmitParticles := 25;
 +
 +  // preconfigure particles
 +  FParticles.Colored.StartColor := TAlphaColorF.Create( TAlphaColorRec.Blue );
 +  FParticles.Colored.EndColor := TAlphaColorF.Create( TAlphaColorRec.Blueviolet );
 +  FParticles.ParticleSize   := TParticlePreset.Create(20, 20, 1, false);
 +  FParticles.ParticleGrowth := TParticlePreset.Create(0, 0, 1, false);
 +  FParticles.Colored.Enabled := false;
 +  FParticles.Wind.Enabled := false;
 +
 +  // create a physics influencer
 +  FInfluencer := TGorillaPhysicsInfluencer.Create(FParticles);
 +  FInfluencer.Emitter := FParticles;
 +  // link to physics system component
 +  FInfluencer.Physics := FPhysics;
 +  FInfluencer.Enabled := true;
 +
 +  // another particle emitter to simulate rain drop splashes when they hit an obstacle
 +  FSplashes := TGorillaSpotParticleEmitter.Create(FViewport);
 +  FSplashes.Parent := FViewport;
 +  FSplashes.Camera := FCamera;
 +  FSplashes.LoadTexture('splash.png');
 +
 +  // activate physics
 +  FPhysics.Active := true;
 +  FParticles.Start();
 +  FSplashes.Start();
 +end;
 +</file>
 ===== Example ===== ===== Example =====