#include "physic.hpp"
Physic::Physic()
- : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true)
+ : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true), gravity(1000)
{
}
return gravity_enabled_flag;
}
+void
+Physic::set_gravity(float gravity)
+{
+ this->gravity = gravity;
+}
+
+float
+Physic::get_gravity() const
+{
+ return gravity;
+}
+
Vector
Physic::get_movement(float elapsed_time)
{
- float grav = gravity_enabled_flag ? 1000 : 0;
+ float grav = gravity_enabled_flag ? gravity : 0;
Vector result(
vx * elapsed_time + ax * elapsed_time * elapsed_time,
/// Enables or disables handling of gravity.
void enable_gravity(bool gravity_enabled);
bool gravity_enabled() const;
+
+ /// Set gravity to apply to object when enabled
+ void set_gravity(float gravity);
+
+ /// Get gravity to apply to object when enabled
+ float get_gravity() const;
Vector get_movement(float elapsed_time);
float vx, vy;
/// should we respect gravity in out calculations?
bool gravity_enabled_flag;
+ /// current gravity to apply to object, if enabled
+ float gravity;
};
#endif