-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathADDAC_Physics.cpp
executable file
·143 lines (115 loc) · 2.98 KB
/
ADDAC_Physics.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "ADDAC_Physics.h"
//-----------------------------------------------------------------------ADDAC-----------------
/*! \brief Default constructor for ADDAC_Physics. */
ADDAC_Physics::ADDAC_Physics(){
AinitCondition = 2;
Angle = PI/2;
Kelasticity = 1;
Mass = 1;
Bmaterial = 1;
x=0;
y=0;
x0=0;
y0=0;
t0=0;
ax=0;
bx=0;
ay=0;
by=0;
gx=4;
gy=-10;
boundX=500;
boundY=500;
t=0.0f;
inc_t = 0.01f;
Ymin=0.0f;
Ymax=1.0f;
gateThreshold = 400; // 1.25v !!
//Serial.println("PHYSICS COMPLETE");
hitXWall=false;
hitYWall=false;
}
// --------------------------------------------------------------------------- UPDATE -------------------------
//
/*! \brief Marble Physics update
\param _gx X gravity/force
\param _gy Y gravity/force
\param _material ball ellasticity
\param _speed ball spped
*/
void ADDAC_Physics::update(float _gx, float _gy, float _material, float _speed) {
gx =_gx-0.5;//1023.0f - 0.5f;
gy =_gy-0.5;//1023.0f - 0.5f;
Bmaterial= _material/2.0f+0.5;///1023.0f/2+0.5f;
//boundX=_speed;
//boundY=_speed;
inc_t = _speed*4.0f;
//x = AinitCondition* encolher * cos(sqrt(Kelasticity/Mass)*t*(encolher))*cos(Angle);
//y = -AinitCondition* encolher * cos(sqrt(Kelasticity/Mass)*t*(encolher))*sin(Angle);
//x = (x+2) / 4.0f * addacMaxResolution;
//y = (y+2) / 4.0f * addacMaxResolution;
x = 0.5f * gx * (t*t) + (ax*t) + bx;
y= 0.5f * gy * (t*t) + (ay*t) + by;
hitXWall=false;
hitYWall=false;
if(x < -boundX || x>boundX){
if(x < -boundX) x=-boundX;
else if(x > boundX) x=boundX;
t0=t;
t=0;
bx=x;
by=y;
float vx=gx*t0 + ax;
float vy=gy*t0 + ay;
ax = -vx*Bmaterial;
ay = vy*Bmaterial;
if(gx!=0)hitXWall=true;
}
if(y < -boundY || y>boundY){
if(y < -boundY) y=-boundY;
else if(y > boundY) y=boundY;
t0=t;
t=0;
bx=x;
by=y;
float vx=gx*t0 + ax;
float vy=gy*t0 + ay;
ax = vx*Bmaterial;
ay = -vy*Bmaterial;
hitYWall=true;
}
Velocity = sqrt((gx * t + ax)*(gx * t + ax) + (gy * t + ay)*(gy * t + ay));
Velocity = constrain(Velocity,0,20);
Velocity = Velocity/20.0f;
x=(x + boundX) / (boundX * 2);
y=(y + boundY) / (boundY * 2);
t = t+inc_t;
}
/*! \brief Bump Marble
\param _fMinGateVal force
*/
void ADDAC_Physics::bump(int _fMinGateVal){
if(_fMinGateVal>gateThreshold){
Serial.print(" GATED!");
t=0;
x=0;
y=0;
x0=0;
y0=0;
ax=10; // vel inicial x
bx=0;
ay=-10.0f; // vel inicial y
by=0;
//Spring.gx= map(mouseX,0,width,0,2)-1;
//Spring.gy= map(mouseY,0,height,0,2)-1;
t=0;
}
}
// --------------------------------------------------------------------------- OTHER -------------------------
//
void ADDAC_Physics::setInc(float _inc){
inc_t=_inc;
inc_t2=_inc;
}
// --------------------------------------------------------------------------- END ----------------------------------
//