aboutsummaryrefslogtreecommitdiffstats
path: root/src/particlebody.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/particlebody.cpp')
-rw-r--r--src/particlebody.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/particlebody.cpp b/src/particlebody.cpp
index e120d3c5..20682368 100644
--- a/src/particlebody.cpp
+++ b/src/particlebody.cpp
@@ -11,15 +11,19 @@
#include <cmath>
#include <iostream>
-namespace yage {
+namespace yage
+{
-ParticleBody::ParticleBody(const Vector2d& position, double mass,
- const Vector2d& velocity, bool gravity)
- : Body(position, mass, velocity, gravity) {}
+ParticleBody::ParticleBody(const Vector2d &position, double mass,
+ const Vector2d &velocity, bool gravity)
+ : Body(position, mass, velocity, gravity)
+{
+}
-void ParticleBody::applyForce(const Vector2d& force) { force_ += force; }
+void ParticleBody::applyForce(const Vector2d &force) { force_ += force; }
-void ParticleBody::update() {
+void ParticleBody::update()
+{
// set the time_step for 60fps
double time_step = 1.0 / 60.0;
@@ -31,11 +35,12 @@ void ParticleBody::update() {
(0.5 * last_acceleration * std::pow(time_step, 2));
// update the acceleration
- if (gravity_)
+ if (gravity_) {
acceleration_ =
Vector2d(force_.x() / mass_, (GRAVITY + force_.y()) / mass_);
- else
+ } else {
acceleration_ = Vector2d(force_.x() / mass_, force_.y() / mass_);
+ }
Vector2d avg_acceleration = (acceleration_ + last_acceleration) / 2.0;
@@ -43,4 +48,4 @@ void ParticleBody::update() {
velocity_ += avg_acceleration * time_step;
}
-} // yage
+} // yage