Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / supertux / physic.hpp
1 //  SuperTux
2 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
3 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 //
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.
9 //
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.
14 //
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/>.
17
18 #ifndef HEADER_SUPERTUX_SUPERTUX_PHYSIC_HPP
19 #define HEADER_SUPERTUX_SUPERTUX_PHYSIC_HPP
20
21 #include "math/vector.hpp"
22
23 /// Physics engine.
24 /** This is a very simplistic physics engine handling accelerated and constant
25  * movement along with gravity.
26  */
27 class Physic
28 {
29 public:
30   Physic();
31   ~Physic();
32
33   /// Resets all velocities and accelerations to 0.
34   void reset();
35
36   /// Sets velocity to a fixed value.
37   void set_velocity(float vx, float vy);
38   void set_velocity(const Vector& vector);
39
40   void set_velocity_x(float vx);
41   void set_velocity_y(float vy);
42
43   /// Velocity inversion.
44   void inverse_velocity_x();
45   void inverse_velocity_y();
46
47   Vector get_velocity() const;
48   float get_velocity_x() const;
49   float get_velocity_y() const;
50
51   /// Set acceleration.
52   /** Sets acceleration applied to the object. (Note that gravity is
53    * eventually added to the vertical acceleration)
54    */
55   void set_acceleration(float ax, float ay);
56
57   void set_acceleration_x(float ax);
58   void set_acceleration_y(float ay);
59
60   Vector get_acceleration() const;
61   float get_acceleration_x() const;
62   float get_acceleration_y() const;
63
64   /// Enables or disables handling of gravity.
65   void enable_gravity(bool gravity_enabled);
66   bool gravity_enabled() const;
67
68   /** Set gravity modifier factor to apply to object when enabled */
69   void set_gravity_modifier(float gravity);
70
71   Vector get_movement(float elapsed_time);
72
73 private:
74   /** horizontal and vertical acceleration */
75   float ax, ay;
76
77   /** horizontal and vertical velocity */
78   float vx, vy;
79   
80   /** should we respect gravity in our calculations? */
81   bool gravity_enabled_flag;
82
83   /** gravity modifier is multiplied with the sectors gravity */
84   float gravity_modifier;
85 };
86
87 #endif
88
89 /* EOF */