Ejemplo n.º 1
0
void
TaxonomyVertex :: LoadNeighbours ( SaveLoadManager& m )
{
	unsigned int j, size;
	size = m.loadUInt();
	for ( j = 0; j < size; ++j )
		addNeighbour ( true, m.loadVertex() );
	size = m.loadUInt();
	for ( j = 0; j < size; ++j )
		addNeighbour ( false, m.loadVertex() );
}
Ejemplo n.º 2
0
static int getNeighbours(const float* pos, const float height, const float range,
						 const dtCrowdAgent* skip, dtCrowdNeighbour* result, const int maxResult,
						 dtCrowdAgent** agents, const int /*nagents*/, dtProximityGrid* grid)
{
	int n = 0;
	
	static const int MAX_NEIS = 32;
	unsigned short ids[MAX_NEIS];
	int nids = grid->queryItems(pos[0]-range, pos[2]-range,
								pos[0]+range, pos[2]+range,
								ids, MAX_NEIS);
	
	for (int i = 0; i < nids; ++i)
	{
		const dtCrowdAgent* ag = agents[ids[i]];
		
		if (ag == skip) continue;
		
		// Check for overlap.
		float diff[3];
		dtVsub(diff, pos, ag->npos);
		if (dtMathFabs(diff[1]) >= (height+ag->params.height)/2.0f)
			continue;
		diff[1] = 0;
		const float distSqr = dtVlenSqr(diff);
		if (distSqr > dtSqr(range))
			continue;
		
		n = addNeighbour(ids[i], distSqr, result, n, maxResult);
	}
	return n;
}
Ejemplo n.º 3
0
unsigned dtCrowd::computeNeighbors(unsigned id)
{
	unsigned n = 0;
	const dtCrowdAgent* agent = m_crowdQuery->getAgent(id);

	for (unsigned i = 0; i < m_maxAgents; ++i)
	{
		dtCrowdAgent* target = 0;

		// Check if the agent is active and is not the tested one
		if (!getActiveAgent(&target, i) || target->id == agent->id)
			continue;
				
		float diff[3];
		dtVsub(diff, agent->position, target->position);

		// Check if the agent are on the same level
		if (fabsf(diff[1]) > (agent->height + target->height) / 2.f)
			continue;

		diff[1] = 0;
		const float dist2D = dtVlenSqr(diff);

		if (dist2D > dtSqr(agent->perceptionDistance))
			continue;

		n = addNeighbour(target->id, dist2D, m_agentsEnv[agent->id].neighbors, n, DT_CROWDAGENT_MAX_NEIGHBOURS);
	}

	return n;
}
Ejemplo n.º 4
0
//===========================================================================
void ftSurfaceSetPoint::addInfo(ftSurfaceSetPoint* other)
//
// Add face, parameter and connectivity info from the point other to this point
// NB! It is assumed that the position information is consistent
//===========================================================================
{
    size_t ki, kj;

    // Face and parameter information
    for (ki=0; ki<other->par_pts_.size(); ++ki)
    {
	// Check if the face exists already
	for (kj=0; kj<par_pts_.size(); ++kj)
	    if (par_pts_[kj].first.get() == other->par_pts_[ki].first.get())
		break;

	if (kj == par_pts_.size())
	    addPair(other->par_pts_[ki].first, other->par_pts_[ki].second);
    }

    // Connectivity information
    vector<PointIter> neighbours = other->getNeighbours();
    for (ki=0; ki<neighbours.size(); ++ki)
    {
	neighbours[ki]->addNeighbour(this);
	addNeighbour(neighbours[ki]);
    }
}
Ejemplo n.º 5
0
//1.remove an item at random "f_index" from frontier vector 
//2.addNeighbour(new_x, new_y);
//3.randomly choose a neighbour cell(the cell that is "in" the maze)
//4.connect the neighbour cell to the frontier cell 
//5.remove the frontier cell from the frontier vector
//6.repeat the process until no more frontier cell is in the vector
void Maze::generateMaze()
{
    
  srand(static_cast<int>(time(nullptr)));

  //randomly create the starting coordinate
  int x = rand() % (height);
  int y = rand() % (width);

  expandMaze(x,y);
  
  unsigned long f_size = frontier.size();
  while(f_size > 0)
  {
    //randomly choose a cell from the frontier set
    int f_index = rand() % (f_size);
    Cell f_cell = frontier[f_index];
    int f_new_x = f_cell.x;
    int f_new_y = f_cell.y;
  
    std::vector<Cell> neighbour = addNeighbour(f_new_x, f_new_y);
    unsigned long n_size = neighbour.size();

    int  n_index = rand() % (n_size);
    Cell n_cell  = neighbour[n_index];
    int  n_new_x = n_cell.x;
    int  n_new_y = n_cell.y;
  
    //dir is the direction going from n_cell to f_cell;
    Direction dir = getDirection(f_new_x, f_new_y, n_new_x ,n_new_y);
    connectCells(f_new_x, f_new_y, n_new_x, n_new_y, dir); 

    //Remove the chosen frontier cell from the vector
    frontier.erase(frontier.begin() + f_index); 
    
    expandMaze(f_new_x,f_new_y);
    
    f_size = frontier.size();//update f_size and check if the frontier vector is empty
  }
  

}
Ejemplo n.º 6
0
static int getNeighbours(const float* pos, const float height, const float range,
						 const dtCrowdAgent* skip, dtCrowdNeighbour* result, const int maxResult,
						 dtCrowdAgent** agents, const int /*nagents*/, dtProximityGrid* grid)
{
	int n = 0;
	
	static const int MAX_NEIS = 32;
	unsigned short ids[MAX_NEIS];
	int nids = grid->queryItems(pos[0]-range, pos[2]-range,
								pos[0]+range, pos[2]+range,
								ids, MAX_NEIS);
	
	for (int i = 0; i < nids; ++i)
	{
		const dtCrowdAgent* ag = agents[ids[i]];
		
		if (ag == skip) continue;
		
		// Check for overlap.
		float diff[3];
		dtVsub(diff, pos, ag->npos);
		if (fabsf(diff[1]) >= (height+ag->params.height)/2.0f)
			continue;
		diff[1] = 0;
		const float distSqr = dtVlenSqr(diff);
		if (distSqr > dtSqr(range))
			continue;

		// [UE4] add only when avoidance group allows it
		const bool bDontAvoid = (skip->params.groupsToIgnore & ag->params.avoidanceGroup) || !(skip->params.groupsToAvoid & ag->params.avoidanceGroup);
		if (bDontAvoid)
			continue;
		
		n = addNeighbour(ids[i], distSqr, result, n, maxResult);
	}
	return n;
}