X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fphysic.h;h=86114eb8cc8bdc235a18e03b9a84e88bbab69554;hb=fc5dc4864949fc6945153bf2f172cb9c6a02e843;hp=f980bcb8c22ca4253846ce114172ee8a5b09720c;hpb=7b10050a21caeb94ee3adf5a38a332b26482cf7f;p=supertux.git diff --git a/src/physic.h b/src/physic.h index f980bcb8c..86114eb8c 100644 --- a/src/physic.h +++ b/src/physic.h @@ -1,49 +1,77 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2004 Tobias Glaesser // -// C++ Interface: physic +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. // -// Description: -// -// -// Author: Tobias Glaesser , (C) 2004 -// -// Copyright: See COPYING file that comes with this distribution -// -// - +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. #ifndef SUPERTUX_PHYSIC_H #define SUPERTUX_PHYSIC_H -#include "timer.h" +#include "math/vector.h" -enum { - PH_VT, /* Vertical throw.*/ - PH_HA /* Horizontal acceleration. */ -}; +/// 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); -/* Physic type: */ + Vector get_movement(float elapsed_time); -struct physic_type - { - int state; - float start_vy; - float start_vx; - float acceleration; - unsigned int start_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; }; -/* global variables. */ -extern float gravity; - -void physic_init(physic_type* pphysic); -int physic_get_state(physic_type* pphysic); -void physic_set_state(physic_type* pphysic, int nstate); -void physic_set_start_vy(physic_type* pphysic, float start_vy); -void physic_set_start_vx(physic_type* pphysic, float start_vx); -void physic_set_acceleration(physic_type* pphysic, float acceleration); -int physic_is_set(physic_type* pphysic); -float physic_get_velocity(physic_type* pphysic); -float physic_get_max_distance(physic_type* pphysic); -unsigned int physic_get_max_time(physic_type* pphysic); -unsigned int physic_get_time_gone(physic_type* pphysic); - -#endif /*SUPERTUX_PHYSIC_H*/ +#endif