示例#1
0
static bool FindIntersection(const double& x0, const double& y0,
                                  const double& x1, const double& y1,
                                  const double& a0, const double& b0,
                                  const double& a1, const double& b1,
                                  double& xy, double& ab) {
    // four endpoints are x0, y0 & x1,y1 & a0,b0 & a1,b1
    // returned values xy and ab are the fractional distance along xy and ab
    // and are only defined when the result is true
    
    bool partial = false;
    double denom = (b0 - b1) * (x0 - x1) - (y0 - y1) * (a0 - a1);
    if (denom == 0) {
        xy = -1;
        ab = -1;
    } else {
        xy = (a0 * (y1 - b1) + a1 * (b0 - y1) + x1 * (b1 - b0)) / denom;
        partial = IsBetween(-0.02, xy, 1.02);
        if (partial) {
            // no point calculating this unless xy is between 0 & 1
            ab = (y1 * (x0 - a1) + b1 * (x1 - x0) + y0 * (a1 - x1)) / denom;
        }
    }
    if ( partial && IsBetween(-0.02, ab, 1.02)) {
        ab = 1-ab;
        xy = 1-xy;
        return true;
    }  else return false;
}
示例#2
0
文件: HaveVertex.cpp 项目: 7kia/CG
void CHaveReferenceVertex::CheckIndex(uint index) const
{
	if (!IsBetween(index, 0u, uint(m_pVertex.size())))
	{
		throw std::runtime_error("Vertex have the index not exist");
	}
}
示例#3
0
void CheckAlarms() {
	SYSTEMTIME time;
	GetLocalTime(&time);

	// put triggered alarms in another list - so we don't keep the critical section locked for longer than necessary
	AlarmList triggered_list, remove_list;

	mir_cslock lck(alarm_cs);
	ALARM *i;
	for(alarms.reset(); i = alarms.current(); alarms.next()) {
		if (!UpdateAlarm(i->time, i->occurrence)) { 
			// somehow an expired one-off alarm is in our list
			remove_list.push_back(i);
			continue;
		}

		switch(i->occurrence) {
		case OC_ONCE:
			if (IsBetween(i->time, last_check, time)) {
				if (!startup || !(i->flags & ALF_NOSTARTUP)) triggered_list.push_back(i);
				// erase and fix iterator - alarm has now been triggered and has therefore expired
				remove_list.push_back(i);
			}
			break;
		default:
			if (IsBetween(i->time, last_check, time)) {
				if (i->flags & ALF_SUSPENDED)
					i->flags = i->flags & ~ALF_SUSPENDED;
				else
					if (!startup || !(i->flags & ALF_NOSTARTUP)) triggered_list.push_back(i);
			}
			break;
		}
	}
	
	last_check = time;
	WriteLastCheckTime();

	startup = false;

	for(triggered_list.reset(); i = triggered_list.current(); triggered_list.next())
		DoAlarm(i);
	for(remove_list.reset(); i = remove_list.current(); remove_list.next())
		remove(i->id);


}
示例#4
0
void copy_list(AlarmList &copy, SYSTEMTIME &start, SYSTEMTIME &end) {
	copy.clear();
	ALARM *i;
	mir_cslock lck(alarm_cs);
	for(alarms.reset(); i = alarms.current(); alarms.next())
		if (IsBetween(i->time, start, end))
			copy.push_back(i);
}
    void UpdatePortals() // Here we handle the beams' behavior
    {
        for (int j=0; j<3; ++j) // j = color
            if (Creature *portal = Unit::GetCreature(*me, PortalGUID[j]))
            {
                // the one who's been casted upon before
                Unit *current = Unit::GetUnit(*portal, BeamTarget[j]);
                // temporary store for the best suitable beam reciever
                Unit *pTarget = me;

                if (Map* map = me->GetMap())
                {
                    Map::PlayerList const& players = map->GetPlayers();

                    // get the best suitable target
                    for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
                    {
                        Player* p = i->getSource();
                        if (p && p->isAlive() // alive
                            && (!pTarget || pTarget->GetDistance2d(portal)>p->GetDistance2d(portal)) // closer than current best
                            && !p->HasAura(PlayerDebuff[j],0) // not exhausted
                            && !p->HasAura(PlayerBuff[(j+1)%3],0) // not on another beam
                            && !p->HasAura(PlayerBuff[(j+2)%3],0)
                            && IsBetween(me, p, portal)) // on the beam
                            pTarget = p;
                    }
                }
                // buff the target
                if (pTarget->GetTypeId() == TYPEID_PLAYER)
                    pTarget->AddAura(PlayerBuff[j], pTarget);
                else
                    pTarget->AddAura(NetherBuff[j], pTarget);
                // cast visual beam on the chosen target if switched
                // simple target switching isn't working -> using BeamerGUID to cast (workaround)
                if (!current || pTarget != current)
                {
                    BeamTarget[j] = pTarget->GetGUID();
                    // remove currently beaming portal
                    if (Creature *beamer = Unit::GetCreature(*portal, BeamerGUID[j]))
                    {
                        beamer->CastSpell(pTarget, PortalBeam[j], false);
                        beamer->SetVisibility(VISIBILITY_OFF);
                        beamer->DealDamage(beamer, beamer->GetMaxHealth());
                        beamer->RemoveFromWorld();
                        BeamerGUID[j] = 0;
                    }
                    // create new one and start beaming on the target
                    if (Creature *beamer = portal->SummonCreature(PortalID[j],portal->GetPositionX(),portal->GetPositionY(),portal->GetPositionZ(),portal->GetOrientation(),TEMPSUMMON_TIMED_DESPAWN,60000))
                    {
                        beamer->CastSpell(pTarget, PortalBeam[j], false);
                        BeamerGUID[j] = beamer->GetGUID();
                    }
                }
                // aggro target if Red Beam
                if (j == RED_PORTAL && me->getVictim() != pTarget && pTarget->GetTypeId() == TYPEID_PLAYER)
                    me->getThreatManager().addThreat(pTarget, 100000.0f+DoGetThreat(me->getVictim()));
            }
    }
示例#6
0
bool Intersect(int &x, int &y, CRect &DRect, CPoint &Pt1, CPoint &Pt2)
{
	int xt, yt;
	double x1 = (double)Pt1.x;
	double x2 = (double)Pt2.x;
	double y1 = (double)Pt1.y;
	double y2 = (double)Pt2.y;


	if (IsBetween(DRect.left, Pt1.x, Pt2.x)){
		yt = int(y1 + (y2-y1)/(x2-x1) * ((double)DRect.left-x1));
		if (IsBetween(yt, DRect.bottom, DRect.top)) {
			x = DRect.left;
			y = yt;
			return true;
		}
	}
	if (IsBetween(DRect.right, Pt1.x, Pt2.x)){
		yt = int(y1 + (y2-y1)/(x2-x1) * ((double)DRect.right-x1));
		if (IsBetween(yt, DRect.bottom, DRect.top)) {
			x = DRect.right;
			y = yt;
			return true;
		}
	}
	if (IsBetween(DRect.bottom, Pt1.y, Pt2.y)){
		xt = int(x1 + (x2-x1)/(y2-y1) * ((double)DRect.bottom-y1));
		if (IsBetween(xt, DRect.left, DRect.right)) {
			x = xt;
			y = DRect.bottom;
			return true;
		}
	}
	if (IsBetween(DRect.top, Pt1.y, Pt2.y)){
		xt = int(x1 + (x2-x1)/(y2-y1) * ((double)DRect.top-y1));
		if (IsBetween(xt, DRect.left, DRect.right)) {
			x = xt;
			y = DRect.top;
			return true;
		}
	}
	return false;
}