blob: 54e024409f875dbaf06eda3025d4c0456f563d0c [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 {
40 double fTimeOfBirth;
41 double fTimeOfDeath;
Brian Osman7c979f52019-02-12 13:27:51 -050042 SkParticlePose fPose;
43 SkParticleVelocity fVelocity;
Brian Osman125daa42019-02-20 12:25:20 -050044 SkColor4f fColor;
45 SkScalar fFrame; // Parameter to drawable for animated sprites, etc.
46 SkRandom fStableRandom;
Brian Osman7c979f52019-02-12 13:27:51 -050047};
48
49struct SkParticleUpdateParams {
50 SkRandom* fRandom;
Brian Osman7c979f52019-02-12 13:27:51 -050051 float fDeltaTime;
52 float fParticleT;
53};
54
55#endif // SkParticleData_DEFINED