4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true)
36 ax = ay = vx = vy = 0;
37 gravity_enabled_flag = true;
41 Physic::set_velocity_x(float nvx)
47 Physic::set_velocity_y(float nvy)
53 Physic::set_velocity(float nvx, float nvy)
60 Physic::set_velocity(const Vector& vector)
66 void Physic::inverse_velocity_x()
71 void Physic::inverse_velocity_y()
77 Physic::get_velocity_x() const
83 Physic::get_velocity_y() const
89 Physic::get_velocity() const
91 return Vector(vx, -vy);
95 Physic::set_acceleration_x(float nax)
101 Physic::set_acceleration_y(float nay)
107 Physic::set_acceleration(float nax, float nay)
114 Physic::get_acceleration_x() const
120 Physic::get_acceleration_y() const
126 Physic::get_acceleration() const
128 return Vector(ax, -ay);
132 Physic::enable_gravity(bool enable_gravity)
134 gravity_enabled_flag = enable_gravity;
138 Physic::gravity_enabled() const
140 return gravity_enabled_flag;
144 Physic::get_movement(float elapsed_time)
146 float grav = gravity_enabled_flag ? 1000 : 0;
149 vx * elapsed_time + ax * elapsed_time * elapsed_time,
150 vy * elapsed_time + (ay + grav) * elapsed_time * elapsed_time
152 vx += ax * elapsed_time;
153 vy += (ay + grav) * elapsed_time;