2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "PhysicsEntity.h"
20 #include <bear/debug.h>
21 #include <bear/Vector2.h>
24 #include "effectManager.h"
27 /// ***** Constructors/Destructors *****
29 PhysicsEntity::PhysicsEntity(const Vector2& pos)
30 : Entity(pos), force(0,0), mass(1), CoR(0.8)
34 PhysicsEntity::~PhysicsEntity()
39 /// ***** Public Class Methods *****
41 void PhysicsEntity::update(float time_step)
43 position = positionAt(time_step);
44 velocity = velocityAt(time_step);
49 Vector2 PhysicsEntity::positionAt(float time_step) const
51 Vector2 newPosition = position;
52 Vector2 newVelocity = velocity;
53 Vector2 newForce = force;
55 newPosition += effect::positionDelta(this, time_step);
56 newVelocity += effect::velocityDelta(this, time_step);
57 newForce += effect::forceDelta(this, time_step);
59 return newForce/mass / 2 * time_step * time_step + newVelocity * time_step + newPosition;
62 Vector2 PhysicsEntity::velocityAt(float time_step) const
64 Vector2 newForce = force;
65 Vector2 newVelocity = velocity;
67 newForce += effect::forceDelta(this, time_step);
68 newVelocity += effect::velocityDelta(this, time_step);
70 return newForce/mass / 2 * time_step + newVelocity;
73 void PhysicsEntity::applyForce(const Vector2& force)
75 applyForce(force, position);
77 void PhysicsEntity::applyForce(const Vector2& force, const Vector2& /*at*/)
82 void PhysicsEntity::applyImpulse(const Vector2& impulse)
84 applyImpulse(impulse, position);
86 void PhysicsEntity::applyImpulse(const Vector2& impulse, const Vector2& /*at*/)
91 void PhysicsEntity::applyNudge(const Vector2& vecPush)