forked from cassiodezotti/Rabisco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Momentum.pde9177459809550585352.tmp
49 lines (46 loc) · 2.42 KB
/
Momentum.pde9177459809550585352.tmp
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
class Momentum{
private Skeleton skeleton;
private final float smoothStep = 0.15; //
public float fluid = 0; // in percentage.
public float harsh = 0; // in percentage.
public float total = 0; // in m/s². Generally, below 10 can be considered no intention of movement, thus resting state.
public float averageFluid = 0;
public float averageHarsh = 0;
public float averageTotal = 0;
Momentum(Skeleton skeleton){
this.skeleton = skeleton;
}
public void update(){
this.fluid = 0;
this.harsh = 0;
this.total = 0;
for (int j = 0; j < 25; j++){
if(this.skeleton.joints[j].estimatedAcceleration.mag() > 0.0001){ // prevent from falling into NaN
PVector previousVelocityDirection = PVector.sub(this.skeleton.joints[j].estimatedVelocity, this.skeleton.joints[j].estimatedAcceleration).normalize();
float tangentialAccelerationMagnitude = this.skeleton.joints[j].estimatedVelocity.cross(previousVelocityDirection).mag();
float radialAccelerationMagnitude = abs(PVector.dot(this.skeleton.joints[j].estimatedVelocity, previousVelocityDirection));
float tangentialAccelerationPercentage = tangentialAccelerationMagnitude/(tangentialAccelerationMagnitude+radialAccelerationMagnitude);
float radialAccelerationPercentage = radialAccelerationMagnitude/(tangentialAccelerationMagnitude+radialAccelerationMagnitude);
this.fluid += tangentialAccelerationPercentage/25;
this.harsh += radialAccelerationPercentage/25;
this.total += this.skeleton.joints[j].estimatedAcceleration.mag();
}
}
this.averageFluid = lerp(this.averageFluid, this.fluid, this.smoothStep);
this.averageHarsh = lerp(this.averageHarsh, this.harsh, this.smoothStep);
this.averageTotal = lerp(this.averageTotal, this.total, this.smoothStep);
/*
println("this.fluid: "+ this.averageFluid);
println("this.harsh: "+ this.averageHarsh);
println("this.total: "+ this.averageTotal);
*/
}
public void draw(){ // Draw 2 bars: one indicating percentage of harsh/fluid and another indicating total.
// Da pra ver que tem algo errado no sistema de coordenadas que eu to usando, desde o inicio... Eu considerei que o eixo y é pra cima, enquanto ele é pra baixo. Isso explica varias coisas... não sei onde devo começar pra arrumar isso haha
pushMatrix();
rotateY(PI);
text("Total Momentum", 200, 0);
rect(100, 0, 200, 20);
popMatrix();
}
}