viewer.cpp 66.6 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
/*******************************************************************************
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
 * Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
 *                                                                              *
 * This library is free software; you can redistribute it and/or modify it      *
 * under the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation; either version 2.1 of the License, or (at your     *
 * option) any later version.                                                   *
 *                                                                              *
 * This library 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 Lesser General Public License  *
 * for more details.                                                            *
 *                                                                              *
 * You should have received a copy of the GNU Lesser General Public License     *
 * along with this library; if not, write to the Free Software Foundation,      *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
 *                                                                              *
 * Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
24
25

#include "viewer.h"
26
#include "env_generator.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
27
#include <string>
Thomas Jund's avatar
Thomas Jund committed
28
#include "glm/gtc/type_ptr.hpp"
Thomas Jund's avatar
Thomas Jund committed
29
#include "Algo/Export/export.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30
31


pitiot's avatar
pitiot committed
32
SocialAgents::SocialAgents(unsigned int config, unsigned int minSize, unsigned int nbAgent, unsigned int nbObst,bool resolution, unsigned int iterations) :
33
34
35
#ifdef EXPORTING_OBJ
	m_objAgent(mapAgent),
#endif
36
	m_renderStyle(0),
David Cazier's avatar
David Cazier committed
37
38
	nbIterations(0),
	maxIterations(iterations),
Thomas Jund's avatar
Thomas Jund committed
39
	nbGeneratedPov(0),
David Cazier's avatar
David Cazier committed
40
	frames(0),
pitiot's avatar
maj    
pitiot committed
41
	nextUpdate(0),
pitiot's avatar
pitiot committed
42
	simulator(config, minSize, nbAgent, nbObst, resolution),
David Cazier's avatar
David Cazier committed
43
	render_anim(false),
Thomas Jund's avatar
Thomas Jund committed
44
45
	drawEnvLines(false),
	drawEnvFaces(true),
David Cazier's avatar
David Cazier committed
46
	drawEnvTopo(false),
pitiot's avatar
maj    
pitiot committed
47
48
	drawObstacles(false),
	drawMovingObstacles(true),
David Cazier's avatar
David Cazier committed
49
50
51
	drawAgents(true),
	drawAgentsNeighborDist(false),
	drawAgentsObstacleDist(false),
pitiot's avatar
maj    
pitiot committed
52
	drawAgentsPredictionTri(false),
53
	drawAgentsPath(false),
pitiot's avatar
pitiot committed
54
	drawObstPredictionTri(false),
55
	drawObstPath(false),
pitiot's avatar
merging    
pitiot committed
56
	draw_dart(false),
pitiot's avatar
pitiot committed
57
	target_Agent(false),
58
	draw_posX(false),
59
60
	draw_elipse(false),
	display_times(false)
Pierre Kraemer's avatar
Pierre Kraemer committed
61
{
David Cazier's avatar
David Cazier committed
62
	timer = new QTimer(this) ;
pitiot's avatar
stats    
pitiot committed
63
64
65
66
67
68
69
70
71
72
73
74

	switch (config){
		case 0 :name<<"cercle_";break;
		case 1 :name<<"corridor_";break;
		case 2 :name<<"corridorSnake_";break;
		case 3 :name<<"ville_";break;
		case 5 :name<<"strasbourg_";break;
		default : break;
	}

	filename<<name.str().c_str()<<nbAgent<<"_"<<nbObst<<"_"<<resolution;
	percent = false;
75
76
	time_update = 0 ;
	elapsedTime = 0;
David Cazier's avatar
David Cazier committed
77
	connect(timer, SIGNAL(timeout()), this, SLOT(animate())) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
78

pitiot's avatar
maj    
pitiot committed
79
	clock_gettime(CLOCK_MONOTONIC, &startTime) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
80

81
	glEnable(GL_POINT_SMOOTH) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
82
83
}

Pierre Kraemer's avatar
Pierre Kraemer committed
84
void SocialAgents::initGUI()
Pierre Kraemer's avatar
Pierre Kraemer committed
85
{
David Cazier's avatar
David Cazier committed
86
	setDock(&dock) ;
pitiot's avatar
pitiot committed
87
//	dock.check_timer->setChecked(render_anim);
pitiot's avatar
maj    
pitiot committed
88
89
90
91
	dock.check_drawEnvLines->setChecked(drawEnvLines) ;
	dock.check_drawEnvFaces->setChecked(drawEnvFaces) ;
	dock.check_drawAgents->setChecked(drawAgents) ;
	dock.check_drawMovingObstacles->setChecked(drawMovingObstacles) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
92

David Cazier's avatar
David Cazier committed
93
94
95
96
97
	setCallBack(dock.check_timer, SIGNAL(toggled(bool)), SLOT(slot_timer(bool))) ;
	setCallBack(dock.check_drawEnvLines, SIGNAL(toggled(bool)), SLOT(slot_drawEnvLines(bool))) ;
	setCallBack(dock.check_drawEnvFaces, SIGNAL(toggled(bool)), SLOT(slot_drawEnvFaces(bool))) ;
	setCallBack(dock.check_drawEnvTopo, SIGNAL(toggled(bool)), SLOT(slot_drawEnvTopo(bool))) ;
	setCallBack(dock.check_drawObstacles, SIGNAL(toggled(bool)), SLOT(slot_drawObstacles(bool))) ;
pitiot's avatar
maj    
pitiot committed
98
	setCallBack(dock.check_drawMovingObstacles, SIGNAL(toggled(bool)), SLOT(slot_drawMovingObstacles(bool))) ;
David Cazier's avatar
David Cazier committed
99
	setCallBack(dock.check_drawAgents, SIGNAL(toggled(bool)), SLOT(slot_drawAgents(bool))) ;
pitiot's avatar
maj    
pitiot committed
100
	setCallBack(dock.check_drawAgentsPredictionTri, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsPredictionTri(bool))) ;
pitiot's avatar
pitiot committed
101
	setCallBack(dock.check_drawObstPredictionTri, SIGNAL(toggled(bool)), SLOT(slot_drawObstPredictionTri(bool))) ;
pitiot's avatar
maj    
pitiot committed
102
103
	setCallBack(dock.check_drawAgentsNeighborDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsNeighborDist(bool))) ;
	setCallBack(dock.check_drawAgentsObstacleDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsObstacleDist(bool))) ;
104
	setCallBack(dock.check_drawAgentsPath, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsPath(bool))) ;
105
	setCallBack(dock.check_drawObstPath, SIGNAL(toggled(bool)), SLOT(slot_drawObstPath(bool))) ;
pitiot's avatar
maj    
pitiot committed
106
107
	setCallBack(dock.check_dart, SIGNAL(toggled(bool)), SLOT(slot_dart(bool))) ;
	setCallBack(dock.check_slide, SIGNAL(valueChanged(int)), SLOT(slot_slide(int))) ;
108
109
110
	setCallBack(dock.check_pos, SIGNAL(toggled(bool)), SLOT(slot_posX(bool))) ;
	setCallBack(dock.check_x_val, SIGNAL(valueChanged(int)), SLOT(slot_slide2(int))) ;
	setCallBack(dock.check_y_val, SIGNAL(valueChanged(int)), SLOT(slot_slide3(int))) ;
pitiot's avatar
merging    
pitiot committed
111
	setCallBack(dock.check_elipse, SIGNAL(toggled(bool)), SLOT(slot_elipse(bool))) ;
pitiot's avatar
pitiot committed
112
113
	setCallBack(dock.checkAgent, SIGNAL(toggled(bool)), SLOT(slot_Agent(bool))) ;
	setCallBack(dock.AgentSelect, SIGNAL(valueChanged(int)), SLOT(slot_AgentSlider(int))) ;
Thomas Jund's avatar
Thomas Jund committed
114
115
116

	dock.check_x_val->setRange(-100000, 100000) ;
	dock.check_y_val->setRange(-100000, 100000) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
117
}
Pierre Kraemer's avatar
Pierre Kraemer committed
118

Pierre Kraemer's avatar
Pierre Kraemer committed
119
120
void SocialAgents::cb_initGL()
{
Thomas Jund's avatar
Thomas Jund committed
121
122
123
	std::cout << "initGL" << std::endl;

	colClear = Geom::Vec4f(0.7f, 0.7f, 0.7f, 0.5f) ;
Thomas Jund's avatar
Thomas Jund committed
124
	colDif = Geom::Vec4f(0.3f, 0.3f, 0.3f, 1.0f) ;
Thomas Jund's avatar
Thomas Jund committed
125
126
	colSpec = Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f) ;
	colNormal = Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
127

David Cazier's avatar
David Cazier committed
128
	bb = Algo::Geometry::computeBoundingBox<PFP>(simulator.envMap_.map, simulator.envMap_.position) ;
Thomas Jund's avatar
Thomas Jund committed
129
130
131
132
133
134
135
	if(simulator.config==5)
	{
		Geom::BoundingBox<PFP::VEC3> bbBuilding = Algo::Geometry::computeBoundingBox<PFP>(simulator.envMap_.mapScenary, simulator.envMap_.positionScenary) ;
		bb.addPoint(bbBuilding.min());
		bb.addPoint(bbBuilding.max());
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
136
137
138
139
	VEC3 gPosObj = bb.center() ;
	float tailleX = bb.size(0) ;
	float tailleY = bb.size(1) ;
	float tailleZ = bb.size(2) ;
140
141
142
143
144
	float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;

	if(simulator.config<6)
		gWidthObj /= 5.0f;

145
	setParamObject(gWidthObj, gPosObj.data()) ;
Thomas Jund's avatar
Thomas Jund committed
146

147
148
	std::cout << "Bb " << bb << std::endl;

Thomas Jund's avatar
Thomas Jund committed
149
150
151
152
153
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);

	// create the render
	m_render = new Algo::Render::GL2::MapRender();
Thomas Jund's avatar
Thomas Jund committed
154
155
156
157
#ifdef ONERING
	m_renderWithin = new Algo::Render::GL2::MapRender();
#endif

Thomas Jund's avatar
Thomas Jund committed
158
	m_renderTopo = new Algo::Render::GL2::TopoRender();
159
	m_ds = new Utils::Drawer();
Thomas Jund's avatar
Thomas Jund committed
160

Thomas Jund's avatar
Thomas Jund committed
161
162
163
	if(simulator.config==5)
		m_renderPedway = new Algo::Render::GL2::MapRender();

Thomas Jund's avatar
Thomas Jund committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
	// create VBO for position
	m_positionVBO = new Utils::VBO();
	m_normalVBO = new Utils::VBO() ;

	// using simple shader with color
	m_simpleColorShader = new Utils::ShaderSimpleColor();
	m_simpleColorShader->setAttributePosition(m_positionVBO);
	m_simpleColorShader->setColor(Geom::Vec4f(0.,1.,0.,0.));

	m_positionVBO->updateData(simulator.envMap_.position) ;
	m_normalVBO->updateData(simulator.envMap_.normal) ;

	if(simulator.config==5)
	{
		m_render_scenary = new Algo::Render::GL2::MapRender();

		m_positionVBO_scenary = new Utils::VBO();
		m_normalVBO_scenary = new Utils::VBO() ;

		m_positionVBO_scenary->updateData(simulator.envMap_.positionScenary) ;
		m_normalVBO_scenary->updateData(simulator.envMap_.normalScenary) ;

Thomas Jund's avatar
Thomas Jund committed
186
187
188
#ifdef EXPORTING
		m_flatShader_scenary = new ShaderCustom();
#else
Thomas Jund's avatar
Thomas Jund committed
189
		m_flatShader_scenary = new Utils::ShaderFlat();
Thomas Jund's avatar
Thomas Jund committed
190
#endif
Thomas Jund's avatar
Thomas Jund committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
		m_flatShader_scenary->setAttributePosition(m_positionVBO_scenary);
		m_flatShader_scenary->setAmbiant(colClear) ;
		m_flatShader_scenary->setDiffuse(colDif) ;

		registerShader(m_flatShader_scenary);
	}

	m_agentsVBO = new Utils::VBO();
	m_agentsVBO->setDataSize(3);
	m_agentsVBO->allocate(simulator.agents_.size());


	PFP::VEC3* data = static_cast<PFP::VEC3*>(m_agentsVBO->lockPtr());
	for (unsigned int i=0; i< simulator.agents_.size(); ++i)
	{
		VEC3 p = simulator.agents_[i]->getPosition();
		data[i] = p;
	}
	m_agentsVBO->releasePtr();

	m_sprite = new Utils::PointSprite();
	m_sprite->setAttributePosition(m_agentsVBO);
213
214
	m_sprite->setSize(Agent::radius_);
//	m_sprite->setSize((50.0f/gWidthObj) *  Agent::radius_ );
Thomas Jund's avatar
Thomas Jund committed
215
216
217
218

	registerShader(m_simpleColorShader);
	registerShader(m_sprite);

Arash HABIBI's avatar
Arash HABIBI committed
219
220
221
	qglviewer::Camera* cam = getQGLWidget()->camera();
	cam->setSceneRadius(10000);

Thomas Jund's avatar
Thomas Jund committed
222
223
224
225
226
	initRendering();
}

void SocialAgents::initRendering()
{
227
228
229
//	dCD = new Utils::Drawer();
//	registerShader(dCD->getShader());

Thomas Jund's avatar
Thomas Jund committed
230
231
	if(simulator.config==5)
	{
Sylvain Thery's avatar
Sylvain Thery committed
232
233
		m_render_scenary->initPrimitives<PFP>(simulator.envMap_.mapScenary, Algo::Render::GL2::LINES,false) ;
		m_render_scenary->initPrimitives<PFP>(simulator.envMap_.mapScenary, Algo::Render::GL2::TRIANGLES,false) ;
Thomas Jund's avatar
Thomas Jund committed
234

235
236
237
		MapBrowserSelector mbs(simulator.envMap_.map,SelectorCellMarked<FACE>(simulator.envMap_.pedWayMark));
		simulator.envMap_.map.setBrowser(&mbs);

Sylvain Thery's avatar
Sylvain Thery committed
238
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ;
239
240
241
		m_renderPedway->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ;

		simulator.envMap_.map.setBrowser(NULL);
Thomas Jund's avatar
Thomas Jund committed
242

243
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ;
Sylvain Thery's avatar
Sylvain Thery committed
244
		m_renderPedway->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ;
Thomas Jund's avatar
Thomas Jund committed
245
246
247
	}
	else
	{
Sylvain Thery's avatar
Sylvain Thery committed
248
249
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ;
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ;
Thomas Jund's avatar
Thomas Jund committed
250
251
252
253

#ifdef ONERING
		m_renderWithin->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ;
#endif
Thomas Jund's avatar
Thomas Jund committed
254
255
	}

Sylvain Thery's avatar
Sylvain Thery committed
256
	m_renderTopo->updateData<PFP>(simulator.envMap_.map, simulator.envMap_.position, 0.9, 0.9);
Thomas Jund's avatar
Thomas Jund committed
257
258
259
260
261
262
263


	for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
	{
		m_obst_render.push_back(new Algo::Render::GL2::MapRender());

		Utils::ShaderFlat * shader = new Utils::ShaderFlat();
264
265
		shader->setAmbiant(Geom::Vec4f(1.,1.,0.,0.)) ;
		shader->setDiffuse(Geom::Vec4f(1.,1.,0.,0.));
Thomas Jund's avatar
Thomas Jund committed
266
267
268
269
270
271
272
273
274

		Utils::VBO * vbo = new Utils::VBO();
		vbo->setDataSize(3);
		vbo->allocate(simulator.movingObstacles_[i]->nbVertices);
		shader->setAttributePosition(vbo);

		m_obst_VBO.push_back(vbo);
		m_obstShader.push_back(shader);
		registerShader(shader);
275
276
277
278
279

		simulator.movingObstacles_[i]->initGL();
#ifdef EXPORTING_BOXES
		registerShader(simulator.movingObstacles_[i]->m_shader);
#endif
Thomas Jund's avatar
Thomas Jund committed
280
281
282
	}

	updateObstacleVBO();
Thomas Jund's avatar
Thomas Jund committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350

#ifdef EXPORTING

#if 1
	m_Ground_VBO = new Utils::VBO();
	m_Ground_VBO->setDataSize(3);
	m_Ground_VBO->allocate(4);
	PFP::VEC3* data = static_cast<PFP::VEC3*>(m_Ground_VBO->lockPtr());
	data[0] = VEC3(bb.min()[0], bb.min()[1], 0);
	data[1] = VEC3(bb.max()[0], bb.min()[1], 0);
	data[2] = VEC3(bb.max()[0], bb.max()[1], 0);
	data[3] = VEC3(bb.min()[0], bb.max()[1], 0);
	m_Ground_VBO->releasePtr();
#else
	m_Ground_VBO = new Utils::VBO();
	m_Ground_VBO->setDataSize(3);
	m_Ground_VBO->allocate(4*N_THETA*N_PHI);
	PFP::VEC3* data = static_cast<PFP::VEC3*>(m_Ground_VBO->lockPtr());

	for( unsigned int i=0, n=0; i<N_THETA; ++i )
	{
		float theta1 = M_PI* i   /N_THETA;
		float theta2 = M_PI*(i+1)/N_THETA;

		for( unsigned int j=0; j<N_PHI; ++j )
		{
			float phi1 = 2.0f*M_PI* j   /N_PHI;
			float phi2 = 2.0f*M_PI*(j+1)/N_PHI;

			float x, y, z;

			x = RADIUS * std::sin(theta1) * std::cos(phi1);
			y = RADIUS * std::cos(theta1);
			z = RADIUS * std::sin(theta1) * std::sin(phi1);
			data[n++] = VEC3(x,y,z);

			x = RADIUS * std::sin(theta1) * std::cos(phi2);
			y = RADIUS * std::cos(theta1);
			z = RADIUS * std::sin(theta1) * std::sin(phi2);
			data[n++] = VEC3(x,y,z);

			x = RADIUS * std::sin(theta2) * std::cos(phi2);
			y = RADIUS * std::cos(theta2);
			z = RADIUS * std::sin(theta2) * std::sin(phi2);
			data[n++] = VEC3(x,y,z);

			x = RADIUS * std::sin(theta2) * std::cos(phi1);
			y = RADIUS * std::cos(theta2);
			z = RADIUS * std::sin(theta2) * std::sin(phi1);
			data[n++] = VEC3(x,y,z);
		}
	}
	m_Ground_VBO->releasePtr();
#endif

	m_Ground_Shader = new Utils::ShaderFlat();
	m_Ground_Shader->setAmbiant (Geom::Vec4f(0.6f, 0.8f, 0.6f, 1.0f));
	m_Ground_Shader->setDiffuse (Geom::Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
	m_Ground_Shader->setAttributePosition(m_Ground_VBO);
	registerShader(m_Ground_Shader);

	if( !m_DeferedShader.loadShaders("./shaders/Defered.vert", "./shaders/Defered.frag") )
		std::cout << __FUNCTION__ << ": pas glop!" << std::endl;

	if( !m_DeferedShader2.loadShaders("./shaders/Defered2.vert", "./shaders/Defered2.frag") )
		std::cout << __FUNCTION__ << ": pas glop!" << std::endl;

#endif
Thomas Jund's avatar
Thomas Jund committed
351
352

	for(unsigned int i = 0 ; i < simulator.movingMeshes_.size() ; ++i)
Thomas Jund's avatar
Thomas Jund committed
353
354
	{
		simulator.movingMeshes_[i]->initGL();
Thomas Jund's avatar
Thomas Jund committed
355
#ifdef EXPORTING2
Thomas Jund's avatar
Thomas Jund committed
356
357
		registerShader(simulator.movingMeshes_[i]->m_shaderTex);
#else
Thomas Jund's avatar
Thomas Jund committed
358
		registerShader(simulator.movingMeshes_[i]->m_simpleColorShader);
Thomas Jund's avatar
Thomas Jund committed
359
360
#endif
	}
361
362
363
364
365
366
367

	simulator.envMap_.initGL();
#ifdef EXPORTING3
	for(unsigned int j = 0 ; j < simulator.envMap_.m_shaderTex_Export.size() ; ++j)
		registerShader(simulator.envMap_.m_shaderTex_Export[j]);
#endif

368
#ifdef EXPORTING_OBJ
Thomas Jund's avatar
Thomas Jund committed
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
	std::vector<std::string> attrNames ;
	m_objAgent.import("./meshRessources/Mexicainlowres2.obj",attrNames);
//	m_objAgent.import("./meshRessources/Mexicainhighres.obj",attrNames);
	positionAgent = mapAgent.getAttribute<VEC3, VERTEX>(attrNames[0]) ;

//	Geom::BoundingBox<PFP::VEC3> bb ;
//	bb = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
//	std::cout << "bb agent " << bb << std::endl;

	TraversorV<PFP2::MAP> tV(mapAgent);
	for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
	{
		positionAgent[d] /= 12.0f;
		positionAgent[d] *= Agent::radius_;
	}

	m_texcoordVBOAgent = new Utils::VBO();
	m_positionVBOAgent = new Utils::VBO();
	m_normalVBOAgent = new Utils::VBO();

	m_textureAgent = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);

//	if (m_textureAgent->load("./meshRessources/sombrero2lowres_grp.png"))
	if (m_textureAgent->load("./meshRessources/sombrero2_grp.png"))
			m_textureAgent->update();
	else
		std::cout << "problem : loading texture" << std::endl;

	m_textureAgent->setWrapping(GL_CLAMP_TO_EDGE);

	m_shaderTexAgent = new ShaderCustomTex();
	m_shaderTexAgent->setAttributePosition(m_positionVBOAgent);
	m_shaderTexAgent->setAttributeTexCoord(m_texcoordVBOAgent);
	m_shaderTexAgent->setTextureUnit(GL_TEXTURE0);
	m_shaderTexAgent->setTexture(m_textureAgent);

	glEnable(GL_TEXTURE_2D);

	if (!m_objAgent.hasNormals())
	{
		normalAgent = mapAgent.getAttribute<VEC3, VERTEX>("normal") ;
		if(!normalAgent.isValid())
			normalAgent = mapAgent.addAttribute<VEC3, VERTEX>("normal") ;

		Algo::Surface::Geometry::computeNormalVertices<PFP2>(mapAgent, m_objAgent.m_positions, normalAgent) ;
		m_objAgent.setNormalAttribute(normalAgent);
	}

	mapAgent.setBrowser(NULL);

	m_nbIndicesAgent = m_objAgent.createSimpleVBO_PTN(m_positionVBOAgent,m_texcoordVBOAgent,m_normalVBOAgent);

	registerShader(m_shaderTexAgent);
422
#endif
Thomas Jund's avatar
Thomas Jund committed
423

pitiot's avatar
pitiot committed
424
#ifdef EXPORTING_AGENT
Thomas Jund's avatar
Thomas Jund committed
425
426
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
Thomas Jund's avatar
merge    
Thomas Jund committed
427
			simulator.agents_[i]->initGL();
Thomas Jund's avatar
Thomas Jund committed
428
429
430
431
//
//#ifdef EXPORTING_OBJ
//			registerShader(simulator.agents_[i]->m_shaderTex);
//#endif
432
433
434
			registerShader(simulator.agents_[i]->m_ghost_shader);
		}
#endif
435
436
437
438
439
440
441
442
//	bb = Algo::Geometry::computeBoundingBox<PFP>(simulator.envMap_.m_map_Export, simulator.envMap_.position_Export) ;
//
//	VEC3 gPosObj = bb.center() ;
//	float tailleX = bb.size(0) ;
//	float tailleY = bb.size(1) ;
//	float tailleZ = bb.size(2) ;
//	float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ);///10.0f ;
//	setParamObject(gWidthObj, gPosObj.data()) ;
Thomas Jund's avatar
Thomas Jund committed
443
444
445
446
447
448
449
450
451
452
453
454
455
}

void SocialAgents::updateObstacleVBO()
{
	for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
	{
		Utils::VBO * vbo = m_obst_VBO[i];
		PFP::VEC3* data = static_cast<PFP::VEC3*>(vbo->lockPtr());
		for (unsigned int j=0; j< simulator.movingObstacles_[i]->nbVertices; ++j)
		{
			VEC3 p = simulator.movingObstacles_[i]->getDilatedPosition(j);
			data[j] = p;
		}
Thomas Jund's avatar
Thomas Jund committed
456

Thomas Jund's avatar
Thomas Jund committed
457
458
459
460
461
462
		vbo->releasePtr();
	}
}

void SocialAgents::updateObstaclePredTriVBO()
{
pitiot's avatar
pitiot committed
463
//	CGoGNout<<"update"<<CGoGNendl;
Thomas Jund's avatar
Thomas Jund committed
464
465
466
467
468
	for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
	{

		Utils::VBO * vbo = m_triObst_VBO[i];
		PFP::VEC3* data = static_cast<PFP::VEC3*>(vbo->lockPtr());
pitiot's avatar
up    
pitiot committed
469
470
471
472
473
		for(unsigned int j =0; j<simulator.movingObstacles_[i]->nbVertices; j++ )
		{
			VEC3 p = simulator.movingObstacles_[i]->getDilatedPosition(j);
			data[j*4+0] = p;
			data[j*4+3] = p;
Thomas Jund's avatar
Thomas Jund committed
474

pitiot's avatar
up    
pitiot committed
475
476
			p = simulator.envMap_.position[simulator.movingObstacles_[i]->parts_[j]->d];
			data[j*4+1] = p;
Thomas Jund's avatar
Thomas Jund committed
477

pitiot's avatar
up    
pitiot committed
478
479
			p = simulator.envMap_.position[simulator.envMap_.map.phi1(simulator.movingObstacles_[i]->parts_[j]->d)];
			data[j*4+2] = p;
Thomas Jund's avatar
Thomas Jund committed
480

481
482

		}
Thomas Jund's avatar
Thomas Jund committed
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
		vbo->releasePtr();
	}
}

void SocialAgents::updateAgentPredTriVBO()
{
	for(unsigned int i=0 ; i < simulator.agents_.size() ; ++i)
	{
		Utils::VBO * vbo = m_triAgent_VBO[i];
		PFP::VEC3* data = static_cast<PFP::VEC3*>(vbo->lockPtr());

		VEC3 p = simulator.agents_[i]->getPosition();
		data[0] = p;

		p = simulator.envMap_.position[simulator.agents_[i]->part_.d];
		data[1] = p;

		p = simulator.envMap_.position[simulator.envMap_.map.phi1(simulator.agents_[i]->part_.d)];
		data[2] = p;

		vbo->releasePtr();
	}
}

void SocialAgents::updateVBOprimitives(int upType)
{
Thomas Jund's avatar
Thomas Jund committed
509
510
511
512
513
514
515
516
517
518
519
520
#ifdef ONERING
	CellMarker<FACE> cmF(simulator.envMap_.map);
	TraversorF<PFP::MAP> tF(simulator.envMap_.map);
	for(Dart d = tF.begin() ; d != tF.end() ; d = tF.next())
	{
		if(simulator.envMap_.neighborObstvect[d].size() > 0 && !(simulator.envMap_.obstvect[d].size()>0))
			cmF.mark(d);
	}

	MapBrowserSelector mbs1(simulator.envMap_.map,SelectorCellMarked<FACE>(cmF));
	simulator.envMap_.map.setBrowser(&mbs1);

Thomas Jund's avatar
Thomas Jund committed
521
	if(upType & Algo::Render::GL2::TRIANGLES)
Sylvain Thery's avatar
Sylvain Thery committed
522
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES, false) ;
Thomas Jund's avatar
Thomas Jund committed
523

Thomas Jund's avatar
Thomas Jund committed
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
	simulator.envMap_.map.setBrowser(NULL);

	CellMarker<FACE> cmF2(simulator.envMap_.map);
	TraversorF<PFP::MAP> tF2(simulator.envMap_.map);
	for(Dart d = tF.begin() ; d != tF.end() ; d = tF.next())
	{
		if(simulator.envMap_.obstvect[d].size() > 0)
		{
			cmF2.mark(d);
		}
	}

	MapBrowserSelector mbs2(simulator.envMap_.map,SelectorCellMarked<FACE>(cmF2));
	simulator.envMap_.map.setBrowser(&mbs2);

	if(upType & Algo::Render::GL2::TRIANGLES)
		m_renderWithin->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES, false) ;

	simulator.envMap_.map.setBrowser(NULL);
#else
	if(upType & Algo::Render::GL2::TRIANGLES)
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES, false) ;
#endif


Thomas Jund's avatar
Thomas Jund committed
549
	if(upType & Algo::Render::GL2::LINES)
Sylvain Thery's avatar
Sylvain Thery committed
550
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ;
Thomas Jund's avatar
Thomas Jund committed
551
552

	if(upType & Algo::Render::GL2::POINTS)
Sylvain Thery's avatar
Sylvain Thery committed
553
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::POINTS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
554
}
Pierre Kraemer's avatar
Pierre Kraemer committed
555

Arash HABIBI's avatar
Arash HABIBI committed
556
557
558
559
560
//-----------------------------------
// An ellipse has two foci placed at
// F1 and F2. The ellipse is the set
// of points M for whom MF1 + MF2 = s

pitiot's avatar
pitiot committed
561
562
//static void drawEllipse(VEC3 F1, VEC3 F2, float s, int N)
//{
Thomas Jund's avatar
Thomas Jund committed
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
//	float a,b=0;
//	VEC3 O,u,v;
//	O = 0.5f*(F1+F2);
//	u = F1-F2;
//	float c = (F1-F2).norm();
//	if(c==0)
//	{
//		u[0] = 1.0;
//		u[1] = 0.0;
//		v[0] = 0.0;
//		v[1] = 1.0;
//		a=s/2;
//		b=s/2;
//	}
//	else // c>0
//	{
//		u = (1.0f/c) * u;
//		v.zero();
//		v[0] = u[1];
//		v[1] = -u[0];
//
//		c = 0.5 * c;
//		a = s/2.0;
//		if(a<c)
//		{
//			cerr << "a=" << a << " and c=" << c << endl;
//			cerr << "No such an ellipse is possible" << endl;
//		}
//		else // a >= c
//			b = sqrt( a*a - c*c );
//	}
Thomas Jund's avatar
Thomas Jund committed
594
595
596
597
598
599
600
601
602
603
604
//	glBegin(GL_LINE_LOOP);
//	VEC3 M;
//	float dtheta = 2 * M_PI / N;
//	float theta;
//	for(theta=0; theta<2*M_PI; theta+=dtheta)
//	{
//		M = O + a*cos(theta)*u + b*sin(theta)*v;
//		glColor3f(0,0,1);
//		glVertex2f(M[0],M[1]);
//	}
//	glEnd();
pitiot's avatar
pitiot committed
605
//}
Arash HABIBI's avatar
Arash HABIBI committed
606
607
608

//-----------------------------------

Thomas Jund's avatar
Thomas Jund committed
609
610
611
612
613
614
615
616
617
618
619
620
void SocialAgents::moveCameraTo(VEC3 newPos)
{
	float& x = trans_x();
	float& y = trans_y();
	float& z = trans_z();

	x = newPos[0];
	y = newPos[1];
	z = newPos[2];

//	transfoTranslate(newPos[0],newPos[1],newPos[2]);

621
622
623
624
625
626
627
628
629
630
631
632
//	float * quat = curquat();
//
//	float theta = M_PI/2.0f;
//	float qx = 1 * sin(theta/2.0f);
//	float qy = 0 * sin(theta/2.0f);
//	float qz = 0 * sin(theta/2.0f);
//	float qw = cos(theta/2.0f);
//
//	quat[0] = qx;
//	quat[1] = qy;
//	quat[2] = qz;
//	quat[3] = qw;
Thomas Jund's avatar
Thomas Jund committed
633
634
635
636

	updateGLMatrices();
}

Pierre Kraemer's avatar
Pierre Kraemer committed
637
638
void SocialAgents::cb_redraw()
{
Thomas Jund's avatar
Thomas Jund committed
639
640
641
642
643
644
645
646
647
648
649
650
651
652
	pushTransfoMatrix();

#ifdef EXPORTING
	Utils::FBO fbo( width(), height() );
	int deferedColorAttachment = fbo.createAttachColorTexture( GL_RGB );
	int deferedNormalAttachment = fbo.createAttachColorTexture( GL_RGB );
	fbo.createAttachDepthTexture();
	fbo.bind();
	fbo.enableAllColorAttachments();
#endif

	glClearColor( 0.8f, 0.8f, 1.0f, 1.0f );
	glClear( GL_COLOR_BUFFER_BIT );

Thomas Jund's avatar
Thomas Jund committed
653
//	glEnable(GL_CULL_FACE);
Thomas Jund's avatar
Thomas Jund committed
654
655
656
657
658
	glEnable(GL_MULTISAMPLE);
	glEnable(GL_LINE_SMOOTH);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glEnable(GL_POINT_SMOOTH);
	glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
Thomas Jund's avatar
Thomas Jund committed
659

Thomas Jund's avatar
Thomas Jund committed
660
661
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
	glEnable(GL_LIGHTING);
pitiot's avatar
maj    
pitiot committed
662

663
	glEnable( GL_MULTISAMPLE );
664
	simulator.envMap_.draw();
Thomas Jund's avatar
Thomas Jund committed
665

Thomas Jund's avatar
Thomas Jund committed
666
	dock.check_slide->setRange(0, simulator.envMap_.map.end().index) ;
667

David Cazier's avatar
David Cazier committed
668
669
	if (drawAgents)
	{
Thomas Jund's avatar
Thomas Jund committed
670
#ifdef EXPORTING_OBJ
Thomas Jund's avatar
Thomas Jund committed
671
672
673
674
675
676
677
678
679
680
681
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
			m_nbIndicesAgent = m_objAgent.createSimpleVBO_PTN(m_positionVBOAgent,m_texcoordVBOAgent,m_normalVBOAgent);
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

			m_shaderTexAgent->setTransformation(simulator.agents_[i]->m_transfo);
			m_shaderTexAgent->activeTexture();
			m_shaderTexAgent->enableVertexAttribs();
			glDrawArrays(GL_TRIANGLES, 0, m_nbIndicesAgent);
			m_shaderTexAgent->disableVertexAttribs();
		}
Thomas Jund's avatar
Thomas Jund committed
682
#else
Thomas Jund's avatar
Thomas Jund committed
683
684
685
686
687
688
689
		PFP::VEC3* data = static_cast<PFP::VEC3*>(m_agentsVBO->lockPtr());
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
			VEC3 p = simulator.agents_[i]->getPosition();
			data[i] = p;
		}
		m_agentsVBO->releasePtr();
Pierre Kraemer's avatar
Pierre Kraemer committed
690

Thomas Jund's avatar
Thomas Jund committed
691
692
693
694
695
		m_sprite->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f));
		m_sprite->enableVertexAttribs();
		glDrawArrays(GL_POINTS, 0, simulator.agents_.size());
		m_sprite->disableVertexAttribs();
		m_sprite->postdraw();
Thomas Jund's avatar
Thomas Jund committed
696
#endif
Thomas Jund's avatar
Thomas Jund committed
697

Thomas Jund's avatar
Thomas Jund committed
698
#ifdef EXPORTING_AGENT
699
700
701
702
703
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
			simulator.agents_[i]->draw();
		}
#endif
Thomas Jund's avatar
Thomas Jund committed
704

705
706
707
708
		if(target_Agent)
		{
			glDisable(GL_LIGHTING);
			VEC3 pos =simulator.agents_[agentSlider]->part_.getPosition();
Thomas Jund's avatar
Thomas Jund committed
709
			m_ds->newList(GL_COMPILE_AND_EXECUTE);
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
			m_ds->lineWidth(5.0f);
			m_ds->pointSize(10.0f);
			m_ds->begin(GL_POINTS);
			// fait varier la couleur du plus pres au plus loin

			m_ds->color3f(0.0f , 1.0f, 0.9f);

			m_ds->vertex(pos);
			m_ds->vertex(pos+VEC3(0,0,50));

			m_ds->vertex(pos+VEC3(0,10,50));

			m_ds->end();
			m_ds->endList();
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
725
	}
pitiot's avatar
up    
pitiot committed
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
	if (draw_posX)
	{
		glDisable(GL_LIGHTING);
		VEC3 pos =VEC3 (posXSlider,posYSlider,0);
		m_ds->newList(GL_COMPILE_AND_EXECUTE);
		m_ds->lineWidth(5.0f);
		m_ds->pointSize(10.0f);
		m_ds->begin(GL_POINTS);
		// fait varier la couleur du plus pres au plus loin

		m_ds->color3f(0.0f , 1.0f, 0.9f);

		m_ds->vertex(pos);
		m_ds->vertex(pos+VEC3(0,0,50));

		m_ds->vertex(pos+VEC3(0,10,50));
742

pitiot's avatar
up    
pitiot committed
743
744
745
		m_ds->end();
		m_ds->endList();
	}
pitiot's avatar
maj    
pitiot committed
746
747
	if (drawMovingObstacles)
	{
Thomas Jund's avatar
Thomas Jund committed
748
#ifdef SHADOWSHELL
749
		updateObstacleVBO();
Thomas Jund's avatar
Thomas Jund committed
750
#endif
Thomas Jund's avatar
Thomas Jund committed
751
752
753

		for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i)
		{
Thomas Jund's avatar
Thomas Jund committed
754
#ifdef SHADOWSHELL
pitiot's avatar
up    
pitiot committed
755
			if(simulator.movingObstacles_[i]->index==12){
pitiot's avatar
pitiot committed
756
757
				Utils::ShaderFlat* moShader = m_obstShader[i];

Thomas Jund's avatar
Thomas Jund committed
758
759
760
761
//			moShader->setAmbiant(Geom::Vec4f(0.43137254902,0.76862745098,0.8862745098,0.));
			moShader->setAmbiant(Geom::Vec4f(0,0,0,0.));
			moShader->setDiffuse(Geom::Vec4f(0.,0.,0.,0.));

762
763
764
			moShader->enableVertexAttribs();
			glDrawArrays(GL_POLYGON, 0, simulator.movingObstacles_[i]->nbVertices);
			moShader->disableVertexAttribs();
pitiot's avatar
pitiot committed
765
			}
Thomas Jund's avatar
Thomas Jund committed
766
#endif
767

768
#ifdef EXPORTING_BOXES
Thomas Jund's avatar
Thomas Jund committed
769
			simulator.movingObstacles_[i]->draw(drawObstPath);
770
#endif
Thomas Jund's avatar
Thomas Jund committed
771
		}
Arash HABIBI's avatar
Arash HABIBI committed
772
773
774
775

		// Commente par Arash (Pourquoi ?)
		for (std::vector<MovingMesh*>::iterator it = simulator.movingMeshes_.begin() ; it != simulator.movingMeshes_.end() ; ++it)
			(*it)->draw();
pitiot's avatar
maj    
pitiot committed
776
777
778

	}

Pierre Kraemer's avatar
Pierre Kraemer committed
779
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
780
781
	if (drawAgentsPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
782
783
784
		updateAgentPredTriVBO();

		for(unsigned int i = 0 ; i < simulator.agents_.size() ; ++i)
David Cazier's avatar
David Cazier committed
785
		{
Thomas Jund's avatar
Thomas Jund committed
786
787
788
789
790
			Utils::ShaderSimpleColor* agShader = m_triAgent_Shader[i];

			agShader->enableVertexAttribs();
			glDrawArrays(GL_LINE_LOOP, 0, 3);
			agShader->disableVertexAttribs();
Pierre Kraemer's avatar
Pierre Kraemer committed
791
792
		}
	}
pitiot's avatar
pitiot committed
793
794
795

	if (drawObstPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
796
		updateObstaclePredTriVBO();
Thomas Jund's avatar
Thomas Jund committed
797

798
		for(unsigned int i = 0 ; i < m_triObst_Shader.size() ; ++i)
Thomas Jund's avatar
Thomas Jund committed
799
800
		{
			Utils::ShaderSimpleColor* moShader = m_triObst_Shader[i];
pitiot's avatar
up    
pitiot committed
801
			MovingObstacle * mo =simulator.movingObstacles_[i];
Thomas Jund's avatar
Thomas Jund committed
802
			moShader->enableVertexAttribs();
pitiot's avatar
up    
pitiot committed
803
			glDrawArrays(GL_LINE_LOOP, 0, 4*mo->nbVertices);
Thomas Jund's avatar
Thomas Jund committed
804
			moShader->disableVertexAttribs();
Thomas Jund's avatar
Thomas Jund committed
805
		}
pitiot's avatar
pitiot committed
806
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
807
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
808
809

	//draw the environment
David Cazier's avatar
David Cazier committed
810
811
	if (drawEnvLines)
	{
Thomas Jund's avatar
Thomas Jund committed
812
813
		m_simpleColorShader->setColor(Geom::Vec4f(0.5,0.5,0.5,0.));
		m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
814
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
815

David Cazier's avatar
David Cazier committed
816
	if (drawEnvTopo)
pitiot's avatar
pitiot committed
817
	{
Thomas Jund's avatar
Thomas Jund committed
818
		m_renderTopo->drawTopo();
pitiot's avatar
pitiot committed
819

Thomas Jund's avatar
Thomas Jund committed
820
821
		if (draw_dart && dartSlider < (simulator.envMap_.map.end().index))
				m_renderTopo->overdrawDart(dartSlider,5.0f,0,1.0f,0.5f);
Pierre Kraemer's avatar
Pierre Kraemer committed
822
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
823

pitiot's avatar
maj    
pitiot committed
824
825
826
	if (drawEnvFaces)
	{
		glEnable(GL_POLYGON_OFFSET_FILL) ;
827
		glPolygonOffset(1.0f, -0.5f) ;
Thomas Jund's avatar
Thomas Jund committed
828
829
830
		switch(m_renderStyle)
		{
		case SIMPLE:
Thomas Jund's avatar
Thomas Jund committed
831
#ifdef ONERING
Thomas Jund's avatar
Thomas Jund committed
832
			m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.));
Thomas Jund's avatar
Thomas Jund committed
833
#else
Thomas Jund's avatar
Thomas Jund committed
834
			m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.));
Thomas Jund's avatar
Thomas Jund committed
835
#endif
Thomas Jund's avatar
Thomas Jund committed
836
			m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
pitiot's avatar
maj    
pitiot committed
837

Thomas Jund's avatar
Thomas Jund committed
838
839
840
841
842
#ifdef ONERING
//			m_simpleColorShader->setColor(Geom::Vec4f(1.0,0.8,0.7,0.));
			m_simpleColorShader->setColor(Geom::Vec4f(0.7,0.7,0.75,0.));
			m_renderWithin->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
#endif
Thomas Jund's avatar
Thomas Jund committed
843
844
845
846
			break;
		}
		glDisable(GL_POLYGON_OFFSET_FILL) ;
	}
pitiot's avatar
maj    
pitiot committed
847

Thomas Jund's avatar
Thomas Jund committed
848

David Cazier's avatar
David Cazier committed
849
	++frames ;
pitiot's avatar
maj    
pitiot committed
850
851
	struct timespec realTime ;
	clock_gettime(CLOCK_MONOTONIC, &realTime) ;
pitiot's avatar
stats    
pitiot committed
852
	elapsedTime += timespec_delta(startTime,realTime).tv_nsec ;
853
	clock_gettime(CLOCK_MONOTONIC, &startTime) ;
pitiot's avatar
l    
pitiot committed
854
	float refresh = 1;
855
	if(display_times)
Thomas Jund's avatar
Thomas Jund committed
856
	{
857
		CGoGNout <<CGoGNendl;
pitiot's avatar
stats    
pitiot committed
858
859
860
861
862
863
864
		CGoGNout << "temps mis pour "<<nbIterations<< " : "<< elapsedTime/10000000.0f<<CGoGNendl;
		CGoGNout << "temps mis pour l'affichage : "<< (long int)elapsedTime/10000000.0f - ((time_update)/1000000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour le DoStep : "<< ((time_update)/10000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour les Agents : "<< (( simulator.time_agent)/10000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour les Agents Polygonaux : "<< ((simulator.time_obstacle)/10000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour le Comportement : "<< ((simulator.time_behave)/10000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour la multirésolution : "<<((simulator.time_multires)/10000000.0f)<<CGoGNendl;
865
866
		CGoGNout <<CGoGNendl;
		display_times= false;
Thomas Jund's avatar
Thomas Jund committed
867

868
		}
pitiot's avatar
l    
pitiot committed
869
	if (elapsedTime/(1000000000.0f*refresh) >= nextUpdate)
David Cazier's avatar
David Cazier committed
870
871
	{
		// Sortie des stats pour analyse externe
872
873
874
//		std::cout << elapsedTime << ";" << frames << ";" << sim.nbUpdates << ";"
//		    << sim.totalNeighbors << ";" << sim.nearNeighbors << ";" << sim.nbSorts << ";"
//		    << sim.nbRefineCandidate << ";" << sim.nbCoarsenCandidate << std::endl ;
pitiot's avatar
maj    
pitiot committed
875

David Cazier's avatar
David Cazier committed
876
877
		// Affichage des stats dans la barre d'état
		std::ostringstream oss ;
pitiot's avatar
l    
pitiot committed
878
879
		oss << "Elapsed time : " << elapsedTime/(1000000000.0f*refresh);
		oss << " | " << ((float)frames)/refresh << " fps" ;
David Cazier's avatar
David Cazier committed
880
		oss << " | Iterations " << nbIterations ;
David Cazier's avatar
David Cazier committed
881
882
883
884
885
886
887
888
889
		oss << " | Neighbors " << simulator.totalNeighbors
			<< " [" << (simulator.nbUpdates == 0 ? 0 : simulator.totalNeighbors / simulator.nbUpdates) << "]" ;
		oss << " | Near Neighbors " << simulator.nearNeighbors
			<< " [" << (simulator.nbUpdates == 0 ? 0 : simulator.nearNeighbors / simulator.nbUpdates) << "]" ;
		oss << " | Sorts " << simulator.nbSorts
			<< " [" << (simulator.nbUpdates == 0 ? 0 : 100 * simulator.nbSorts / simulator.nbUpdates) << "%]" ;
		oss << " | To Refine " << simulator.nbRefineCandidate ;
		oss << " | To Coarsen " << simulator.nbCoarsenCandidate ;
		if(simulator.detect_agent_collision)
890
		{
David Cazier's avatar
David Cazier committed
891
			oss << " | agents morts : "<<simulator.nb_dead;
892
		}
pitiot's avatar
maj    
pitiot committed
893
894
895
		glColor3f(1.0f, 1.0f, 1.0f) ;
		statusMsg(oss.str().c_str()) ;

David Cazier's avatar
David Cazier committed
896
897
898
899
900
901
		simulator.nbUpdates = 0 ;
		simulator.totalNeighbors = 0 ;
		simulator.nearNeighbors = 0 ;
		simulator.nbSorts = 0 ;
		simulator.nbRefineCandidate = 0 ;
		simulator.nbCoarsenCandidate = 0 ;
David Cazier's avatar
David Cazier committed
902
		frames = 0 ;
pitiot's avatar
l    
pitiot committed
903
		nextUpdate = elapsedTime/(1000000000.0f*refresh) + 1 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
904
	}
Thomas Jund's avatar
Thomas Jund committed
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924


#ifdef EXPORTING
	fbo.unbind();


	Utils::FBO fbo2( width(), height() );
	int deferedEdgesAttachment = fbo2.createAttachColorTexture( GL_RGBA );
	fbo2.bind();

	glMatrixMode( GL_PROJECTION );
	glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	glDisable( GL_LIGHTING );
	glColor3ub( 255, 255, 255 );

	glActiveTexture( GL_TEXTURE0 );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, *fbo.getColorTexId(deferedColorAttachment) );
925
926
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
Thomas Jund's avatar
Thomas Jund committed
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999

	glActiveTexture( GL_TEXTURE1 );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, *fbo.getDepthTexId() );
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);

	glActiveTexture( GL_TEXTURE2 );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, *fbo.getColorTexId(deferedNormalAttachment) );


	m_DeferedShader.bind();
	int samplerId = 0;
	m_DeferedShader.setuniformi<1>( "u_FrameBufferColor", &samplerId );
	samplerId = 1;
	m_DeferedShader.setuniformi<1>( "u_FrameBufferDepth", &samplerId );
	samplerId = 2;
	m_DeferedShader.setuniformi<1>( "u_FrameBufferNormal", &samplerId );

	glBegin( GL_QUADS );
		glTexCoord2i( 0, 0 );
		glVertex2i( -1, -1 );
		glTexCoord2i( 1, 0 );
		glVertex2i(  1, -1 );
		glTexCoord2i( 1, 1 );
		glVertex2i(  1,  1 );
		glTexCoord2i( 0, 1 );
		glVertex2i( -1,  1 );
	glEnd();

	m_DeferedShader.unbind();

	fbo2.unbind();




	glActiveTexture( GL_TEXTURE1 );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, *fbo2.getColorTexId(deferedEdgesAttachment) );


	m_DeferedShader2.bind();
	samplerId = 0;
	m_DeferedShader2.setuniformi<1>( "u_FrameBufferColor", &samplerId );
	samplerId = 1;
	m_DeferedShader2.setuniformi<1>( "u_FrameBufferEdgeDepth", &samplerId );
	samplerId = 2;
	m_DeferedShader2.setuniformi<1>( "u_FrameBufferNormal", &samplerId );

	glBegin( GL_QUADS );
		glTexCoord2i( 0, 0 );
		glVertex2i( -1, -1 );
		glTexCoord2i( 1, 0 );
		glVertex2i(  1, -1 );
		glTexCoord2i( 1, 1 );
		glVertex2i(  1,  1 );
		glTexCoord2i( 0, 1 );
		glVertex2i( -1,  1 );
	glEnd();

	m_DeferedShader2.unbind();




#endif

	popTransfoMatrix();
Pierre Kraemer's avatar
Pierre Kraemer committed
1000
1001
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1002
void SocialAgents::animate()
Pierre Kraemer's avatar
Pierre Kraemer committed
1003
{
pitiot's avatar
pitiot committed
1004
1005
//	if(simulator.nbSteps_ % simulator.nbStepsPerUnit_ == 0 && (simulator.nbSteps_ / simulator.nbStepsPerUnit_) % 10 == 0)
//		std::cout << round(simulator.globalTime_) << " " << simulator.envMap_.mapMemoryCost() << std::endl;
Thomas's avatar
Thomas committed
1006

pitiot's avatar
pitiot committed
1007
1008
//	if (simulator.nbSteps_ % simulator.nbStepsPerUnit_ == 0 && (simulator.nbSteps_ / simulator.nbStepsPerUnit_) % 10 == 0) std::cout
//	    << round(simulator.globalTime_) << " " << simulator.envMap_.mapMemoryCost() << std::endl ;
David Cazier's avatar
David Cazier committed
1009
//
pitiot's avatar
pitiot committed
1010
1011
1012
//	CityGenerator::animateCity<PFP>(&simulator.envMap_) ;
//	if (CityGenerator::animateCity<PFP>(&simulator.envMap_)) simulator.addPathToCorner() ;
//	simulator.addPathsToAgents() ;
David Cazier's avatar
David Cazier committed
1013
//
Thomas Jund's avatar
merge    
Thomas Jund committed
1014

pitiot's avatar
pitiot committed
1015
//	std::cout << "t : " << simulator.globalTime_ << std::endl ;
David Cazier's avatar
David Cazier committed
1016
1017
1018
1019
1020
//
//	timeval startTime ;
//	gettimeofday(&startTime, NULL) ;
//	timeval endTime ;
//	long seconds, nseconds ;
Thomas's avatar
Thomas committed
1021

David Cazier's avatar
David Cazier committed
1022
	nbIterations++ ;
Arash HABIBI's avatar
Arash HABIBI committed
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052

	if(cif_exists)
	{
		qglviewer::Vec lookfrom, lookat, upvector;
		qglviewer::Camera* cam = getQGLWidget()->camera();

		if(nbIterations<cif_begin)
		{
			lookfrom.setValue(cif_lookfrom[0][0],cif_lookfrom[0][1],cif_lookfrom[0][2]);
			lookat.  setValue(cif_lookat  [0][0],cif_lookat  [0][1],cif_lookat  [0][2]);
			upvector.setValue(cif_upvector[0][0],cif_upvector[0][1],cif_upvector[0][2]);
		}
		else if((nbIterations>=cif_begin)&&(nbIterations<cif_end))
		{
			lookfrom.setValue(cif_lookfrom[nbIterations-cif_begin][0],cif_lookfrom[nbIterations-cif_begin][1],cif_lookfrom[nbIterations-cif_begin][2]);
			lookat.  setValue(cif_lookat  [nbIterations-cif_begin][0],cif_lookat  [nbIterations-cif_begin][1],cif_lookat  [nbIterations-cif_begin][2]);
			upvector.setValue(cif_upvector[nbIterations-cif_begin][0],cif_upvector[nbIterations-cif_begin][1],cif_upvector[nbIterations-cif_begin][2]);
		}
		else
		{
			lookfrom.setValue(cif_lookfrom[cif_end-cif_begin][0],cif_lookfrom[cif_end-cif_begin][1],cif_lookfrom[cif_end-cif_begin][2]);
			lookat.  setValue(cif_lookat  [cif_end-cif_begin][0],cif_lookat  [cif_end-cif_begin][1],cif_lookat  [cif_end-cif_begin][2]);
			upvector.setValue(cif_upvector[cif_end-cif_begin][0],cif_upvector[cif_end-cif_begin][1],cif_upvector[cif_end-cif_begin][2]);
			exit(0);
		}
		cam->setPosition(lookfrom);
		cam->lookAt(lookat);
		cam->setUpVector(upvector,true);
	}

David Cazier's avatar
David Cazier committed
1053
1054
	if (maxIterations > 0 && nbIterations > maxIterations)
	{
pitiot's avatar
up    
pitiot committed
1055
//		std::cout << "t : " << simulator.globalTime_ << std::endl ;
David Cazier's avatar
David Cazier committed
1056
		timer->stop() ;
pitiot's avatar
stats    
pitiot committed
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
		if (filename != NULL)
		{
			if (percent) filename<<"_percent";

			std::stringstream datas;
			datas<<"stats/"<<filename.str().c_str()<<".dat";

			std::stringstream gnuplots;
			gnuplots<<"stats/"<<filename.str().c_str()<<".plt";

			string data = datas.str();
			string  gnuplot=gnuplots.str();

			float upAgent=((simulator.time_agent)/1000000000.0f);
			float upObst = ((simulator.time_obstacle)/1000000000.0f);
			float behaviour = ((simulator.time_behave)/1000000000.0f);
			float rendu = 0/*(float)elapsedTime - (((float)time_update)/CLOCKS_PER_SEC)*/ ;
			float multi = ((simulator.time_multires)/1000000000.0f);;
			float sum = multi +upAgent+upObst+behaviour+rendu;

			if(percent)
			{
				multi = (multi/sum)*100;
				upAgent=(upAgent/sum)*100;
				upObst = (upObst/sum)*100;
				behaviour = (behaviour/sum)*100;
				rendu =(rendu/sum)*100;
			}
			CGoGNout<<"temps total : "<<(time_update/1000000000.0f)<< CGoGNendl;
			ofstream fichier(data.c_str(), ios::out | ios::trunc);  //déclaration du flux et ouverture du fichier

			if(fichier)  // si l'ouverture a réussi
			{
				// instructions


				fichier<<"#Multires\tMaJ des agents\tMaJ des obstacles\tComportement\tRendu"<<endl;
				fichier<<0<<" "<<multi<<" "<<upAgent<<" "<<upObst<<" "<<behaviour<<" "<<rendu<<endl;
				fichier.close();

			}
			else  // sinon
			{
					cerr << "Erreur à l'ouverture !" << endl;
			}
			ofstream plot(gnuplot.c_str(), ios::out | ios::trunc);  //déclaration du flux et ouverture du fichier
			if(plot)  // si l'ouverture a réussi
			{

				plot<<"set title '"<<maxIterations<<" itérations scénario "<<name.str().c_str()<<" "<<simulator.agents_.size()<<" agents "<<simulator.movingObstacles_.size()<<" agents polygonaux'"<<endl;
				plot<<"set xtics ('' -1)"<<endl;
				if(percent)
				{
					plot<<"set terminal svg"<<endl<<"set output 'stats/svg/"<<filename.str().c_str()<<".svg'"<<endl<<"set key top right"<<endl<<"set boxwidth 0.5"<<endl<<
							"set ylabel 'Percent of ressource'"<<endl<<"set style fill solid border -1"<<endl<<"set xrange [-1:2]"<<endl<<"set yrange [0:105]"<<endl<<
							"plot '"<<data<<"' using 1:($2+$3+$4+$5+$6) with boxes title 'Multires','"<<data<<"' using 1:($3+$4+$5+$6) with boxes title 'MaJ Agent','"<<data<<
							"' using 1:($4+$5+$6) with boxes title 'MaJ Agents polgonaux','"<<data<<"' using 1:($5+$6) with boxes title 'Comportement'"<<endl<<"#,'"
							<<data<<"' using 1:6 with boxes title 'Rendu'";
				}
				else
				{
					plot<<"set terminal svg"<<endl<<"set output 'stats/svg/"<<filename.str().c_str()<<".svg'"<<endl<<"set key top right"<<endl<<"set boxwidth 0.5"<<endl<<
					"set ylabel 'time ressource in sec'"<<endl<<"set style fill solid border -1"<<endl<<"set xrange [-1:2]"<<endl<<"set yrange [0:"<<sum+(2*sum/100)<<"]"<<endl<<
					"plot '"<<data<<"' using 1:($2+$3+$4+$5+$6) with boxes title 'Multires','"<<data<<"' using 1:($3+$4+$5+$6) with boxes title 'MaJ Agent','"<<data<<
					"' using 1:($4+$5+$6) with boxes title 'MaJ Agents polgonaux','"<<data<<"' using 1:($5+$6) with boxes title 'Comportement'"<<endl<<"#,'"
					<<data<<"' using 1:6 with boxes title 'Rendu'";
				}

				plot.close();
			}
			else  // sinon
					cerr << "Erreur à l'ouverture !" << endl;
		}

David Cazier's avatar
David Cazier committed
1131
1132
		exit(0) ;
	}
pitiot's avatar
stats    
pitiot committed
1133
1134
		struct timespec begTime ;
		clock_gettime(CLOCK_MONOTONIC, &begTime) ;
1135

Arash HABIBI's avatar
Arash HABIBI committed
1136
		simulator.doStep() ;
pitiot's avatar
stats    
pitiot committed
1137
1138
1139
1140
		struct timespec endTime ;
		clock_gettime(CLOCK_MONOTONIC, &endTime) ;

		time_update += timespec_delta(begTime,endTime).tv_nsec;
Pierre Kraemer's avatar
Pierre Kraemer committed
1141

Thomas Jund's avatar
Thomas Jund committed
1142
1143
1144
1145
1146
1147
1148
1149
1150
	m_positionVBO->updateData(simulator.envMap_.position);

	if (drawEnvFaces)
		updateVBOprimitives(Algo::Render::GL2::TRIANGLES);

	if (drawEnvLines)
		updateVBOprimitives(Algo::Render::GL2::LINES);

	if(drawEnvTopo)
Sylvain Thery's avatar
Sylvain Thery committed
1151
		m_renderTopo->updateData<PFP>(simulator.envMap_.map, simulator.envMap_.position, 0.9, 0.9);
Thomas Jund's avatar
Thomas Jund committed
1152

David Cazier's avatar
David Cazier committed
1153
1154
1155
//	gettimeofday(&endTime, NULL) ;
//	seconds = endTime.tv_sec - startTime.tv_sec ;
//	nseconds = endTime.tv_usec - startTime.tv_usec ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1156
//
David Cazier's avatar
David Cazier committed
1157
1158
1159
//	elapsedTime += (seconds + nseconds / 1000000.0) ;
//
//	if (sim.globalTime_ - int(sim.globalTime_) == 0.0f && int(sim.globalTime_) % 1500 == 0)
Thomas's avatar
Thomas committed
1160
//	{
David Cazier's avatar
David Cazier committed
1161
1162
//		std::cout << "end " << elapsedTime << std::endl ;
//		timer->stop() ;
Thomas's avatar
Thomas committed
1163
//	}
David Cazier's avatar
David Cazier committed
1164
//
pitiot's avatar
pitiot committed
1165
//	if (simulator.reachedGoal())
1166
//	{
David Cazier's avatar
David Cazier committed
1167
1168
//		std::cout << "end " << elapsedTime << std::endl ;
//		timer->stop() ;
1169
//	}
Thomas's avatar
Thomas committed
1170

Pierre Kraemer's avatar
Pierre Kraemer committed
1171
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
1172
1173
	if (render_anim)
	{
Thomas Jund's avatar
Thomas Jund committed
1174
		if(nbIterations%4==0)
1175
		{
Arash HABIBI's avatar
Arash HABIBI committed
1176
1177
			// getQGLWidget()->resize(800,600);
			getQGLWidget()->resize(1024,768);
1178
1179
1180
1181
1182
1183
1184
1185
			updateGL() ;
//			getQGLWidget()->setSnapshotQuality(100);

			std::ostringstream tmpNb ;
			unsigned int counter = getQGLWidget()->snapshotCounter();
			tmpNb << std::setfill('0') << std::setw(5) << counter ;

			getQGLWidget()->setSnapshotCounter(++counter);
Thomas Jund's avatar
Thomas Jund committed
1186
1187
1188
//			QString filename("./export/meshCercleBA" );
//			QString filename("./export/meshCorridorBA" );
//			QString filename("./export/oneRing" );
Arash HABIBI's avatar
Arash HABIBI committed
1189
			QString filename("./export/scenario3." );
1190
1191
1192
1193
1194
1195
1196
1197
1198
			filename.append((tmpNb.str()).c_str());
			filename.append(".png");
//			getQGLWidget()->setSnapshotFileName(filename);
//			getQGLWidget()->setSnapshotFormat(QString("PNG"));
			QImage image = getQGLWidget()->grabFrameBuffer ();
			if( !image.save( filename, "PNG" ) )
			{
			  QMessageBox::warning( this, "Save Image", "Error saving image." );
			}
Jund Thomas's avatar
Jund Thomas committed
1199

Thomas Jund's avatar
Thomas Jund committed
1200
			if (nbIterations >= 20000)
1201
1202
1203
1204
			{
				std::cout << "enough .png generated" << std::endl ;
				exit(0) ;
			}
Jund Thomas's avatar
Jund Thomas committed
1205

Thomas Jund's avatar
Thomas Jund committed
1206
1207
			if(nbIterations % 1000 == 0)
				std::cout << "image " << nbIterations << std::endl;
1208
		}
Thomas Jund's avatar
Thomas Jund committed
1209

1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
//		std::ostringstream oss ;
//		std::ostringstream tmpNb ;
//		tmpNb << std::setfill('0') << std::setw(5) << nbGeneratedPov ;
////		oss << "./DeCirkelMesh/meshCercle" << tmpNb.str() << ".pov" ;
//		oss << "./DeCorridorMesh/meshCorrida" << tmpNb.str() << ".pov" ;
//		std::string chaine = oss.str() ;
////		VEC3 agPos = sim.agents_[0]->meanPos_ ;
////		agPos[2] = agPos[1] ;
////		agPos[1] = 0.0f ;
////		VEC3 camPos(agPos) ;
////		VEC3 camLook(agPos) ;
//
////		camPos = camPos
////		    + VEC3(-10 - 0.05 * nbGenerated, 30 + 0.05 * nbGenerated,
////		           log(1.0f + nbGenerated / 700.0f)) ;
//
////travelling city nbMaxAgent 15000, nbSquare 40 (45?)
////		VEC3 camPos(-800, 10, -800) ;
////		camPos = camPos
////		    + VEC3(-10 - 0.3 * nbGenerated, 30 + 0.3 * nbGenerated,
////		           400.0f * log(1.0f + nbGenerated / 700.0f)) ;
////		VEC3 camLook(0, 0, 0) ;
////		camLook = camLook
////		    + VEC3(-10 - 0.1 * nbGenerated, 30 + 0.1 * nbGenerated,
////		           400.0f * log(1.0f + nbGenerated / 700.0f)) ;
//
////travelling horizontal
////		VEC3 camPos(0, 5, -200) ;
////		camPos = camPos + VEC3(-10 - 0.15 * nbGenerated, 0, 0) ;
////		VEC3 camLook = camPos ;
////		camLook[0] += 0.15 * nbGenerated ;
////		camLook[2] += 100 ;
////		camLook[1] = 0 ;
//
////vertical view
////		VEC3 camPos(0, 300, 0) ;
////		Geom::BoundingBox<VEC3> bb = simulator.getAgentsBB() ;
////		VEC3 seeEveryone = bb.max() - bb.min() ;
////		if (seeEveryone[0] > 200)
////			camPos[1] += seeEveryone[0] ;
////		else
////			camPos[1] += 200 ;
////		VEC3 camLook(0) ;
//
////video intro
////		VEC3 camPos(-20, 10, 75) ;
////		VEC3 camLook(-25, 0, 0) ;
//
////mall
////		VEC3 camPos(-500, 500, -400) ;
////		VEC3 camLook(100, 100, 0) ;
//
////openStreetMap
////		VEC3 camPos(500, 75, 400) ;
////		VEC3 camLook(-250, 0, 650) ;
//
////pathDyn
////		VEC3 camPos(-700, 700, -1800) ;
////		VEC3 camLook(200, 0, 0) ;
//
////corridor side
////		VEC3 camPos(-700, 100, 0) ;
////		VEC3 camLook(200, 0, 0) ;
//
////corridor top
////		VEC3 camPos(0, 300, 0) ;
////		VEC3 camLook(0, 0, 0) ;
//
////corridor take2
////		VEC3 camPos(-350, 200, 0) ;
////		VEC3 camLook(0, 0, 0) ;
//
////openStreetMap mapRoad & mapBuildings
////		VEC3 camPos(-200, 100, 500) ;
////		VEC3 camLook(1000, 0, 0) ;
//
////openStreetMap sphere
////		VEC3 camPos(-200, 100, 500) ;
////		VEC3 camLook(100, 0, 0) ;
//
////		//diligences / Cercle
////		VEC3 camPos(0, 300, 750) ;
////		VEC3 camLook(0, 0, 0) ;
//
//		//corridor
Thomas Jund's avatar
Thomas Jund committed
1295
1296
//		VEC3 camPos(0, 300, 750) ;
//		VEC3 camLook(0, 0, 0) ;
pitiot's avatar
up    
pitiot committed
1297
//
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
//
////		if(nbIterations%2==0)
////		{
////			exportScenePov(simulator.envMap_.map,simulator.envMap_.position,chaine,camPos,camLook,VEC3(0.0f,0,0),0,0,0);
////			// 		exportScenePov(sim.envMap_.map,sim.envMap_.position,chaine,VEC3(43,762,65),VEC3(0,762,0),VEC3(1.0f,0,0),0,0,0);
////		//		exportScenePov(sim.envMap_.map,sim.envMap_.position,chaine,VEC3(43,762,65+(1500.0f*float(nbGenerated)/400.0f)),VEC3(0,762,0),VEC3(1.0f,0,0),0,0,0);
////			nbGeneratedPov++;
////		}
////
////		if (nbIterations >= 20000)
////		{
////			std::cout << "enough .pov generated" << std::endl ;
////			exit(0) ;
////		}
Pierre Kraemer's avatar
Pierre Kraemer committed
1312
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
1313
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
1314

1315
	updateGL() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1316
}
1317

Pierre Kraemer's avatar
Pierre Kraemer committed
1318
#ifndef SPATIAL_HASHING
Thomas's avatar
Thomas committed
1319
1320
1321
void SocialAgents::exportInfoFace(std::ofstream& out, Dart d)
{
	//get corner
1322
	Dart dd = d ;
David Cazier's avatar
David Cazier committed
1323
	VEC3 cornerLeftBottom = simulator.envMap_.position[d] ;
David Cazier's avatar
David Cazier committed
1324
1325
	do
	{
David Cazier's avatar
David Cazier committed
1326
		VEC3 p = simulator.envMap_.position[dd] ;
1327
1328
1329
		if (cornerLeftBottom[0] > p[0]) cornerLeftBottom[0] = p[0] ;
		if (cornerLeftBottom[1] > p[1]) cornerLeftBottom[1] = p[1] ;
		if (cornerLeftBottom[2] > p[2]) cornerLeftBottom[2] = p[2] ;
David Cazier's avatar
David Cazier committed
1330
		dd = simulator.envMap_.map.phi1(dd) ;
1331
	} while (dd != d) ;