4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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
21 #ifndef SUPERTUX_PHYSIC_H
22 #define SUPERTUX_PHYSIC_H
24 #include "math/vector.hpp"
27 /** This is a very simplistic physics engine handling accelerated and constant
28 * movement along with gravity.
36 /// Resets all velocities and accelerations to 0.
39 /// Sets velocity to a fixed value.
40 void set_velocity(float vx, float vy);
41 void set_velocity(const Vector& vector);
43 void set_velocity_x(float vx);
44 void set_velocity_y(float vy);
46 /// Velocities invertion.
47 void inverse_velocity_x();
48 void inverse_velocity_y();
50 Vector get_velocity() const;
51 float get_velocity_x() const;
52 float get_velocity_y() const;
55 /** Sets acceleration applied to the object. (Note that gravity is
56 * eventually added to the vertical acceleration)
58 void set_acceleration(float ax, float ay);
60 void set_acceleration_x(float ax);
61 void set_acceleration_y(float ay);
63 Vector get_acceleration() const;
64 float get_acceleration_x() const;
65 float get_acceleration_y() const;
67 /// Enables or disables handling of gravity.
68 void enable_gravity(bool gravity_enabled);
69 bool gravity_enabled() const;
71 /// Set gravity to apply to object when enabled
72 void set_gravity(float gravity);
74 /// Get gravity to apply to object when enabled
75 float get_gravity() const;
77 Vector get_movement(float elapsed_time);
80 /// horizontal and vertical acceleration
82 /// horizontal and vertical velocity
84 /// should we respect gravity in out calculations?
85 bool gravity_enabled_flag;
86 /// current gravity to apply to object, if enabled