-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject.cpp
60 lines (46 loc) · 1.25 KB
/
Object.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
#include "Object.h"
using namespace std;
Object::Object(float mass, ObjectType type) :
shapeType(type),
position(0), linearVelocity(0), momentOfInertia(0), mass(mass), force(0),
angle(0), angularVelocity(0), torque(0) {
}
void Object::MoveTo(float x, float y, bool relative) {
if (relative) {
position.x += x;
position.y += y;
} else {
position.x = x;
position.y = y;
}
}
void Object::SetLinearVelocity(float vx, float vy) {
linearVelocity.x = vx;
linearVelocity.y = vy;
}
void Object::SetForce(float fx, float fy) {
force.x = fx;
force.y = fy;
}
void Object::Rotate(float angle, bool relative) {
if (relative) this->angle += angle;
else this->angle = angle;
}
void Object::SetAngularVelocity(float av) {
angularVelocity = av;
}
void Object::SetTorque(float torque) {
this->torque = torque;
}
void Object::ChangeMass(float mass, bool relative) {
if (relative) this->mass += mass;
else this->mass = mass;
if (this->mass < 1) this->mass = 1;
}
float Object::GetAngularMass(glm::vec2 r, glm::vec2 n) const {
auto c = glm::cross(glm::vec3(r, 0), glm::vec3(n, 0)).z;
auto m = momentOfInertia / c * c;
return m;
}
void Object::CalculateInertia() {
}