Beispiel #1
0
/// Get the position of a grid point
static void getGridPos(Vector3i *result, int x, int y, bool center, bool water)
{
	if (center)
	{
		Vector3i a,b,c,d;
		getGridPos(&a, x  , y  , false, water);
		getGridPos(&b, x+1, y  , false, water);
		getGridPos(&c, x  , y+1, false, water);
		getGridPos(&d, x+1, y+1, false, water);
		averagePos(result, &a, &b, &c, &d);
		return;
	}
	result->x = world_coord(x);
	result->z = world_coord(-y);
	
	if (x <= 0 || y <= 0 || x >= mapWidth || y >= mapHeight)
	{
		result->y = 0;
	}
	else
	{
		result->y = map_TileHeight(x, y);
		if (water)
		{
			result->y = map_WaterHeight(x, y);
		}
	}
}
void CGameRulesRSSpawning::UpdateMapCentre()
{
	float fNumSpawns = 0.0f;
	Vec3 averagePos(0.0f, 0.0f, 0.0f);

	TSpawnLocations::const_iterator itEnd = m_spawnLocations.end();
	for (TSpawnLocations::const_iterator it=m_spawnLocations.begin(); it!=itEnd; ++it)
	{
		UpdateSpawnPointAverage((*it), fNumSpawns, averagePos);
	}

	int numInitialSpawnGroups = m_initialSpawnLocations.size();
	for (int i = 0; i < numInitialSpawnGroups; ++ i)
	{
		TSpawnLocations &spawnPoints = m_initialSpawnLocations[i].m_locations;
		itEnd = spawnPoints.end();
		for (TSpawnLocations::const_iterator it = spawnPoints.begin(); it!=itEnd; ++it)
		{
			UpdateSpawnPointAverage((*it), fNumSpawns, averagePos);
		}
	}

	SpawnLogAlways("[SPAWN] Map centre calculated as (%.2f, %.2f, %.2f) from average of spawners", averagePos.x, averagePos.y, averagePos.z);

	m_mapCentre = averagePos;
}
Beispiel #3
0
	void ConvexHull::CenterHull()
	{
		// Calculate the average of all of the vertices, and then
		// offset all of them to make this the new origin position (0,0)
		const unsigned int numVertices = m_vertices.size();

		Vec2f posSum(0.0f, 0.0f);
	
		for(unsigned int i = 0; i < numVertices; i++)
			posSum += m_vertices[i];

		Vec2f averagePos(posSum / static_cast<float>(numVertices));

		for(unsigned int i = 0; i < numVertices; i++)
			m_vertices[i] -= averagePos;
	}
Beispiel #4
0
void MainFrame::OnMoveClick(wxRibbonButtonBarEvent& event)
{
    Workspace* workspace = static_cast<Workspace*>(m_auiNotebook->GetCurrentPage());
    if(workspace) {
        auto elementList = workspace->GetAllElements();
        // Calculate the average position of selected elements.
        wxPoint2DDouble averagePos(0, 0);
        int numSelElements = 0;
        for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
            Element* element = *it;
            if(element->IsSelected()) {
                averagePos += element->GetPosition();
                numSelElements++;
            }
        }
        averagePos = wxPoint2DDouble(averagePos.m_x / double(numSelElements), averagePos.m_y / double(numSelElements));
        // Set the move position to the average of selected elements.
        for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
            Element* element = *it;
            if(element->IsSelected()) { element->StartMove(averagePos); }
        }
        workspace->SetWorkspaceMode(Workspace::MODE_MOVE_ELEMENT);
    }
}