X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fmath%2Fphysic.h;h=71d7ccd440021524b02aabb0723e294ac4f232d1;hb=20a97191a5899f31c3c10012fd1f8c67bb23021f;hp=74960746a53d60a74bb78c82bda6afe6f50a04a0;hpb=05508d396828b2539754254e9e26f823856777d8;p=supertux.git diff --git a/lib/math/physic.h b/lib/math/physic.h index 74960746a..71d7ccd44 100644 --- a/lib/math/physic.h +++ b/lib/math/physic.h @@ -23,60 +23,61 @@ #include "math/vector.h" -/// Physics engine. -/** This is a very simplistic physics engine handling accelerated and constant - * movement along with gravity. - */ -class Physic -{ -public: - Physic(); - ~Physic(); - - /// Resets all velocities and accelerations to 0. - void reset(); - - /// Sets velocity to a fixed value. - void set_velocity(float vx, float vy); - - void set_velocity_x(float vx); - void set_velocity_y(float vy); - - /// Velocities invertion. - void inverse_velocity_x(); - void inverse_velocity_y(); - - float get_velocity_x(); - float get_velocity_y(); - - /// Set acceleration. - /** Sets acceleration applied to the object. (Note that gravity is - * eventually added to the vertical acceleration) - */ - void set_acceleration(float ax, float ay); - - void set_acceleration_x(float ax); - void set_acceleration_y(float ay); - - float get_acceleration_x(); - float get_acceleration_y(); - - /// Enables or disables handling of gravity. - void enable_gravity(bool gravity_enabled); - - /// Applies the physical simulation to given x and y coordinates. - void apply(float frame_ratio, float &x, float &y, float gravity = 10.0f); - - /// applies the physical simulation to given x and y coordinates. - void apply(Vector& vector, float frame_ratio, float gravity = 10.0f); - -private: - /// horizontal and vertical acceleration - float ax, ay; - /// horizontal and vertical velocity - float vx, vy; - /// should we respect gravity in out calculations? - bool gravity_enabled; -}; +namespace SuperTux + { + + /// Physics engine. + /** This is a very simplistic physics engine handling accelerated and constant + * movement along with gravity. + */ + class Physic + { + public: + Physic(); + ~Physic(); + + /// Resets all velocities and accelerations to 0. + void reset(); + + /// Sets velocity to a fixed value. + void set_velocity(float vx, float vy); + + void set_velocity_x(float vx); + void set_velocity_y(float vy); + + /// Velocities invertion. + void inverse_velocity_x(); + void inverse_velocity_y(); + + float get_velocity_x(); + float get_velocity_y(); + + /// Set acceleration. + /** Sets acceleration applied to the object. (Note that gravity is + * eventually added to the vertical acceleration) + */ + void set_acceleration(float ax, float ay); + + void set_acceleration_x(float ax); + void set_acceleration_y(float ay); + + float get_acceleration_x(); + float get_acceleration_y(); + + /// Enables or disables handling of gravity. + void enable_gravity(bool gravity_enabled); + + Vector get_movement(float elapsed_time); + + private: + /// horizontal and vertical acceleration + float ax, ay; + /// horizontal and vertical velocity + float vx, vy; + /// should we respect gravity in out calculations? + bool gravity_enabled; + }; + +} //namespace SuperTux #endif /*SUPERTUX_PHYSIC_H*/