blob: 0efc54b7e391d8de6c2d0c27fdfb09ae76044efa [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 SkParticleAffector_DEFINED
9#define SkParticleAffector_DEFINED
10
11#include "SkReflected.h"
12
13#include "SkPoint.h"
14
Brian Osman125daa42019-02-20 12:25:20 -050015struct SkColorCurve;
Brian Osman8b6283f2019-02-14 16:55:21 -050016struct SkCurve;
Brian Osman125daa42019-02-20 12:25:20 -050017struct SkParticleState;
Brian Osman7c979f52019-02-12 13:27:51 -050018struct SkParticleUpdateParams;
19
Brian Osman0c486812019-02-26 10:02:15 -050020enum SkParticleFrame {
21 kWorld_ParticleFrame, // "Up" is { 0, -1 }
22 kLocal_ParticleFrame, // "Up" is particle's heading
23 kVelocity_ParticleFrame, // "Up" is particle's direction of travel
24};
25
Brian Osman7c979f52019-02-12 13:27:51 -050026class SkParticleAffector : public SkReflected {
27public:
28 REFLECTED_ABSTRACT(SkParticleAffector, SkReflected)
29
Brian Osman14a67a32019-02-25 14:30:44 -050030 void apply(SkParticleUpdateParams& params, SkParticleState ps[], int count);
Brian Osman1b20cd82019-02-25 14:15:02 -050031 void visitFields(SkFieldVisitor* v) override;
Brian Osman7c979f52019-02-12 13:27:51 -050032
33 static void RegisterAffectorTypes();
34
Brian Osman0c486812019-02-26 10:02:15 -050035 // Affectors that can set the linear or angular velocity. Both have a 'force' option to apply
36 // the resulting value as a force, rather than directly setting the velocity.
Brian Osman8b6283f2019-02-14 16:55:21 -050037 static sk_sp<SkParticleAffector> MakeLinearVelocity(const SkCurve& angle,
38 const SkCurve& strength,
Brian Osmand5c57fe2019-02-22 11:48:18 -050039 bool force,
Brian Osman0c486812019-02-26 10:02:15 -050040 SkParticleFrame frame);
41 static sk_sp<SkParticleAffector> MakeAngularVelocity(const SkCurve& strength,
42 bool force);
43
44 // Set the orientation of a particle, relative to the world, local, or velocity frame.
45 static sk_sp<SkParticleAffector> MakeOrientation(const SkCurve& angle,
46 SkParticleFrame frame);
47
Brian Osman7c979f52019-02-12 13:27:51 -050048 static sk_sp<SkParticleAffector> MakePointForce(SkPoint point, SkScalar constant,
49 SkScalar invSquare);
Brian Osman8b6283f2019-02-14 16:55:21 -050050
Brian Osman125daa42019-02-20 12:25:20 -050051 static sk_sp<SkParticleAffector> MakeSize(const SkCurve& curve);
52 static sk_sp<SkParticleAffector> MakeFrame(const SkCurve& curve);
53 static sk_sp<SkParticleAffector> MakeColor(const SkColorCurve& curve);
Brian Osman1b20cd82019-02-25 14:15:02 -050054
55private:
Brian Osman14a67a32019-02-25 14:30:44 -050056 virtual void onApply(SkParticleUpdateParams& params, SkParticleState ps[], int count) = 0;
Brian Osman1b20cd82019-02-25 14:15:02 -050057
58 bool fEnabled = true;
Brian Osman7c979f52019-02-12 13:27:51 -050059};
60
61#endif // SkParticleAffector_DEFINED