diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components.cpp | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/components.cpp b/src/components.cpp index cf82979..5f67934 100644 --- a/src/components.cpp +++ b/src/components.cpp | |||
@@ -91,18 +91,7 @@ void PhysicsBodyComponent::receive(Game&, Entity&, const Message& msg) | |||
91 | 91 | ||
92 | void PhysicsBodyComponent::tick(Game&, Entity& entity, double dt) | 92 | void PhysicsBodyComponent::tick(Game&, Entity& entity, double dt) |
93 | { | 93 | { |
94 | // RK4 integration | 94 | // Accelerate |
95 | auto a = std::make_pair(velocity.first, velocity.second); | ||
96 | auto b = std::make_pair(velocity.first + a.first*dt*0.5, velocity.second + a.second*dt*0.5); | ||
97 | auto c = std::make_pair(velocity.first + b.first*dt*0.5, velocity.second + b.second*dt*0.5); | ||
98 | auto d = std::make_pair(velocity.first + c.first*dt, velocity.second + c.second*dt); | ||
99 | |||
100 | double dxxdt = 1.0 / 6.0 * (a.first + 2.0*(b.first + c.first) + d.first); | ||
101 | double dxydt = 1.0 / 6.0 * (a.second + 2.0*(b.second + c.second) + d.second); | ||
102 | |||
103 | entity.position.first += dxxdt * dt; | ||
104 | entity.position.second += dxydt * dt; | ||
105 | |||
106 | velocity.first += accel.first * dt; | 95 | velocity.first += accel.first * dt; |
107 | velocity.second += accel.second * dt; | 96 | velocity.second += accel.second * dt; |
108 | 97 | ||
@@ -113,6 +102,10 @@ void PhysicsBodyComponent::tick(Game&, Entity& entity, double dt) | |||
113 | if (velocity.first > TERMINAL_VELOCITY_X) velocity.first = TERMINAL_VELOCITY_X; | 102 | if (velocity.first > TERMINAL_VELOCITY_X) velocity.first = TERMINAL_VELOCITY_X; |
114 | if (velocity.second < -TERMINAL_VELOCITY_Y) velocity.second = -TERMINAL_VELOCITY_Y; | 103 | if (velocity.second < -TERMINAL_VELOCITY_Y) velocity.second = -TERMINAL_VELOCITY_Y; |
115 | if (velocity.second > TERMINAL_VELOCITY_Y) velocity.second = TERMINAL_VELOCITY_Y; | 104 | if (velocity.second > TERMINAL_VELOCITY_Y) velocity.second = TERMINAL_VELOCITY_Y; |
105 | |||
106 | // Do the movement | ||
107 | entity.position.first += velocity.first * dt; | ||
108 | entity.position.second += velocity.second * dt; | ||
116 | } | 109 | } |
117 | 110 | ||
118 | void PhysicsBodyComponent::detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position) | 111 | void PhysicsBodyComponent::detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position) |