forked from mperes/ZombieAttack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DirectionSolver.pde
46 lines (36 loc) · 1003 Bytes
/
DirectionSolver.pde
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
class DirectionSolver{
float value;
float totalV;
int numReadings = 8;
float runningTotal = 0;
int thresh = 50;
float[] readings = new float[numReadings];
int index = 0;
float average = 0;
float currentRot = 0;
DirectionSolver(){
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}
void setValue(float theValue) {
value = theValue;
}
void resetRotation(float moveButton){
if(moveButton == 1.0)
currentRot = 0;
}
void update(){
runningTotal = runningTotal - readings[index];//subtract the last reading
readings[index] = value;//read from OSC
runningTotal = runningTotal+readings[index];//add the next position to the total
index ++;
if(index >= numReadings)
index = 0;
average = runningTotal / numReadings;
currentRot += average;
}
float getDirection(){
return currentRot * -0.000042;
}
}