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 
56  void set_acceleration_x(float nax) { ax = nax; }
57  void set_acceleration_y(float nay) { ay = nay; }
58 
59  Vector get_acceleration() const { return Vector(ax, ay); }
60  float get_acceleration_x() const { return ax; }
61  float get_acceleration_y() const { return ay; }
62 
64  void enable_gravity(bool enable) { gravity_enabled_flag = enable; }
65  bool gravity_enabled() const { return gravity_enabled_flag; }
66 
68  void set_gravity_modifier(float modifier) { gravity_modifier = modifier; }
69 
70  Vector get_movement(float dt_sec);
71 
72 private:
74  float ax, ay;
75 
77  float vx, vy;
78 
80  bool gravity_enabled_flag;
81 
83  float gravity_modifier;
84 };
85 
86 #endif
87 
88 /* EOF */
Simple two dimensional vector.
Definition: vector.hpp:24
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:64
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:68
void inverse_velocity_x()
Velocity inversion.
Definition: physic.hpp:43