aboutsummaryrefslogtreecommitdiffstats
path: root/src/particlebody.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/particlebody.cpp')
-rw-r--r--src/particlebody.cpp56
1 files changed, 25 insertions, 31 deletions
diff --git a/src/particlebody.cpp b/src/particlebody.cpp
index a66489e9..09e0a1c0 100644
--- a/src/particlebody.cpp
+++ b/src/particlebody.cpp
@@ -8,47 +8,41 @@
#include "Physics/particlebody.hpp"
-#include <iostream>
#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()
-{
- // set the time_step for 60fps
- double time_step=1.0/60.0;
+void ParticleBody::update() {
+ // set the time_step for 60fps
+ double time_step = 1.0 / 60.0;
- // set the last acceleration
- Vector2d last_acceleration=acceleration_;
+ // 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 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_);
+ // update the acceleration
+ if (gravity_)
+ acceleration_ =
+ Vector2d(force_.x() / mass_, (GRAVITY + force_.y()) / mass_);
+ else
+ acceleration_ = Vector2d(force_.x() / mass_, force_.y() / mass_);
- std::cout<<acceleration_<<"\n";
+ std::cout << acceleration_ << "\n";
- Vector2d avg_acceleration=(acceleration_+last_acceleration)/2.0;
+ Vector2d avg_acceleration = (acceleration_ + last_acceleration) / 2.0;
- // update the velocity of the body
- velocity_+=avg_acceleration*time_step;
+ // update the velocity of the body
+ velocity_ += avg_acceleration * time_step;
}
-} // yage
+} // yage