agent.h 3.81 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
#ifndef M_AGENT_H
#define M_AGENT_H

#include <iostream>

#include "utils.h"
#include "env_map.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
8
#include "spatialHashing.h"
9

10

Thomas Jund's avatar
Thomas Jund committed
11
// #define SECURED
pitiot's avatar
pitiot committed
12
//#define EXPORTING_AGENT   // trainée derriere l'agent
pitiot's avatar
merging    
pitiot committed
13

pitiot's avatar
pitiot committed
14
//#define EXPORTING_OBJ // skin mexicain
pitiot's avatar
pitiot committed
15
#define ARASH
16

17

Arash HABIBI's avatar
Arash HABIBI committed
18
19
#define SMOOTHING_BUFFER_SIZE 200

20

21
22
23
#ifdef SECURED
	#include "Algo/MovingObjects/particle_cell_2D_secured.h"
#else
24
25
26
27

#ifdef TWO_AND_HALF_DIM
	#include "Algo/MovingObjects/particle_cell_2DandHalf.h"
#else
28
29
	#include "Algo/MovingObjects/particle_cell_2D.h"
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
30

31
32
#endif

33
34
35
36
37
38
39
40
41
42
43
44
45
#ifdef EXPORTING_AGENT
	#include "Utils/vbo.h"
	#include "Utils/Shaders/shaderSimpleColor.h"
#endif

#ifdef EXPORTING_OBJ
	#include "Algo/Render/GL2/mapRender.h"
	#include "Utils/vbo.h"

	#include "Algo/Import/importObjTex.h"
	#include "shaderCustomTex.h"
#endif

David Cazier's avatar
David Cazier committed
46
class Simulator ;
Pierre Kraemer's avatar
Pierre Kraemer committed
47
48
49
50

class Agent
{
public:
51
	Agent(Simulator* sim, const VEC3& position, const VEC3& goals, Dart d) ;
David Cazier's avatar
David Cazier committed
52
	Agent(Simulator* sim, const VEC3& position, const VEC3& goals) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
53

54
55
	static void rotate(const VEC3& planeN1, const VEC3& planeN2, VEC3& project);

56
	void init(const VEC3& start, const VEC3& goal);
57
58
	void initGL();
	void draw();
Pierre Kraemer's avatar
Pierre Kraemer committed
59

David Cazier's avatar
David Cazier committed
60
	VEC3 getPosition() ;
61

David Cazier's avatar
David Cazier committed
62
63
	void updateAgentNeighbors() ;
	void updateObstacleNeighbors() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
64

pitiot's avatar
maj    
pitiot committed
65
66
67
68
	void update();
	void obstacle_priority(PFP::VEC3 * goalVector); //ajout moving obst
	void computePrefVelocity();
	void computeNewVelocity();
69

David Cazier's avatar
David Cazier committed
70
	void computeNewVelocity2() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
71

David Cazier's avatar
David Cazier committed
72
73
	bool linearProgram1(const std::vector<Line>& lines, unsigned int lineNo, float radius,
	                    const VEC3& optVelocity, bool directionOpt, VEC3& result) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
74

David Cazier's avatar
David Cazier committed
75
76
77
78
79
80
81
82
	unsigned int linearProgram2(const std::vector<Line>& lines, float radius,
	                            const VEC3& optVelocity, bool directionOpt, VEC3& result) ;

	void linearProgram3(const std::vector<Line>& lines, unsigned int numObstLines,
	                    unsigned int beginLine, float radius, VEC3& result) ;

	std::vector<std::pair<float, Agent*> > agentNeighbors_ ;
	std::vector<std::pair<float, Obstacle*> > obstacleNeighbors_ ;
pitiot's avatar
maj    
pitiot committed
83
	std::vector<std::pair<float, Obstacle*> > movingObstacleNeighbors_;
Pierre Kraemer's avatar
Pierre Kraemer committed
84

85
#ifdef EXPORTING_AGENT
86
	static const unsigned int m_ghost_nb = 500;
87
88
89
90
91
92
	std::list<VEC3> m_ghost_previousPos;
	Utils::VBO * m_ghost_VBO;
	Utils::ShaderSimpleColor * m_ghost_shader;
#endif

#ifdef EXPORTING_OBJ
Thomas Jund's avatar
Thomas Jund committed
93
94
95
//	PFP2::MAP map;
//	VertexAttribute<VEC3> position;
//	VertexAttribute<VEC3> normal;
96

97
98
//	VEC3 previousPos;
//	float previousRot;
Thomas Jund's avatar
Thomas Jund committed
99
	Geom::Matrix44f m_transfo;
100

Thomas Jund's avatar
Thomas Jund committed
101
102
103
//	Algo::Render::GL2::MapRender* m_render;
//	Utils::VBO* m_positionVBO;
//	Utils::VBO* m_normalVBO;
104

Thomas Jund's avatar
Thomas Jund committed
105
106
107
108
109
//	Utils::Texture<2,Geom::Vec3uc>* m_texture;
//	Utils::VBO* m_texcoordVBO;
//	ShaderCustomTex* m_shaderTex;
//	Algo::Surface::Import::OBJModel<PFP2> m_obj;
//	unsigned int m_nbIndices;
110
111
#endif

Pierre Kraemer's avatar
Pierre Kraemer committed
112
113
114
#ifdef SPATIAL_HASHING
	VEC3 pos ;
#else
115
	#ifdef SECURED
116
	CGoGN::Algo::Surface::MovingObjects::ParticleCell2DSecured<PFP> part_ ;
117
	#else
118
119
120
121

		#ifdef TWO_AND_HALF_DIM
		CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP> part_ ;
		#else
122
		CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP> part_ ;
123
		#endif
124
	#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
125
#endif
David Cazier's avatar
David Cazier committed
126

David Cazier's avatar
David Cazier committed
127
	unsigned int curGoal_ ;
David Cazier's avatar
David Cazier committed
128
129
130
131
132
	std::vector<VEC3> goals_ ;

	VEC3 finalGoal ;
	Dart finalDart ;

Arash HABIBI's avatar
Arash HABIBI committed
133
134
135
	MovingObstacle **movingObstacles_;
	int nb_mos;

136
137
	static VEC3 xyPlane;

David Cazier's avatar
David Cazier committed
138
	static unsigned int maxNeighbors_ ;
Arash HABIBI's avatar
Arash HABIBI committed
139
	static unsigned int maxMovingObstacles_;
pitiot's avatar
merge    
pitiot committed
140

David Cazier's avatar
David Cazier committed
141
	static float averageMaxSpeed_ ;
pitiot's avatar
pitiot committed
142
	static float panicSpeed;
David Cazier's avatar
David Cazier committed
143
144
145
146
147
148
149
	static float neighborDist_ ;
	static float neighborDistSq_ ;
	static float radius_ ;
	static float timeHorizon_ ;
	static float timeHorizonObst_ ;
	static float range_ ;
	static float rangeSq_ ;
Pierre Kraemer's avatar
Pierre Kraemer committed
150
151

	static unsigned int cptAgent ;
pitiot's avatar
maj    
pitiot committed
152

Thomas Jund's avatar
Thomas Jund committed
153
154
	VEC3 forces;

pitiot's avatar
maj    
pitiot committed
155
156
157
	float color1;
	float color2;
	float color3;
Pierre Kraemer's avatar
bla    
Pierre Kraemer committed
158
159
	unsigned int agentNo ;

David Cazier's avatar
David Cazier committed
160
	float maxSpeed_ ;
David Cazier's avatar
David Cazier committed
161
162
163
	VEC3 velocity_ ;
	VEC3 newVelocity_ ;
	VEC3 prefVelocity_ ;
Arash HABIBI's avatar
Arash HABIBI committed
164
	VEC3 meanVelocity_[SMOOTHING_BUFFER_SIZE] ;
David Cazier's avatar
David Cazier committed
165
	VEC3 meanDirection_ ;
166

pitiot's avatar
pitiot committed
167
	float ratio;
pitiot's avatar
maj    
pitiot committed
168
169
170
	Simulator* sim_;
	bool alive;
};
Pierre Kraemer's avatar
Pierre Kraemer committed
171
172

#endif