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