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)
45 Physic::get_velocity_x()
51 Physic::get_velocity_y()
57 Physic::set_acceleration(float nax, float nay)
64 Physic::get_acceleration_x()
70 Physic::get_acceleration_y()
76 Physic::enable_gravity(bool enable_gravity)
78 gravity_enabled = enable_gravity;
82 Physic::apply(float &x, float &y)
86 grav = gravity / 100.0;
90 x += vx * frame_ratio + ax * frame_ratio * frame_ratio;
91 y += vy * frame_ratio + (ay + grav) * frame_ratio * frame_ratio;
92 vx += ax * frame_ratio;
93 vy += (ay + grav) * frame_ratio;