2 // C Implementation: physic
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
22 : ax(0), ay(0), vx(0), vy(0), gravity_enabled(true)
33 ax = ay = vx = vy = 0;
34 gravity_enabled = true;
38 Physic::set_velocity(float nvx, float nvy)
44 void Physic::inverse_velocity_x()
49 void Physic::inverse_velocity_y()
55 Physic::get_velocity_x()
61 Physic::get_velocity_y()
67 Physic::set_acceleration(float nax, float nay)
74 Physic::get_acceleration_x()
80 Physic::get_acceleration_y()
86 Physic::enable_gravity(bool enable_gravity)
88 gravity_enabled = enable_gravity;
92 Physic::apply(float frame_ratio, float &x, float &y)
94 float gravity = World::current()->get_level()->gravity;
97 grav = gravity / 100.0;
101 x += vx * frame_ratio + ax * frame_ratio * frame_ratio;
102 y += vy * frame_ratio + (ay + grav) * frame_ratio * frame_ratio;
103 vx += ax * frame_ratio;
104 vy += (ay + grav) * frame_ratio;