summaryrefslogtreecommitdiffstats
path: root/src/physics.h
blob: 3eb83f5d95aa2bc48365669345d03998b47503d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// physics.h

#ifndef _PHYSICS_H_
#define	_PHYSICS_H_


class CInstanceManager;
class CD3DEngine;
class CLight;
class CParticule;
class CTerrain;
class CWater;
class CCamera;
class CObject;
class CBrain;
class CMotion;
class CSound;


enum PhysicsType
{
	TYPE_ROLLING	= 1,
	TYPE_FLYING		= 2,
};

enum PhysicsMode
{
	MO_ADVACCEL		= 0,
	MO_RECACCEL		= 1,
	MO_STOACCEL		= 2,
	MO_MOTACCEL		= 3,
	MO_ADVSPEED		= 4,
	MO_RECSPEED		= 5,
	MO_MOTSPEED		= 6,
	MO_CURSPEED		= 7,
	MO_TERFORCE		= 8,
	MO_TERSPEED		= 9,
	MO_TERSLIDE		= 10,
	MO_REASPEED		= 11,
};


typedef struct
{
	D3DVECTOR	advanceAccel;	// acc�l�ration de d�part (+)
	D3DVECTOR	recedeAccel;	// acc�l�ration de d�part (+)
	D3DVECTOR	stopAccel;		// acc�l�ration d'arr�t (+)
	D3DVECTOR	motorAccel;		// acc�l�ration actuelle (+/-)

	D3DVECTOR	advanceSpeed;	// vitesse en marche avant (+)
	D3DVECTOR	recedeSpeed;	// vitesse en marche arri�re (+)
	D3DVECTOR	motorSpeed;		// vitesse souhait�e (+/-)
	D3DVECTOR	currentSpeed;	// vitesse actuelle (+/-)

	D3DVECTOR	terrainForce;	// force de r�sistance du terrain (+)
	D3DVECTOR	terrainSpeed;	// vitesse du terrain (+/-)
	D3DVECTOR	terrainSlide;	// limite vitesse de glissement (+)

	D3DVECTOR	realSpeed;		// vitesse r�elle (+/-)

	D3DVECTOR	finalInclin;	// inclinaison finale
}
Motion;




class CPhysics
{
public:
	CPhysics(CInstanceManager* iMan, CObject* object);
	~CPhysics();

	void		DeleteObject(BOOL bAll=FALSE);

	BOOL		EventProcess(const Event &event);

	void		SetBrain(CBrain* brain);
	void		SetMotion(CMotion* motion);

	void		SetType(PhysicsType type);
	PhysicsType	RetType();

	BOOL		Write(char *line);
	BOOL		Read(char *line);

	void		SetGravity(float value);
	float		RetGravity();

	float		RetFloorHeight();

	void		SetLinMotion(PhysicsMode mode, D3DVECTOR value);
	D3DVECTOR	RetLinMotion(PhysicsMode mode);
	void		SetLinMotionX(PhysicsMode mode, float value);
	void		SetLinMotionY(PhysicsMode mode, float value);
	void		SetLinMotionZ(PhysicsMode mode, float value);
	float		RetLinMotionX(PhysicsMode mode);
	float		RetLinMotionY(PhysicsMode mode);
	float		RetLinMotionZ(PhysicsMode mode);

	void		SetCirMotion(PhysicsMode mode, D3DVECTOR value);
	D3DVECTOR	RetCirMotion(PhysicsMode mode);
	void		SetCirMotionX(PhysicsMode mode, float value);
	void		SetCirMotionY(PhysicsMode mode, float value);
	void		SetCirMotionZ(PhysicsMode mode, float value);
	float		RetCirMotionX(PhysicsMode mode);
	float		RetCirMotionY(PhysicsMode mode);
	float		RetCirMotionZ(PhysicsMode mode);

	float		RetLinStopLength(PhysicsMode sMode=MO_ADVSPEED, PhysicsMode aMode=MO_STOACCEL);
	float		RetCirStopLength();
	float		RetLinMaxLength(float dir);
	float		RetLinTimeLength(float dist, float dir=1.0f);
	float		RetLinLength(float dist);

	void		SetMotor(BOOL bState);
	BOOL		RetMotor();
	void		SetLand(BOOL bState);
	BOOL		RetLand();
	void		SetSwim(BOOL bState);
	BOOL		RetSwim();
	void		SetCollision(BOOL bCollision);
	BOOL		RetCollision();
	void		SetFreeze(BOOL bFreeze);
	BOOL		RetFreeze();
	void		SetReactorRange(float range);
	float		RetReactorRange();

	void		SetMotorSpeed(D3DVECTOR speed);
	void		SetMotorSpeedX(float speed);
	void		SetMotorSpeedY(float speed);
	void		SetMotorSpeedZ(float speed);
	D3DVECTOR	RetMotorSpeed();
	float		RetMotorSpeedX();
	float		RetMotorSpeedY();
	float		RetMotorSpeedZ();

	void		CreateInterface(BOOL bSelect);
	Error		RetError();

protected:
	BOOL		EventFrame(const Event &event);
	void		WaterFrame(float aTime, float rTime);
	void		SoundMotor(float rTime);
	void		SoundMotorFull(float rTime, ObjectType type);
	void		SoundMotorSlow(float rTime, ObjectType type);
	void		SoundMotorStop(float rTime, ObjectType type);
	void		SoundReactorFull(float rTime, ObjectType type);
	void		SoundReactorStop(float rTime, ObjectType type);
	void		FrameParticule(float aTime, float rTime);
	void		MotorUpdate(float aTime, float rTime);
	void		EffectUpdate(float aTime, float rTime);
	void		UpdateMotionStruct(float rTime, Motion &motion);
	void		FloorAdapt(float aTime, float rTime, D3DVECTOR &pos, D3DVECTOR &angle);
	void		FloorAngle(const D3DVECTOR &pos, D3DVECTOR &angle);
	int			ObjectAdapt(const D3DVECTOR &pos, const D3DVECTOR &angle);
	BOOL		JostleObject(CObject* pObj, D3DVECTOR iPos, float iRad, D3DVECTOR oPos, float oRad);
	BOOL		JostleObject(CObject* pObj, float force);
	BOOL		ExploOther(ObjectType iType, CObject *pObj, ObjectType oType, float force);
	int			ExploHimself(ObjectType iType, ObjectType oType, float force);

	void		PowerParticule(float factor, BOOL bBreak);
	void		CrashParticule(float crash);
	void		MotorParticule(float aTime, float rTime);
	void		WaterParticule(float aTime, D3DVECTOR pos, ObjectType type, float floor, float advance, float turn);
	void		WheelParticule(int color, float width);

protected:
	CInstanceManager* m_iMan;
	CD3DEngine*	m_engine;
	CLight*		m_light;
	CParticule*	m_particule;
	CTerrain*	m_terrain;
	CWater*		m_water;
	CCamera*	m_camera;
	CObject*	m_object;
	CBrain*		m_brain;
	CMotion*	m_motion;
	CSound*		m_sound;

	PhysicsType	m_type;			// TYPE_*
	float		m_gravity;		// force de gravitation
	float		m_time;			// temps absolu
	D3DVECTOR	m_motorSpeed;	// vitesse du moteur (-1..1)
	Motion		m_linMotion;	// mouvement lin�aire
	Motion		m_cirMotion;	// mouvement circulaire
	BOOL		m_bMotor;
	BOOL		m_bLand;
	BOOL		m_bSwim;
	BOOL		m_bCollision;
	BOOL		m_bObstacle;
	BOOL		m_bFreeze;
	int			m_repeatCollision;
	float		m_linVibrationFactor;
	float		m_cirVibrationFactor;
	float		m_inclinaisonFactor;
	float		m_lastPowerParticule;
	float		m_lastSlideParticule;
	float		m_lastMotorParticule;
	float		m_lastWaterParticule;
	float		m_lastUnderParticule;
	float		m_lastPloufParticule;
	float		m_lastFlameParticule;
	BOOL		m_bWheelParticuleBrake;
	D3DVECTOR	m_wheelParticulePos[2];
	float		m_absorbWater;
	float		m_reactorTemperature;
	float		m_reactorRange;
	float		m_timeReactorFail;
	float		m_timeUnderWater;
	float		m_lastEnergy;
	float		m_lastSoundWater;
	float		m_lastSoundInsect;
	float		m_restBreakParticule;
	float		m_floorLevel;	// niveau du sol
	float		m_floorHeight;	// hauteur au-dessus du sol
	int			m_soundChannel;
	int			m_soundChannelSlide;
	float		m_soundTimePshhh;
	float		m_soundTimeJostle;
	float		m_soundTimeBoum;
	BOOL		m_bSoundSlow;
	BOOL		m_bForceUpdate;
	BOOL		m_bLowLevel;
};


#endif //_PHYSICS_H_