-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBody.cpp
More file actions
35 lines (33 loc) · 869 Bytes
/
Body.cpp
File metadata and controls
35 lines (33 loc) · 869 Bytes
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
#include "Body.h"
// CONSTRUCTORS
Body::Body() : mass(0), radius(0), position(), velocity(), acceleration() {}
Body::Body(double mass, double radius, Vector2 position, Vector2 velocity)
: mass(mass), radius(radius), position(position), velocity(velocity), acceleration() {}
// FUNCTIONS
void Body::update(double dt)
{
velocity += (acceleration * dt);
position += (velocity * dt);
acceleration.zero();
}
void Body::applyForce(const Vector2 &force)
{
if (mass == 0)
{
return;
}
Vector2 accelFromForce = force / mass;
acceleration += accelFromForce;
}
double Body::distanceTo(const Body &other) const
{
return this->position.distanceTo(other.position);
}
bool Body::isCollidingWith(const Body &other) const
{
if (distanceTo(other) >= (this->radius + other.radius))
{
return false;
}
return true;
}