-
Notifications
You must be signed in to change notification settings - Fork 1
/
physics.cpp
79 lines (65 loc) · 1.1 KB
/
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
#include "physics.h"
int Physics::fps;
int Physics::getFps()
{
return fps;
}
void Physics::setFps(int value)
{
fps = value;
}
double Physics::getMaxV() const
{
return maxV;
}
void Physics::setMaxV(double value)
{
maxV = value;
}
double Physics::getMinV() const
{
return minV;
}
void Physics::setMinV(double value)
{
minV = value;
}
Physics::Physics(double v, double a, double maxV, double minV)
{
this->v = v;
this->a = a;
this->maxV = maxV;
this->minV = minV;
this->accelerattionFrames = 0;
}
double Physics::getV() const
{
return v;
}
void Physics::setV(double value)
{
v = value;
}
double Physics::getA() const
{
return a;
}
void Physics::setA(double value)
{
a = value;
}
void Physics::accelerate(int x)
{
double nextV = this->v + this->a * (this->accelerattionFrames + x);
if(nextV > maxV || nextV < minV)
return;
this->accelerattionFrames += x;
}
int Physics::getAccelerattionFrames() const
{
return accelerattionFrames;
}
double Physics::movement()
{
return (this->v + this->a * this->accelerattionFrames) / fps;
}