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 
24 
27 class Physic final
28 {
29 public:
30  Physic();
31 
33  void reset();
34 
36  void set_velocity(float nvx, float nvy);
37  void set_velocity(const Vector& vector);
38 
39  void set_velocity_x(float nvx) { vx = nvx; }
40  void set_velocity_y(float nvy) { vy = nvy; }
41 
43  void inverse_velocity_x() { vx = -vx; }
44  void inverse_velocity_y() { vy = -vy; }
45 
46  Vector get_velocity() const { return Vector(vx, vy); }
47  float get_velocity_x() const { return vx; }
48  float get_velocity_y() const { return vy; }
49 
51 
54  void set_acceleration(float nax, float nay);
55  void set_acceleration(const Vector& vector);
56 
57  void set_acceleration_x(float nax) { ax = nax; }
58  void set_acceleration_y(float nay) { ay = nay; }
59 
60  Vector get_acceleration() const { return Vector(ax, ay); }
61  float get_acceleration_x() const { return ax; }
62  float get_acceleration_y() const { return ay; }
63 
65  void enable_gravity(bool enable) { gravity_enabled_flag = enable; }
66  bool gravity_enabled() const { return gravity_enabled_flag; }
67 
69  void set_gravity_modifier(float modifier) { gravity_modifier = modifier; }
70 
71  float get_gravity_modifier() const { return gravity_modifier; }
72 
73  Vector get_movement(float dt_sec);
74 
75 private:
77  float ax, ay;
78 
80  float vx, vy;
81 
83  bool gravity_enabled_flag;
84 
86  float gravity_modifier;
87 };
88 
89 #endif
90 
91 /* EOF */
Physics engine.
Definition: physic.hpp:27
void set_velocity(float nvx, float nvy)
Sets velocity to a fixed value.
Definition: physic.cpp:38
void enable_gravity(bool enable)
Enables or disables handling of gravity.
Definition: physic.hpp:65
void set_acceleration(float nax, float nay)
Set acceleration.
Definition: physic.cpp:52
void reset()
Resets all velocities and accelerations to 0.
Definition: physic.cpp:31
void set_gravity_modifier(float modifier)
Set gravity modifier factor to apply to object when enabled.
Definition: physic.hpp:69
void inverse_velocity_x()
Velocity inversion.
Definition: physic.hpp:43