diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-09-09 07:55:22 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-09-09 07:55:22 +0100 |
commit | 60072c1d8089ffd3294e76636198d14710be95b8 (patch) | |
tree | 511d459e9afe69ca58d05880eb53ce44a9a183c6 /src/particlebody.cpp | |
parent | 660996bd750dbb5fcdce85845ee6b260f3ed23eb (diff) | |
download | YAGE-60072c1d8089ffd3294e76636198d14710be95b8.tar.gz YAGE-60072c1d8089ffd3294e76636198d14710be95b8.zip |
Restructuring
Diffstat (limited to 'src/particlebody.cpp')
-rw-r--r-- | src/particlebody.cpp | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/particlebody.cpp b/src/particlebody.cpp deleted file mode 100644 index bdb81eac..00000000 --- a/src/particlebody.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* ---------------------------------------------------------------------------- - * particlebody.cpp - * - * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License - * See file LICENSE for more details - * ---------------------------------------------------------------------------- - */ - -#include <YAGE/Physics/particlebody.h> - -#include <cmath> -#include <iostream> - -namespace yage -{ - -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::update() -{ - // set the time_step for 60fps - double time_step = 1.0 / 60.0; - - // set the last acceleration - Vector2d last_acceleration = acceleration_; - - // update the position of the body - position_ += velocity_ * time_step + - (0.5 * last_acceleration * std::pow(time_step, 2)); - - // update the acceleration - if (gravity_) { - acceleration_ = - Vector2d(force_.x() / mass_, (GRAVITY + force_.y()) / mass_); - } else { - acceleration_ = Vector2d(force_.x() / mass_, force_.y() / mass_); - } - - Vector2d avg_acceleration = (acceleration_ + last_acceleration) / 2.0; - - // update the velocity of the body - velocity_ += avg_acceleration * time_step; -} - -} // namespace yage |