blob: e0fa77133e94ef0b08ecab090a8d9c04f0783150 [file] [log] [blame]
Brian Osman7c979f52019-02-12 13:27:51 -05001/*
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 Osman125daa42019-02-20 12:25:20 -050011#include "SkColor.h"
Brian Osman7c979f52019-02-12 13:27:51 -050012#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
20struct 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
34struct SkParticleVelocity {
35 SkVector fLinear;
36 SkScalar fAngular;
37};
38
Brian Osman125daa42019-02-20 12:25:20 -050039struct SkParticleState {
Brian Osmand8e1ee92019-02-20 14:33:49 -050040 float fAge; // Normalized age [0, 1]
41 float fInvLifetime; // 1 / Lifetime
Brian Osman7c979f52019-02-12 13:27:51 -050042 SkParticlePose fPose;
43 SkParticleVelocity fVelocity;
Brian Osman125daa42019-02-20 12:25:20 -050044 SkColor4f fColor;
Brian Osmand8e1ee92019-02-20 14:33:49 -050045 SkScalar fFrame; // Parameter to drawable for animated sprites, etc.
Brian Osmane5d532e2019-02-26 14:58:40 -050046 SkRandom fRandom;
Brian Osman7c979f52019-02-12 13:27:51 -050047};
48
49struct SkParticleUpdateParams {
Brian Osman7c979f52019-02-12 13:27:51 -050050 float fDeltaTime;
Brian Osman7c979f52019-02-12 13:27:51 -050051};
52
53#endif // SkParticleData_DEFINED