Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
physics.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
3 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
4 // *
5 // * This program is free software: you can redistribute it and/or modify
6 // * it under the terms of the GNU General Public License as published by
7 // * the Free Software Foundation, either version 3 of the License, or
8 // * (at your option) any later version.
9 // *
10 // * This program is distributed in the hope that it will be useful,
11 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // * GNU General Public License for more details.
14 // *
15 // * You should have received a copy of the GNU General Public License
16 // * along with this program. If not, see http://www.gnu.org/licenses/.
17 
23 #pragma once
24 
25 
26 #include "common/global.h"
27 
28 #include "object/object.h"
29 
30 #include "math/vector.h"
31 
32 
33 class CObject;
34 class CBrain;
35 class CMotion;
36 class CSoundInterface;
37 
38 namespace Gfx {
39 class CCamera;
40 class CEngine;
41 class CLight;
42 class CParticle;
43 class CTerrain;
44 class CWater;
45 }
46 
47 
48 enum PhysicsType
49 {
50  TYPE_ROLLING = 1,
51  TYPE_FLYING = 2,
52 };
53 
54 enum PhysicsMode
55 {
56  MO_ADVACCEL = 0,
57  MO_RECACCEL = 1,
58  MO_STOACCEL = 2,
59  MO_MOTACCEL = 3,
60  MO_ADVSPEED = 4,
61  MO_RECSPEED = 5,
62  MO_MOTSPEED = 6,
63  MO_CURSPEED = 7,
64  MO_TERFORCE = 8,
65  MO_TERSPEED = 9,
66  MO_TERSLIDE = 10,
67  MO_REASPEED = 11,
68 };
69 
70 
71 struct Motion
72 {
73  Math::Vector advanceAccel; // acceleration starting (+)
74  Math::Vector recedeAccel; // acceleration starting (+)
75  Math::Vector stopAccel; // acceleration stoping (+)
76  Math::Vector motorAccel; // current acceleration (+/-)
77 
78  Math::Vector advanceSpeed; // forward speed (+)
79  Math::Vector recedeSpeed; // reversing speed (+)
80  Math::Vector motorSpeed; // desired speed (+/-)
81  Math::Vector currentSpeed; // current speed (+/-)
82 
83  Math::Vector terrainForce; // power of resistance of the ground (+)
84  Math::Vector terrainSpeed; // speed of the ground (+/-)
85  Math::Vector terrainSlide; // limit sliding speed (+)
86 
87  Math::Vector realSpeed; // real speed(+/-)
88 
89  Math::Vector finalInclin; // final inclination
90 };
91 
92 
93 
94 
95 class CPhysics
96 {
97 public:
98  CPhysics(CObject* object);
99  ~CPhysics();
100 
101  void DeleteObject(bool bAll=false);
102 
103  bool EventProcess(const Event &event);
104 
105  void SetBrain(CBrain* brain);
106  void SetMotion(CMotion* motion);
107 
108  void SetType(PhysicsType type);
109  PhysicsType GetType();
110 
111  bool Write(char *line);
112  bool Read(char *line);
113 
114  void SetGravity(float value);
115  float GetGravity();
116 
117  float GetFloorHeight();
118 
119  void SetLinMotion(PhysicsMode mode, Math::Vector value);
120  Math::Vector GetLinMotion(PhysicsMode mode);
121  void SetLinMotionX(PhysicsMode mode, float value);
122  void SetLinMotionY(PhysicsMode mode, float value);
123  void SetLinMotionZ(PhysicsMode mode, float value);
124  float GetLinMotionX(PhysicsMode mode);
125  float GetLinMotionY(PhysicsMode mode);
126  float GetLinMotionZ(PhysicsMode mode);
127 
128  void SetCirMotion(PhysicsMode mode, Math::Vector value);
129  Math::Vector GetCirMotion(PhysicsMode mode);
130  void SetCirMotionX(PhysicsMode mode, float value);
131  void SetCirMotionY(PhysicsMode mode, float value);
132  void SetCirMotionZ(PhysicsMode mode, float value);
133  float GetCirMotionX(PhysicsMode mode);
134  float GetCirMotionY(PhysicsMode mode);
135  float GetCirMotionZ(PhysicsMode mode);
136 
137  float GetLinStopLength(PhysicsMode sMode=MO_ADVSPEED, PhysicsMode aMode=MO_STOACCEL);
138  float GetCirStopLength();
139  float GetLinMaxLength(float dir);
140  float GetLinTimeLength(float dist, float dir=1.0f);
141  float GetLinLength(float dist);
142 
143  void SetMotor(bool bState);
144  bool GetMotor();
145  void SetLand(bool bState);
146  bool GetLand();
147  void SetSwim(bool bState);
148  bool GetSwim();
149  void SetCollision(bool bCollision);
150  bool GetCollision();
151  void SetFreeze(bool bFreeze);
152  bool GetFreeze();
153  void SetReactorRange(float range);
154  float GetReactorRange();
155 
156  void SetMotorSpeed(Math::Vector speed);
157  void SetMotorSpeedX(float speed);
158  void SetMotorSpeedY(float speed);
159  void SetMotorSpeedZ(float speed);
160  Math::Vector GetMotorSpeed();
161  float GetMotorSpeedX();
162  float GetMotorSpeedY();
163  float GetMotorSpeedZ();
164 
165  void CreateInterface(bool bSelect);
166  Error GetError();
167 
168 protected:
169  bool EventFrame(const Event &event);
170  void WaterFrame(float aTime, float rTime);
171  void SoundMotor(float rTime);
172  void SoundMotorFull(float rTime, ObjectType type);
173  void SoundMotorSlow(float rTime, ObjectType type);
174  void SoundMotorStop(float rTime, ObjectType type);
175  void SoundReactorFull(float rTime, ObjectType type);
176  void SoundReactorStop(float rTime, ObjectType type);
177  void FrameParticle(float aTime, float rTime);
178  void MotorUpdate(float aTime, float rTime);
179  void EffectUpdate(float aTime, float rTime);
180  void UpdateMotionStruct(float rTime, Motion &motion);
181  void FloorAdapt(float aTime, float rTime, Math::Vector &pos, Math::Vector &angle);
182  void FloorAngle(const Math::Vector &pos, Math::Vector &angle);
183  int ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle);
184  bool JostleObject(CObject* pObj, Math::Vector iPos, float iRad, Math::Vector oPos, float oRad);
185  bool JostleObject(CObject* pObj, float force);
186  bool ExploOther(ObjectType iType, CObject *pObj, ObjectType oType, float force);
187  int ExploHimself(ObjectType iType, ObjectType oType, float force);
188 
189  void PowerParticle(float factor, bool bBreak);
190  void CrashParticle(float crash);
191  void MotorParticle(float aTime, float rTime);
192  void WaterParticle(float aTime, Math::Vector pos, ObjectType type, float floor, float advance, float turn);
193  void WheelParticle(int color, float width);
194 
195 protected:
196  Gfx::CEngine* m_engine;
197  Gfx::CLightManager* m_lightMan;
198  Gfx::CParticle* m_particle;
199  Gfx::CTerrain* m_terrain;
200  Gfx::CWater* m_water;
201  Gfx::CCamera* m_camera;
202  CObject* m_object;
203  CBrain* m_brain;
204  CMotion* m_motion;
205  CSoundInterface* m_sound;
206 
207  PhysicsType m_type; // TYPE_*
208  float m_gravity; // force of gravity
209  float m_time; // absolute time
210  Math::Vector m_motorSpeed; // motor speed (-1..1)
211  Motion m_linMotion; // linear motion
212  Motion m_cirMotion; // circular motion
213  bool m_bMotor;
214  bool m_bLand;
215  bool m_bSwim;
216  bool m_bCollision;
217  bool m_bObstacle;
218  bool m_bFreeze;
219  int m_repeatCollision;
220  float m_linVibrationFactor;
221  float m_cirVibrationFactor;
222  float m_inclinaisonFactor;
223  float m_lastPowerParticle;
224  float m_lastSlideParticle;
225  float m_lastMotorParticle;
226  float m_lastWaterParticle;
227  float m_lastUnderParticle;
228  float m_lastPloufParticle;
229  float m_lastFlameParticle;
230  bool m_bWheelParticleBrake;
231  Math::Vector m_wheelParticlePos[2];
232  float m_absorbWater;
233  float m_reactorTemperature;
234  float m_reactorRange;
235  float m_timeReactorFail;
236  float m_timeUnderWater;
237  float m_lastEnergy;
238  float m_lastSoundWater;
239  float m_lastSoundInsect;
240  float m_restBreakParticle;
241  float m_floorLevel; // ground level
242  float m_floorHeight; // height above the ground
243  int m_soundChannel;
244  int m_soundChannelSlide;
245  float m_soundTimePshhh;
246  float m_soundTimeJostle;
247  float m_soundTimeBoum;
248  bool m_bSoundSlow;
249  bool m_bForceUpdate;
250  bool m_bLowLevel;
251 };
252 
Some common, global definitions.
Definition: physics.h:95
Definition: physics.h:71
Manager for dynamic lights in 3D scene.
Definition: lightman.h:142
Particle engine.
Definition: particle.h:266
ObjectType
Type of game object.
Definition: object.h:46
Camera moving in 3D scene.
Definition: camera.h:130
Terrain loader/generator and manager.
Definition: terrain.h:220
Definition: motion.h:44
CObject - base class for all game objects.
Vector struct and related functions.
The graphics engine.
Definition: engine.h:681
Error
Type of error or info message.
Definition: global.h:29
Water manager/renderer.
Definition: water.h:116
3D (3x1) vector
Definition: vector.h:49
Event sent by system, interface or game.
Definition: event.h:687
Definition: object.h:372
Sound plugin interface.
Definition: sound.h:149
Definition: brain.h:78