Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkParticleData_DEFINED |
| 9 | #define SkParticleData_DEFINED |
| 10 | |
Brian Osman | 125daa4 | 2019-02-20 12:25:20 -0500 | [diff] [blame] | 11 | #include "SkColor.h" |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 12 | #include "SkPoint.h" |
| 13 | #include "SkRandom.h" |
| 14 | #include "SkRSXform.h" |
| 15 | |
| 16 | /* |
| 17 | * Various structs used to communicate particle information among emitters, affectors, etc. |
| 18 | */ |
| 19 | |
| 20 | struct SkParticlePose { |
| 21 | SkPoint fPosition; |
| 22 | SkVector fHeading; |
| 23 | SkScalar fScale; |
| 24 | |
| 25 | SkRSXform asRSXform(SkPoint ofs) const { |
| 26 | const float s = fHeading.fX * fScale; |
| 27 | const float c = -fHeading.fY * fScale; |
| 28 | return SkRSXform::Make(c, s, |
| 29 | fPosition.fX + -c * ofs.fX + s * ofs.fY, |
| 30 | fPosition.fY + -s * ofs.fX + -c * ofs.fY); |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | struct SkParticleVelocity { |
| 35 | SkVector fLinear; |
| 36 | SkScalar fAngular; |
| 37 | }; |
| 38 | |
Brian Osman | 125daa4 | 2019-02-20 12:25:20 -0500 | [diff] [blame] | 39 | struct SkParticleState { |
Brian Osman | d8e1ee9 | 2019-02-20 14:33:49 -0500 | [diff] [blame^] | 40 | float fAge; // Normalized age [0, 1] |
| 41 | float fInvLifetime; // 1 / Lifetime |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 42 | SkParticlePose fPose; |
| 43 | SkParticleVelocity fVelocity; |
Brian Osman | 125daa4 | 2019-02-20 12:25:20 -0500 | [diff] [blame] | 44 | SkColor4f fColor; |
Brian Osman | d8e1ee9 | 2019-02-20 14:33:49 -0500 | [diff] [blame^] | 45 | SkScalar fFrame; // Parameter to drawable for animated sprites, etc. |
Brian Osman | 125daa4 | 2019-02-20 12:25:20 -0500 | [diff] [blame] | 46 | SkRandom fStableRandom; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | struct SkParticleUpdateParams { |
| 50 | SkRandom* fRandom; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 51 | float fDeltaTime; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | #endif // SkParticleData_DEFINED |