00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef PHYSICS_H
00028 #define PHYSICS_H
00029
00030 #include "../include/base.h"
00031 #include "../tool/euler_vector.h"
00032 #include "../tool/point.h"
00033 #include "object_cfg.h"
00034
00035 typedef enum
00036 {
00037 NoMotion,
00038 FreeFall,
00039 Pendulum,
00040 } MotionType_t;
00041
00042 class GameLoop;
00043
00044 class Physics : private ObjectConfig
00045 {
00046 private:
00047 MotionType_t m_motion_type ;
00048 EulerVector m_pos_x;
00049 EulerVector m_pos_y;
00050
00051 protected:
00052 Point2d m_extern_force;
00053 uint m_last_move;
00054 double m_phys_width, m_phys_height;
00055
00056 Point2d m_fix_point_gnd;
00057 Point2d m_fix_point_dxy;
00058 EulerVector m_rope_angle;
00059 EulerVector m_rope_length;
00060 double m_rope_elasticity;
00061 double m_elasticity_damping;
00062 double m_balancing_damping;
00063
00064
00065 bool m_elasticity_off ;
00066
00067
00068 ObjectConfig m_cfg;
00069 public:
00070 Physics ();
00071 virtual ~Physics ();
00072
00073
00074 void SetPhysXY (double x, double y);
00075 void SetPhysXY(const Point2d &position);
00076
00077 double GetPhysX() const;
00078 double GetPhysY() const;
00079 Point2d GetPos() const;
00080
00081
00082 void SetPhysSize (double width, double height);
00083
00084 void SetMass (double mass);
00085 const double GetMass() const { return m_mass; }
00086
00087 void SetWindFactor (double wind_factor);
00088 const double GetWindFactor () const { return m_wind_factor; }
00089
00090 void SetAirResistFactor (double factor);
00091 const double GetAirResistFactor () const{ return m_air_resist_factor; }
00092
00093 void SetGravityFactor (double factor);
00094 const double GetGravityFactor () const { return m_gravity_factor; }
00095
00096 void SetRebounding (bool rebounding) { m_rebounding = rebounding; }
00097 const bool GetRebounding () const { return m_rebounding; }
00098
00099
00100 void ResetConstants();
00101
00102
00103 void SetSpeed (double norme, double angle);
00104 void SetSpeedXY (Point2d vector);
00105
00106
00107 void AddSpeed (double norme, double angle);
00108 void AddSpeedXY (Point2d vector);
00109
00110
00111 void GetSpeed (double &norm, double &angle) const;
00112 void GetSpeedXY (Point2d &vector) const;
00113 Point2d GetSpeed() const;
00114 double GetAngularSpeed() const;
00115 double GetSpeedAngle() const;
00116
00117
00118 void SetExternForce (double length, double angle);
00119 void SetExternForceXY (Point2d vector);
00120
00121
00122 void SetPhysFixationPointXY(double g_x, double g_y,
00123 double dx, double dy) ;
00124 void UnsetPhysFixationPoint() ;
00125 void ChangePhysRopeSize(double dl) ;
00126 double GetRopeAngle() ;
00127 double GetRopeLength();
00128
00129
00130 void RunPhysicalEngine();
00131
00132
00133 virtual void NotifyMove(Point2d oldPos, Point2d newPos) = 0 ;
00134
00135
00136 void StartMoving();
00137
00138
00139 void StopMoving();
00140
00141
00142 bool IsMoving() const;
00143
00144
00145 bool IsFalling() const;
00146
00147 protected:
00148
00149 Point2d ComputeNextXY(double delta_t);
00150
00151 virtual void SignalDeath();
00152 virtual void SignalGhostState (bool was_already_dead);
00153 virtual void SignalDrowning();
00154 virtual void SignalRebound();
00155
00156
00157 void Rebound(Point2d contactPos, double contact_angle);
00158 private:
00159
00160 void ComputeFallNextXY (double delta_t);
00161
00162 void ComputePendulumNextXY (double delta_t);
00163 };
00164
00165 #endif