#303: Typo fixes from mathnerd314
[supertux.git] / src / physic.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 //  02111-1307, USA.
21 #ifndef SUPERTUX_PHYSIC_H
22 #define SUPERTUX_PHYSIC_H
23
24 #include "math/vector.hpp"
25
26 /// Physics engine.
27 /** This is a very simplistic physics engine handling accelerated and constant
28   * movement along with gravity.
29   */
30 class Physic
31 {
32 public:
33   Physic();
34   ~Physic();
35
36   /// Resets all velocities and accelerations to 0.
37   void reset();
38
39   /// Sets velocity to a fixed value.
40   void set_velocity(float vx, float vy);
41   void set_velocity(const Vector& vector);
42
43   void set_velocity_x(float vx);
44   void set_velocity_y(float vy);
45
46   /// Velocity inversion.
47   void inverse_velocity_x();
48   void inverse_velocity_y();
49
50   Vector get_velocity() const;
51   float get_velocity_x() const;
52   float get_velocity_y() const;
53
54   /// Set acceleration.
55   /** Sets acceleration applied to the object. (Note that gravity is
56    * eventually added to the vertical acceleration)
57    */
58   void set_acceleration(float ax, float ay);
59
60   void set_acceleration_x(float ax);
61   void set_acceleration_y(float ay);
62
63   Vector get_acceleration() const;
64   float get_acceleration_x() const;
65   float get_acceleration_y() const;
66
67   /// Enables or disables handling of gravity.
68   void enable_gravity(bool gravity_enabled);
69   bool gravity_enabled() const;
70
71   /// Set gravity to apply to object when enabled
72   void set_gravity(float gravity);
73
74   /// Get gravity to apply to object when enabled
75   float get_gravity() const;
76
77   Vector get_movement(float elapsed_time);
78
79 private:
80   /// horizontal and vertical acceleration
81   float ax, ay;
82   /// horizontal and vertical velocity
83   float vx, vy;
84   /// should we respect gravity in our calculations?
85   bool gravity_enabled_flag;
86   /// current gravity (multiplied by 100) to apply to object, if enabled
87   float gravity;
88 };
89
90 class UsesPhysic
91 {
92 public:
93   Physic physic;
94   friend class Sector;
95 };
96
97 #endif