env_render.h 3.02 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5
#ifndef ENVMAP_RENDER
#define ENVMAP_RENDER

#include "env_map.h"
#include "agent.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
6
#include "Utils/colorMaps.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
7

Pierre Kraemer's avatar
Pierre Kraemer committed
8
inline void renderDart(EnvMap& m, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
9 10 11 12 13 14 15 16 17 18
{
	PFP::VEC3 p1 = m.position[d];
	PFP::VEC3 p2 = m.position[m.map.phi1(d)];

	glBegin(GL_LINES);
		glVertex3f(p1[0],p1[1],p1[2]);
		glVertex3f(p2[0],p2[1],p2[2]);
	glEnd();
}

19
inline void renderFace(EnvMap& m, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
20 21 22 23 24 25 26 27
{
	Dart dd=d;
	do {
		renderDart(m,dd);
		dd = m.map.phi1(dd);
	}while(dd!=d);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
28
inline void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
Pierre Kraemer's avatar
Pierre Kraemer committed
29
{
30 31 32 33
	Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,d,m.position);
	p[2] -= 1000;
	Geom::intersectionPlaneRay(pl,p,VEC3(0,0,-1),p);

Pierre Kraemer's avatar
Pierre Kraemer committed
34 35 36 37 38 39 40 41 42 43 44 45 46
	VEC3 pos1(m.position[d]);
	VEC3 pos2(m.position[m.map.phi1(d)]);
	pos2[2] += 2;
	glBegin(GL_LINE_LOOP);
		glVertex3fv(&p[0]);
		glVertex3fv(& pos1[0]);
		glVertex3fv(& pos2[0]);
	glEnd();
}

static const float cosT[5] = { 1, 0.309017, -0.809017, -0.809017, 0.309017 };
static const float sinT[5] = { 0, 0.951057, 0.587785, -0.587785, -0.951057 };

47
inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false, bool showObstacleDist = false)
Pierre Kraemer's avatar
Pierre Kraemer committed
48
{
Pierre Kraemer's avatar
Pierre Kraemer committed
49 50 51
#ifdef SPATIAL_HASHING
	const VEC3& pos = agent->pos;
#else
52
	VEC3 pos = agent->part_.m_position;
Pierre Kraemer's avatar
Pierre Kraemer committed
53
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
54 55
	float radius = agent->radius_;
	
Pierre Kraemer's avatar
Pierre Kraemer committed
56 57 58
//	Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,agent->part_.d,m.position);
//	pos[2] -= 1000;
//	Geom::intersectionPlaneRay(pl,pos,VEC3(0,0,-1),pos);
59

Pierre Kraemer's avatar
Pierre Kraemer committed
60 61
	glLineWidth(1.0f);
	
Pierre Kraemer's avatar
Pierre Kraemer committed
62 63 64
//	VEC3 col = Utils::color_map_BCGYR(float(agent->agentNo)/float(agent->sim_->agents_.size()));
//	glColor3fv(col.data());
	glColor3f(1.0f, 0.0f, 0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
65
	glBegin(GL_POLYGON);
Pierre Kraemer's avatar
Pierre Kraemer committed
66
	for(unsigned int i = 0; i < 5; ++i)
67
		glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2]+0.01f);
Pierre Kraemer's avatar
Pierre Kraemer committed
68 69
	glEnd();
	
70 71 72
	VEC3 dir = agent->velocity_;
	dir.normalize();

Thomas's avatar
Thomas committed
73
 	//draw the speed vector
74 75 76
//	VEC3 base(0,0,1);
//	VEC3 myAxisRot = base^dir;
//	myAxisRot.normalize();
77
//	float myRot = 57.29f * acos(base*dir);
78 79 80
//
//	glPushMatrix();
//		glTranslatef(pos[0],pos[1],pos[2]);
81
//		glRotatef(myRot,myAxisRot[0],myAxisRot[1],myAxisRot[2]);
82
//
83
//		glColor3f(0.0f, 1.0f, 0.0f);
84 85 86 87 88 89
//		glLineWidth(5.0f);
//		glBegin(GL_LINES);
//		glVertex3f(0.,0.,0.0);
//		glVertex3f(0.,0.,agent->radius_*2.0f);
//		glEnd();
//	glPopMatrix();
90

91 92 93 94 95 96 97 98 99 100 101 102 103
	//show goals
	if(true)
	{
		glLineWidth(3.0f);
		glBegin(GL_LINE_STRIP);
		for(std::vector<VEC3>::iterator it = ++(agent->goals_.begin()) ; it != agent->goals_.end() ; ++it)
		{
			glVertex3f((*it)[0],(*it)[1],(*it)[2]);
		}
		glEnd();
		glLineWidth(1.0f);
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
104 105
	if(showNeighborDist)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
106
		radius = agent->neighborDist_;
Pierre Kraemer's avatar
Pierre Kraemer committed
107 108 109
		glColor3f(0.0f,1.0f,0.0f);
		glBegin(GL_LINE_LOOP);
		for(unsigned int i = 0; i < 5; ++i)
110
			glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2]+0.01f);
Pierre Kraemer's avatar
Pierre Kraemer committed
111 112 113 114 115 116 117 118 119
		glEnd();
	}
	
	if(showObstacleDist)
	{
		radius = (agent->timeHorizonObst_ * agent->maxSpeed_) + agent->radius_;
		glColor3f(0.0f,0.0f,1.0f);
		glBegin(GL_LINE_LOOP);
		for(unsigned int i = 0; i < 5; ++i)
120
			glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2]+0.01f);
Pierre Kraemer's avatar
Pierre Kraemer committed
121 122 123 124 125
		glEnd();
	}
}

#endif