-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathball.h
More file actions
executable file
·83 lines (66 loc) · 1.28 KB
/
ball.h
File metadata and controls
executable file
·83 lines (66 loc) · 1.28 KB
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
#ifndef BALL_H
#define BALL_H
#include "cvec.h"
#include <iostream>
class Ball
{
Cvec3 accel; //accel
Cvec3 pos; //current position
Cvec3 prevPos; //old position
Cvec3 normal; // normal
bool canMove;
public:
Ball() {}
Ball(Cvec3 pos) : accel(Cvec3()), pos(pos), prevPos(pos), normal(Cvec3()), canMove(true) {}
void resetAccel() {
accel = Cvec3();
}
void setAccel(Cvec3 a) {
accel = a;
}
void resetNormal() {
normal = Cvec3();
}
void setNormal(Cvec3 n) {
normal = n;
}
void addNormal (Cvec3 n) {
normal += n.normalize();
}
Cvec3& getNormal() {
return normal;
}
void newForce(Cvec3 force) {
accel += force;
}
void minusForce(Cvec3 force) {
accel -= force;
}
Cvec3& getPos() {
return pos;
}
void movePos(const Cvec3 v) {
if(canMove)
pos += v;
}
void setPos(const Cvec3 v) {
pos = v;
}
void fixMovement() {
canMove = false;
}
void unfixMovement() {
canMove = true;
}
void timeStep() {
if(canMove)
{
Cvec3 tmp = pos;
//account for air resistance in calculating distance moved
pos = accel * 0.25 + pos + (pos - prevPos) * 0.9;
prevPos = tmp;
resetAccel();
}
}
};
#endif //ball_h