Repository navigation
Expand file tree
/
Copy pathBody.cpp
More file actions
57 lines (52 loc) · 1.41 KB
/
Copy pathBody.cpp
File metadata and controls
57 lines (52 loc) · 1.41 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
#include "Forces3.h"
#include <iostream>
Body::Body(point coordinates, Vector2f velocity, Vector2f acceleration, float mass, bool movable, sf::Color color) {
this->mass = mass;
this->setPosition(coordinates);
this->velocity = velocity;
this->acceleration = acceleration;
this->setFillColor(color);
this->setRadius(3.0f);
this->movable = movable;
}
void Body::setForce(Vector2f force) {
if (movable) {
if (MAX_FORCE != -1 && getLength(force) > MAX_FORCE) {
std::cout << "warn force: " << getLength(force) << std::endl;
force = getUnit(force) * MAX_FORCE;
}
acceleration = force / mass;
}
}
void Body::calcVelocity() {
velocity += acceleration;
}
void Body::calcCoordinates() {
move(velocity);
}
void Body::calcAll() {
this->calcVelocity();
this->calcCoordinates();
trail.push_back(Vertex(getPosition() + getRadius(), sf::Color(70, 70, 70)));
for (int i = 0; i < trail.size(); i++) {
trail[i].color.a--;
if (trail[i].color.a <= 0)
trail.erase(trail.begin() + i);
}
if (trail.size() > 255) {
//trail.erase(trail.begin());
std::cout << "trail overflow\n";
}
}
float Body::getmass() {
return mass;
}
Vector2f Body::getVelocity() {
return velocity;
}
Vector2f Body::getAcceleration() {
return acceleration;
}
std::vector<Vertex> Body::getTrail() {
return trail;
}