Ejemplo n.º 1
0
bool Cuboid2D<T>::CheckIntersection(
    T xPosition0
  , T yPosition0
  , T xPosition1
  , T yPosition1
  , gsl::index& rXIndex0
  , gsl::index& rYIndex0
  , gsl::index& rXIndex1
  , gsl::index& rYIndex1
  , std::size_t overlap/*=0*/) const
{
  if (CheckIntersection(xPosition0, yPosition0, xPosition1,
      yPosition1, overlap)) {
    rXIndex0 = std::max(static_cast<gsl::index>((xPosition0 - mXPosition) /
        mDeltaR + overlap + 0.5), gsl::index{0});
    rYIndex0 = std::max(static_cast<gsl::index>((yPosition0 - mYPosition) /
        mDeltaR + overlap + 0.5), gsl::index{0});
    rXIndex1 = std::min(static_cast<gsl::index>((xPosition1 - mXPosition) /
        mDeltaR + overlap + 0.5), static_cast<gsl::index>(mNx - 1 + 2 *
        overlap));
    rYIndex1 = std::min(static_cast<gsl::index>((yPosition1 - mYPosition) /
        mDeltaR + overlap + 0.5), static_cast<gsl::index>(mNy - 1 + 2 *
        overlap));
    return true;
  }
  else {
    rXIndex0 = 1;
    rXIndex1 = 0;
    rYIndex0 = 1;
    rYIndex1 = 0;
    return false;
  }
}
Ejemplo n.º 2
0
bool CBattleDust::CheckForMerging(CBattleEvent* pEvent)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if(!g_pGameCVars->g_battleDust_enable)
		return false;

	if(!pEvent)
		return false;

	if(!gEnv->bServer)
		return false;

	// check if area can merge with nearby areas
	for(std::list<EntityId>::iterator it = m_eventIdList.begin(); it != m_eventIdList.end(); ++it)
	{
		EntityId areaId = (*it);
		CBattleEvent *pBattleArea = FindEvent(areaId);
		if(!pBattleArea)
			continue;

		if(CheckIntersection(pEvent, pBattleArea->m_worldPos, pBattleArea->m_radius) && pBattleArea->m_radius > 0 && (pBattleArea != pEvent) && pBattleArea->GetEntity())
		{
			MergeAreas(pBattleArea, pEvent->m_worldPos, pEvent->m_radius);
			return true;
		}
	}

	return false;
}
Ejemplo n.º 3
0
bool Cuboid2D<T>::CheckIntersection(
    T xPosition
  , T yPosition
  , std::size_t overlap/*=0*/) const
{
  // This is just ContainPoint(xPosition, yPosition, overlap)
  return CheckIntersection(xPosition, yPosition, xPosition, yPosition,
      overlap);
}
Ejemplo n.º 4
0
void ShapeFactory::addLine(ofVec2f point)
{

	for(int i = 0 ;i < points.size() - 3; i ++){

		ofVec2f intersection;
		if(CheckIntersection(_lastPoint, point, points[i], points[i + 1], intersection)){

			_lineComplete = true;
			points = vector<ofVec2f>(points.begin() + i, points.end());

			break;
		}
	}

	points.push_back(point);
}
Ejemplo n.º 5
0
void CBattleDust::RecordEvent(EBattleDustEventType event, Vec3 worldPos, const IEntityClass* pClass)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if(!g_pGameCVars->g_battleDust_enable)
		return;

	if(!gEnv->bServer)
		return;

	// this typically means the xml file failed to load. Turn off the dust.
	if(m_maxParticleCount == 0)
		return;

	SBattleEventParameter param;
	if(!GetEventParams(event, pClass, param))
		return;
	
	if(param.m_power == 0 || worldPos.IsEquivalent(Vec3(0,0,0)))
		return;

	if(m_pBattleEventClass == NULL)
		m_pBattleEventClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( "BattleEvent" );

	// first check if we need a new event
	bool newEvent = true;
	for(std::list<EntityId>::iterator it = m_eventIdList.begin(); it != m_eventIdList.end(); ++it)
	{
		EntityId areaId = (*it);
		CBattleEvent *pBattleArea = FindEvent(areaId);
		if(pBattleArea && CheckIntersection(pBattleArea, worldPos, param.m_power))
		{
			// don't need a new event as this one is within an existing one. Just merge them.
			MergeAreas(pBattleArea, worldPos, param.m_power);
			pBattleArea->m_lifeRemaining += param.m_lifetime;
			pBattleArea->m_lifetime = pBattleArea->m_lifeRemaining;
			pBattleArea->m_lifetime = CLAMP(pBattleArea->m_lifetime, 0.0f, m_maxLifetime);
			pBattleArea->m_lifeRemaining = CLAMP(pBattleArea->m_lifeRemaining, 0.0f, m_maxLifetime);
			newEvent = false;			
			break;
		}
	}
 
	if(newEvent)
	{
		IEntitySystem * pEntitySystem = gEnv->pEntitySystem;
 		SEntitySpawnParams esp;
 		esp.id = 0;
 		esp.nFlags = 0;
 		esp.pClass = m_pBattleEventClass;
 		if (!esp.pClass)
 			return;
 		esp.pUserData = NULL;
 		esp.sName = "BattleDust";
 		esp.vPosition	= worldPos;
	
		// when CBattleEvent is created it will add itself to the list
		IEntity * pEntity = pEntitySystem->SpawnEntity( esp );
		if(pEntity)
		{
			// find the just-added entity in the list, and set it's properties
			IGameObject* pGO = g_pGame->GetIGameFramework()->GetGameObject(pEntity->GetId());
			if(pGO)
			{
				CBattleEvent* pNewEvent = static_cast<CBattleEvent*>(pGO->QueryExtension("BattleEvent"));
				if(pNewEvent)
				{
					pNewEvent->m_radius = param.m_power;
					pNewEvent->m_peakRadius = param.m_power;
					pNewEvent->m_lifetime = param.m_lifetime;
					pNewEvent->m_lifeRemaining = param.m_lifetime;
					pNewEvent->m_worldPos = worldPos;

					pNewEvent->m_lifetime = CLAMP(pNewEvent->m_lifetime, 0.0f, m_maxLifetime);
					pNewEvent->m_lifeRemaining = CLAMP(pNewEvent->m_lifeRemaining, 0.0f, m_maxLifetime);

					pGO->ChangedNetworkState(CBattleEvent::PROPERTIES_ASPECT);
				}
			}
		}
	}
}