forked from jasoncoon/arduino-particle-sys
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEmitter_Spin.cpp
72 lines (62 loc) · 1.75 KB
/
Emitter_Spin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright (C) 2013 Gilad Dayagi. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
/*
* Emitter_Spin.cpp - a spinning emitter
*/
#include "Emitter_Spin.h"
byte Emitter_Spin::maxTtl = 100;
Emitter_Spin::Emitter_Spin(uint16_t x, uint16_t y, uint16_t r, int16_t rv)
{
this->x = x;
this->y = y;
this->r = r;
this->rv = tempRv = rv;
oscilate = false;
counter = 0;
}
Emitter_Spin::Emitter_Spin(ParticleSysConfig *g, uint16_t r, int16_t rv) {
this->x = g->center_x; // default position at center of particle system
this->y = g->center_y;
this->r = r;
this->rv = tempRv = rv;
oscilate = false;
counter = 0;
}
void Emitter_Spin::update(ParticleSysConfig *g)
{
static signed char direction = -1;
float radAngle;
counter++;
//calculate velocity vector
if (oscilate && (counter%20 == 0)){
tempRv += direction;
if (abs(tempRv) > rv){
direction = -direction;
}
}
// Conver from Degree -> Rad
if (counter%2 == 0) {
radAngle = -counter*tempRv*(PI/180) ;
} else {
radAngle = 180-counter*tempRv*(PI/180) ;
}
// Convert Polar -> Cartesian
vx = (int16_t)(r * cos(radAngle));
vy = (int16_t)(r * sin(radAngle));
}
void Emitter_Spin::emit(Particle_Abstract *particle, ParticleSysConfig *g)
{
particle->x = this->x;
particle->y = this->y;
particle->vx = vx;
particle->vy = vy;
particle->ttl = random(20, maxTtl);
particle->hue = (counter>>1)%255;
particle->isAlive = true;
}