2 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
3 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef HEADER_SUPERTUX_SUPERTUX_PHYSIC_HPP
19 #define HEADER_SUPERTUX_SUPERTUX_PHYSIC_HPP
21 #include "math/vector.hpp"
24 /** This is a very simplistic physics engine handling accelerated and constant
25 * movement along with gravity.
33 /// Resets all velocities and accelerations to 0.
36 /// Sets velocity to a fixed value.
37 void set_velocity(float vx, float vy);
38 void set_velocity(const Vector& vector);
40 void set_velocity_x(float vx);
41 void set_velocity_y(float vy);
43 /// Velocity inversion.
44 void inverse_velocity_x();
45 void inverse_velocity_y();
47 Vector get_velocity() const;
48 float get_velocity_x() const;
49 float get_velocity_y() const;
52 /** Sets acceleration applied to the object. (Note that gravity is
53 * eventually added to the vertical acceleration)
55 void set_acceleration(float ax, float ay);
57 void set_acceleration_x(float ax);
58 void set_acceleration_y(float ay);
60 Vector get_acceleration() const;
61 float get_acceleration_x() const;
62 float get_acceleration_y() const;
64 /// Enables or disables handling of gravity.
65 void enable_gravity(bool gravity_enabled);
66 bool gravity_enabled() const;
68 /** Set gravity modifier factor to apply to object when enabled */
69 void set_gravity_modifier(float gravity);
71 Vector get_movement(float elapsed_time);
74 /** horizontal and vertical acceleration */
77 /** horizontal and vertical velocity */
80 /** should we respect gravity in our calculations? */
81 bool gravity_enabled_flag;
83 /** gravity modifier is multiplied with the sectors gravity */
84 float gravity_modifier;