Пример #1
0
void CurveAgent::draw()
{
#ifdef ENABLE_GUI
	// if the agent is selected, do some annotations just for demonstration
	if (gEngine->isAgentSelected(this)) {
		Util::Ray ray;
		ray.initWithUnitInterval(__position, _forward);
		float t = 0.0f;
		SteerLib::SpatialDatabaseItem * objectFound;
		Util::DrawLib::drawLine(ray.pos, ray.eval(1.0f));
		if (gSpatialDatabase->trace(ray, t, objectFound, this, false)) {
			Util::DrawLib::drawAgentDisc(__position, _forward, _radius, Util::gOrange);
		}
		else {
			Util::DrawLib::drawAgentDisc(__position, _forward, _radius, Util::gDarkOrange);
		}
	}
	else {
		Util::DrawLib::drawAgentDisc(__position, _forward, _radius, agentColor);
	}

	// Draw flags for all goal targets
	for (int i = 0; i < _goalQueue.size(); i++)
	{
		if (_goalQueue[i].goalType == SteerLib::GOAL_TYPE_SEEK_STATIC_TARGET)
		{
			Util::DrawLib::drawFlag(_goalQueue[i].targetLocation, agentColor, 2);
		}
	}

	// Draw curve path
	curve.drawCurve(agentColor);

#endif
}
void SearchAgent::draw()
{
#ifdef ENABLE_GUI
	// if the agent is selected, do some annotations just for demonstration
	if (gEngine->isAgentSelected(this)) {
		Util::Ray ray;
		ray.initWithUnitInterval(__position, _forward);
		float t = 0.0f;
		SteerLib::SpatialDatabaseItem * objectFound;
		Util::DrawLib::drawLine(ray.pos, ray.eval(1.0f));
		if (gSpatialDatabase->trace(ray, t, objectFound, this, false)) {
			Util::DrawLib::drawAgentDisc(__position, _forward, _radius, Util::gBlue);
		}
		else {
			Util::DrawLib::drawAgentDisc(__position, _forward, _radius);
		}
	}
	else {
		Util::DrawLib::drawAgentDisc(__position, _forward, _radius, Util::gGray40);
	}
	if (_goalQueue.front().goalType == SteerLib::GOAL_TYPE_SEEK_STATIC_TARGET) {
		Util::DrawLib::drawFlag(_goalQueue.front().targetLocation);
	}
	
	if(__path.size()>0)
	{
		for(int i = 1; i<__path.size(); ++i)
			Util::DrawLib::drawLine(__path[i-1], __path[i], Util::Color(1.0f, 0.0f, 0.0f), 2);
		Util::DrawLib::drawCircle(__path[__path.size()-1], Util::Color(0.0f, 1.0f, 0.0f));
	}
#endif
}
void SocialForcesAgent::draw()
{
#ifdef ENABLE_GUI
	// if the agent is selected, do some annotations just for demonstration
	if (gEngine->isAgentSelected(this))
	{
		Util::Ray ray;
		ray.initWithUnitInterval(_position, _forward);
		float t = 0.0f;
		SteerLib::SpatialDatabaseItem * objectFound;
		Util::DrawLib::drawLine(ray.pos, ray.eval(1.0f));
		if (gSpatialDatabase->trace(ray, t, objectFound, this, false))
		{
			Util::DrawLib::drawAgentDisc(_position, _forward, _radius, Util::gBlue);
		}
		else {
			Util::DrawLib::drawAgentDisc(_position, _forward, _radius);
		}
		Util::DrawLib::drawFlag( this->currentGoal().targetLocation, Color(0.5f,0.8f,0), 2);
		if ( this->currentGoal().goalType == GOAL_TYPE_AXIS_ALIGNED_BOX_GOAL )
		{
			Color color(0.4,0.9,0.4);
			DrawLib::glColor(color);
			DrawLib::drawQuad(Point(this->currentGoal().targetRegion.xmin, 0.1, this->currentGoal().targetRegion.zmin),
					Point(this->currentGoal().targetRegion.xmin, 0.1, this->currentGoal().targetRegion.zmax),
					Point(this->currentGoal().targetRegion.xmax, 0.1, this->currentGoal().targetRegion.zmax),
					Point(this->currentGoal().targetRegion.xmax, 0.1, this->currentGoal().targetRegion.zmin));
		}
		int i;
		for (i=0; ( _waypoints.size() > 1 ) && (i < (_waypoints.size() - 1)); i++)
		{
			DrawLib::drawLine(_waypoints.at(i), _waypoints.at(i+1), gYellow);
			DrawLib::drawStar(_waypoints.at(i), Util::Vector(1,0,0), 0.34f, gBlue);
		}
		// DrawLib::drawStar(_waypoints.at(i), Util::Vector(1,0,0), 0.34f, gBlue);
	}
	else {
		Util::DrawLib::drawAgentDisc(_position, _radius, this->_color);
	}
	if (_goalQueue.front().goalType == SteerLib::GOAL_TYPE_SEEK_STATIC_TARGET) {
		Util::DrawLib::drawFlag(_goalQueue.front().targetLocation);
	}

#ifdef DRAW_COLLISIONS
	std::set<SteerLib::SpatialDatabaseItemPtr> _neighbors;
	gSpatialDatabase->getItemsInRange(_neighbors, _position.x-(this->_radius * 3), _position.x+(this->_radius * 3),
			_position.z-(this->_radius * 3), _position.z+(this->_radius * 3), dynamic_cast<SteerLib::SpatialDatabaseItemPtr>(this));

	for (std::set<SteerLib::SpatialDatabaseItemPtr>::iterator neighbor = _neighbors.begin();  neighbor != _neighbors.end();  neighbor++)
	{
		if ( (*neighbor)->isAgent() && (*neighbor)->computePenetration(this->position(), this->_radius) > 0.00001f)
		{
			Util::DrawLib::drawStar(
					this->position()
					+
					(
						(
							dynamic_cast<AgentInterface*>(*neighbor)->position()
							-
							this->position()
						)
					/2), Util::Vector(1,0,0), 0.8f, gRed);
			// Util::DrawLib::drawStar(this->position(), Util::Vector(1,0,0), 1.14f, gRed);
		}
	}
#endif
#ifdef DRAW_HISTORIES
	__oldPositions.push_back(position());
	int points = 0;
	float mostPoints = 100.0f;
	while ( __oldPositions.size() > mostPoints )
	{
		__oldPositions.pop_front();
	}
	for (int q = __oldPositions.size()-1 ; q > 0 && __oldPositions.size() > 1; q--)
	{
		DrawLib::drawLineAlpha(__oldPositions.at(q), __oldPositions.at(q-1),gBlack, q/(float)__oldPositions.size());
	}

#endif

#ifdef DRAW_ANNOTATIONS

	for (int i=0; ( _waypoints.size() > 1 ) && (i < (_waypoints.size() - 1)); i++)
	{
		if ( gEngine->isAgentSelected(this) )
		{
			DrawLib::drawLine(_waypoints.at(i), _waypoints.at(i+1), gYellow);
		}
		else
		{
			//DrawLib::drawLine(_waypoints.at(i), _waypoints.at(i+1), gBlack);
		}
	}

	for (int i=0; i < (_waypoints.size()); i++)
	{
		DrawLib::drawStar(_waypoints.at(i), Util::Vector(1,0,0), 0.34f, gBlue);
	}

	for (int i=0; ( _midTermPath.size() > 1 ) && (i < (_midTermPath.size() - 1)); i++)
	{
		if ( gEngine->isAgentSelected(this) )
		{
			DrawLib::drawLine(_midTermPath.at(i), _midTermPath.at(i+1), gMagenta);
		}
		else
		{
			// DrawLib::drawLine(_midTermPath.at(i), _midTermPath.at(i+1), gCyan);
		}
	}

	DrawLib::drawLine(position(), this->_currentLocalTarget, gGray10);
	DrawLib::drawStar(this->_currentLocalTarget+Util::Vector(0,0.001,0), Util::Vector(1,0,0), 0.24f, gGray10);

	/*
	// draw normals and closest points on walls
	std::set<SteerLib::ObstacleInterface * > tmp_obs = gEngine->getObstacles();

	for (std::set<SteerLib::ObstacleInterface * >::iterator tmp_o = tmp_obs.begin();  tmp_o != tmp_obs.end();  tmp_o++)
	{
		Util::Vector normal = calcWallNormal( *tmp_o );
		std::pair<Util::Point,Util::Point> line = calcWallPointsFromNormal(* tmp_o, normal);
		Util::Point midpoint = Util::Point((line.first.x+line.second.x)/2, ((line.first.y+line.second.y)/2)+1,
				(line.first.z+line.second.z)/2);
		DrawLib::drawLine(midpoint, midpoint+normal, gGreen);

		// Draw the closes point as well
		std::pair<float, Util::Point> min_stuff = minimum_distance(line.first, line.second, position());
		DrawLib::drawStar(min_stuff.second, Util::Vector(1,0,0), 0.34f, gGreen);
	}
	*/

#endif

#endif
}
Пример #4
0
void AgentInterface::draw()
{
#ifdef ENABLE_GUI

	#ifdef DRAW_HISTORIES
		__oldPositions.push_back(position());
		float mostPoints = 100.0f;
		while ( __oldPositions.size() > mostPoints )
		{
			__oldPositions.pop_front();
		}
		for (int q = __oldPositions.size()-1 ; q > 0 && __oldPositions.size() > 1; q--)
		{
			DrawLib::drawLineAlpha(__oldPositions.at(q), __oldPositions.at(q-1),gBlack, q/(float)__oldPositions.size());
		}

	#endif
	Util::Vector adjust = Util::Vector(0.0,0.6,0.0);
	if (getSimulationEngine()->isAgentSelected(this))
	{
		Util::Ray ray;
		ray.initWithUnitInterval(_position, _forward);
		float t = 0.0f;
		SteerLib::SpatialDatabaseItem * objectFound;
		Util::DrawLib::drawLine(ray.pos + adjust, ray.eval(1.0f));
		// if (getSimulationEngine()->getSpatialDatabase()->trace(ray, t, objectFound, this, false))
		{
			Util::DrawLib::drawAgentDisc(_position, _forward, _radius, Util::gBlue);
		}
		// else
		{
			// Util::DrawLib::drawAgentDisc(_position, _forward, _radius);
		}
		Util::DrawLib::drawFlag( this->currentGoal().targetLocation, Color(0.5f,0.8f,0), 2);
		if ( this->currentGoal().goalType == GOAL_TYPE_AXIS_ALIGNED_BOX_GOAL )
		{
			Color color(0.4,0.9,0.4);
			DrawLib::glColor(color);
			DrawLib::drawQuad(Point(this->currentGoal().targetRegion.xmin, 0.1, this->currentGoal().targetRegion.zmin),
					Point(this->currentGoal().targetRegion.xmin, 0.1, this->currentGoal().targetRegion.zmax),
					Point(this->currentGoal().targetRegion.xmax, 0.1, this->currentGoal().targetRegion.zmax),
					Point(this->currentGoal().targetRegion.xmax, 0.1, this->currentGoal().targetRegion.zmin));
		}

		if ( _midTermPath.size() > 0 )
		{
			// DrawLib::drawStar(_midTermPath.at(0), Util::Vector(1,0,0), 0.34f, gBlue);
			DrawLib::drawLine(this->position(), _midTermPath.at(0), gOrange, 1.5f);
		}
		for (size_t p=1; ( _midTermPath.size() > 1 ) && p < _midTermPath.size(); p++)
		{
			DrawLib::drawLine(_midTermPath.at(p), _midTermPath.at(p-1), gOrange, 1.5f);
			//  DrawLib::drawStar(_midTermPath.at(p), Util::Vector(1,0,0), 0.34f, gOrange);
			// std::cout << "point " << p << ", " << _midTermPath.at(p) << std::endl;
		}
		int i;
		for (i=0; ( _waypoints.size() > 1 ) && (i < (_waypoints.size() - 1)); i++)
		{
			// DrawLib::drawLine(_waypoints.at(i)+adjust, _waypoints.at(i+1)+adjust, gYellow);
			// DrawLib::drawStar(_waypoints.at(i)+adjust, Util::Vector(1,0,0), 0.34f, gBlue);
		}
		// DrawLib::drawStar(_waypoints.at(i), Util::Vector(1,0,0), 0.34f, gBlue);
		// draw line to current localTarget
		// DrawLib::drawLine(position()+adjust, this->_currentLocalTarget+adjust, gYellow);

		// DrawLib::drawLine(position()+adjust, position()+_prefVelocity+adjust, Util::gCyan, 20.0f);
		if (false)
		{
			Util::Vector _rightSide = rightSideInXZPlane(this->forward()*this->radius());
			SpatialDatabaseItemPtr dummyObject;
			Ray lineOfSightTestRight, lineOfSightTestLeft, lineOfSightTestCentre, lineOfSightTestBack;
			Util::Point tmp_pos;
			// lineOfSightTestRight.initWithUnitInterval(_position + _radius*_rightSide, target - (_position + _radius*_rightSide));
			// lineOfSightTestLeft.initWithUnitInterval(_position + _radius*(_rightSide), target - (_position - _radius*_rightSide));
			tmp_pos = _position + _rightSide + (Util::Vector(0.0,0.0,0.0));
			lineOfSightTestRight.initWithUnitInterval(tmp_pos, this->_currentLocalTarget - tmp_pos);
			DrawLib::drawRay(lineOfSightTestRight, gGray60);
			tmp_pos = _position + (-_rightSide) + (Util::Vector(0.0,0.0,0.0));
			lineOfSightTestLeft.initWithUnitInterval(tmp_pos, this->_currentLocalTarget - tmp_pos);
			DrawLib::drawRay(lineOfSightTestLeft, gGray60);
			tmp_pos = _position - this->forward()*this->radius() ;
			lineOfSightTestBack.initWithUnitInterval(tmp_pos, this->_currentLocalTarget - tmp_pos);
			DrawLib::drawRay(lineOfSightTestBack, gGray60);
			lineOfSightTestCentre.initWithUnitInterval(_position, this->_currentLocalTarget - _position);
		}

	}
	else {
		Util::DrawLib::drawAgentDisc(_position, _radius, this->_color);
	}
	if (_goalQueue.front().goalType == SteerLib::GOAL_TYPE_SEEK_STATIC_TARGET) {
		Util::DrawLib::drawFlag(_goalQueue.front().targetLocation);
	}

#endif
}
Пример #5
0
void CurveAgent::draw()
{
#ifdef ENABLE_GUI
	// if the agent is selected, do some annotations just for demonstration
	if (gEngine->isAgentSelected(this)) {
		Util::Ray ray;
		ray.initWithUnitInterval(__position, _forward);
		float t = 0.0f;
		SteerLib::SpatialDatabaseItem * objectFound;
		Util::DrawLib::drawLine(ray.pos, ray.eval(1.0f));
		if (gSpatialDatabase->trace(ray, t, objectFound, this, false)) {
			//Draw pyramid
			glPushMatrix();
			{
				Util::DrawLib::glTranslate(__position);
				Util::DrawLib::glColor(agentColor);
				glScalef(_radius, _radius, _radius);
				glDisable(GL_CULL_FACE);

				glBegin(GL_TRIANGLES);
				//Back tri
				glVertex3f(0.0f, 2.0f, 0.0f);
				glVertex3f(-1.0f, 0.0f, 1.0f);
				glVertex3f(1.0f, 0.0f, 1.0f);
				//Left tri
				glVertex3f(0.0f, 2.0f, 0.0f);
				glVertex3f(-1.0f, 0.0f, 1.0f);
				glVertex3f(-1.0f, 0.0f, -1.0f);
				//Right tri
				glVertex3f(0.0f, 2.0f, 0.0f);
				glVertex3f(1.0f, 0.0f, 1.0f);
				glVertex3f(1.0f, 0.0f, -1.0f);
				//Front tri
				glVertex3f(0.0f, 2.0f, 0.0f);
				glVertex3f(-1.0f, 0.0f, -1.0f);
				glVertex3f(1.0f, 0.0f, -1.0f);
				glEnd();

				glEnable(GL_CULL_FACE);
			}
			glPopMatrix();
		}
		else {
			//Draw pyramid
			glPushMatrix();
			{
				Util::DrawLib::glTranslate(__position);
				Util::DrawLib::glColor(agentColor);
				glScalef(_radius, _radius, _radius);
				glDisable(GL_CULL_FACE);

				glBegin(GL_TRIANGLES);
				//Back tri
				glVertex3f(0.0f, 2.0f, 0.0f);
				glVertex3f(-1.0f, 0.0f, 1.0f);
				glVertex3f(1.0f, 0.0f, 1.0f);
				//Left tri
				glVertex3f(0.0f, 2.0f, 0.0f);
				glVertex3f(-1.0f, 0.0f, 1.0f);
				glVertex3f(-1.0f, 0.0f, -1.0f);
				//Right tri
				glVertex3f(0.0f, 2.0f, 0.0f);
				glVertex3f(1.0f, 0.0f, 1.0f);
				glVertex3f(1.0f, 0.0f, -1.0f);
				//Front tri
				glVertex3f(0.0f, 2.0f, 0.0f);
				glVertex3f(-1.0f, 0.0f, -1.0f);
				glVertex3f(1.0f, 0.0f, -1.0f);
				glEnd();

				glEnable(GL_CULL_FACE);
			}
			glPopMatrix();
		}
	}
	else {
		//Draw pyramid
		glPushMatrix();
		{
			Util::DrawLib::glTranslate(__position);
			Util::DrawLib::glColor(agentColor);
			glScalef(_radius, _radius, _radius);
			glDisable(GL_CULL_FACE);

			glBegin(GL_TRIANGLES);
			//Back tri
			glVertex3f(0.0f, 2.0f, 0.0f);
			glVertex3f(-1.0f, 0.0f, 1.0f);
			glVertex3f(1.0f, 0.0f, 1.0f);
			//Left tri
			glVertex3f(0.0f, 2.0f, 0.0f);
			glVertex3f(-1.0f, 0.0f, 1.0f);
			glVertex3f(-1.0f, 0.0f, -1.0f);
			//Right tri
			glVertex3f(0.0f, 2.0f, 0.0f);
			glVertex3f(1.0f, 0.0f, 1.0f);
			glVertex3f(1.0f, 0.0f, -1.0f);
			//Front tri
			glVertex3f(0.0f, 2.0f, 0.0f);
			glVertex3f(-1.0f, 0.0f, -1.0f);
			glVertex3f(1.0f, 0.0f, -1.0f);
			glEnd();

			glEnable(GL_CULL_FACE);
		}
		glPopMatrix();
	}

	// Draw flags for all goal targets
	for (int i = 0; i < _goalQueue.size(); i++)
	{
		if (_goalQueue[i].goalType == SteerLib::GOAL_TYPE_SEEK_STATIC_TARGET)
		{
			Util::DrawLib::drawFlag(_goalQueue[i].targetLocation, agentColor, 2);
		}
	}

	// Draw curve path
	curve.drawCurve(agentColor);

#endif
}