Add local vs world flag for particle velocity
Adjust reference frame for affector to be consistent (so angles are counted clockwise from "up" in both local and world modes). Bug: skia: Change-Id: I643e1484bc0a58d1f1c0cfe35ac2ab37dc2ea409 Reviewed-on: https://skia-review.googlesource.com/c/194189 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
6674077f46
commit
d5c57fe289
@ -27,7 +27,8 @@ public:
|
||||
|
||||
static sk_sp<SkParticleAffector> MakeLinearVelocity(const SkCurve& angle,
|
||||
const SkCurve& strength,
|
||||
bool force);
|
||||
bool force,
|
||||
bool local);
|
||||
static sk_sp<SkParticleAffector> MakePointForce(SkPoint point, SkScalar constant,
|
||||
SkScalar invSquare);
|
||||
static sk_sp<SkParticleAffector> MakeOrientAlongVelocity();
|
||||
|
@ -15,16 +15,21 @@ class SkLinearVelocityAffector : public SkParticleAffector {
|
||||
public:
|
||||
SkLinearVelocityAffector(const SkCurve& angle = 0.0f,
|
||||
const SkCurve& strength = 0.0f,
|
||||
bool force = true)
|
||||
bool force = true,
|
||||
bool local = false)
|
||||
: fAngle(angle)
|
||||
, fStrength(strength)
|
||||
, fForce(force) {}
|
||||
, fForce(force)
|
||||
, fLocal(local) {}
|
||||
|
||||
REFLECTED(SkLinearVelocityAffector, SkParticleAffector)
|
||||
|
||||
void apply(SkParticleUpdateParams& params, SkParticleState& ps) override {
|
||||
float angle = fAngle.eval(ps.fAge, ps.fStableRandom);
|
||||
SkScalar c, s = SkScalarSinCos(SkDegreesToRadians(angle), &c);
|
||||
SkScalar c_local, s_local = SkScalarSinCos(SkDegreesToRadians(angle), &c_local);
|
||||
SkVector heading = fLocal ? ps.fPose.fHeading : SkVector{ 0, -1 };
|
||||
SkScalar c = heading.fX * c_local - heading.fY * s_local;
|
||||
SkScalar s = heading.fX * s_local + heading.fY * c_local;
|
||||
float strength = fStrength.eval(ps.fAge, ps.fStableRandom);
|
||||
SkVector force = { c * strength, s * strength };
|
||||
if (fForce) {
|
||||
@ -36,6 +41,7 @@ public:
|
||||
|
||||
void visitFields(SkFieldVisitor* v) override {
|
||||
v->visit("Force", fForce);
|
||||
v->visit("Local", fLocal);
|
||||
v->visit("Angle", fAngle);
|
||||
v->visit("Strength", fStrength);
|
||||
}
|
||||
@ -44,6 +50,7 @@ private:
|
||||
SkCurve fAngle;
|
||||
SkCurve fStrength;
|
||||
bool fForce;
|
||||
bool fLocal;
|
||||
};
|
||||
|
||||
class SkPointForceAffector : public SkParticleAffector {
|
||||
@ -157,8 +164,9 @@ void SkParticleAffector::RegisterAffectorTypes() {
|
||||
|
||||
sk_sp<SkParticleAffector> SkParticleAffector::MakeLinearVelocity(const SkCurve& angle,
|
||||
const SkCurve& strength,
|
||||
bool force) {
|
||||
return sk_sp<SkParticleAffector>(new SkLinearVelocityAffector(angle, strength, force));
|
||||
bool force,
|
||||
bool local) {
|
||||
return sk_sp<SkParticleAffector>(new SkLinearVelocityAffector(angle, strength, force, local));
|
||||
}
|
||||
|
||||
sk_sp<SkParticleAffector> SkParticleAffector::MakePointForce(SkPoint point, SkScalar constant,
|
||||
|
@ -33,6 +33,7 @@
|
||||
{
|
||||
"Type": "SkLinearVelocityAffector",
|
||||
"Force": false,
|
||||
"Local": false,
|
||||
"Angle": {
|
||||
"XValues": [],
|
||||
"Segments": [
|
||||
@ -40,11 +41,11 @@
|
||||
"Constant": true,
|
||||
"Ranged": true,
|
||||
"Bidirectional": false,
|
||||
"A0": 240,
|
||||
"A0": -30,
|
||||
"B0": 0,
|
||||
"C0": 0,
|
||||
"D0": 0,
|
||||
"A1": 300,
|
||||
"A1": 30,
|
||||
"B1": 0,
|
||||
"C1": 0,
|
||||
"D1": 0
|
||||
|
@ -35,6 +35,7 @@
|
||||
{
|
||||
"Type": "SkLinearVelocityAffector",
|
||||
"Force": false,
|
||||
"Local": false,
|
||||
"Angle": {
|
||||
"XValues": [],
|
||||
"Segments": [
|
||||
@ -42,11 +43,11 @@
|
||||
"Constant": true,
|
||||
"Ranged": true,
|
||||
"Bidirectional": false,
|
||||
"A0": 280,
|
||||
"A0": 10,
|
||||
"B0": 0,
|
||||
"C0": 0,
|
||||
"D0": 0,
|
||||
"A1": 340,
|
||||
"A1": 70,
|
||||
"B1": 0,
|
||||
"C1": 0,
|
||||
"D1": 0
|
||||
@ -77,6 +78,7 @@
|
||||
{
|
||||
"Type": "SkLinearVelocityAffector",
|
||||
"Force": true,
|
||||
"Local": false,
|
||||
"Angle": {
|
||||
"XValues": [],
|
||||
"Segments": [
|
||||
@ -84,7 +86,7 @@
|
||||
"Constant": true,
|
||||
"Ranged": false,
|
||||
"Bidirectional": false,
|
||||
"A0": 90,
|
||||
"A0": 180,
|
||||
"B0": 0,
|
||||
"C0": 0,
|
||||
"D0": 0,
|
||||
|
@ -33,6 +33,7 @@
|
||||
{
|
||||
"Type": "SkLinearVelocityAffector",
|
||||
"Force": false,
|
||||
"Local": false,
|
||||
"Angle": {
|
||||
"XValues": [],
|
||||
"Segments": [
|
||||
@ -40,11 +41,11 @@
|
||||
"Constant": true,
|
||||
"Ranged": true,
|
||||
"Bidirectional": false,
|
||||
"A0": 80,
|
||||
"A0": 170,
|
||||
"B0": 1,
|
||||
"C0": 0,
|
||||
"D0": 0,
|
||||
"A1": 100,
|
||||
"A1": 190,
|
||||
"B1": 0,
|
||||
"C1": 0,
|
||||
"D1": 0
|
||||
|
@ -33,6 +33,7 @@
|
||||
{
|
||||
"Type": "SkLinearVelocityAffector",
|
||||
"Force": false,
|
||||
"Local": false,
|
||||
"Angle": {
|
||||
"XValues": [],
|
||||
"Segments": [
|
||||
@ -40,11 +41,11 @@
|
||||
"Constant": true,
|
||||
"Ranged": true,
|
||||
"Bidirectional": false,
|
||||
"A0": 260,
|
||||
"A0": -10,
|
||||
"B0": 0,
|
||||
"C0": 0,
|
||||
"D0": 0,
|
||||
"A1": 280,
|
||||
"A1": 10,
|
||||
"B1": 0,
|
||||
"C1": 0,
|
||||
"D1": 0
|
||||
@ -75,6 +76,7 @@
|
||||
{
|
||||
"Type": "SkLinearVelocityAffector",
|
||||
"Force": true,
|
||||
"Local": false,
|
||||
"Angle": {
|
||||
"XValues": [],
|
||||
"Segments": [
|
||||
@ -82,7 +84,7 @@
|
||||
"Constant": true,
|
||||
"Ranged": false,
|
||||
"Bidirectional": false,
|
||||
"A0": 0,
|
||||
"A0": 90,
|
||||
"B0": 0,
|
||||
"C0": 0,
|
||||
"D0": 0,
|
||||
|
Loading…
Reference in New Issue
Block a user