Exemplo n.º 1
0
    void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
    {
        DragAndDropTarget::SourceDetails details (sourceDetails);

        setNewScreenPos (screenPos);

        Component* newTargetComp;
        DragAndDropTarget* const newTarget = findTarget (screenPos, details.localPosition, newTargetComp);

        setVisible (newTarget == nullptr || newTarget->shouldDrawDragImageWhenOver());

        if (newTargetComp != currentlyOverComp)
        {
            DragAndDropTarget* const lastTarget = getCurrentlyOver();

            if (lastTarget != nullptr && details.sourceComponent != nullptr
                  && lastTarget->isInterestedInDragSource (details))
                lastTarget->itemDragExit (details);

            currentlyOverComp = newTargetComp;

            if (newTarget != nullptr
                  && newTarget->isInterestedInDragSource (details))
                newTarget->itemDragEnter (details);
        }

        sendDragMove (details);

        if (canDoExternalDrag && getCurrentlyOver() == nullptr)
            checkForExternalDrag (details, screenPos);
    }
Exemplo n.º 2
0
void CalibrationFilter::update() 
{
	if (captures.size() > 0)
	{
		shownCapture = *(captures[settings.show_capture-1]);
	}
	if (settings.capture == true)
	{
		settings.capture = !settings.once;
		grayInput = input;
		if (findTarget()) {
			showCapturesSlider->max = MAX(captures.size(), settings.min_captures);
			settings.show_capture++;
		}
	}
	
	if (settings.calc_undistort == true)
	{
		settings.calc_undistort = false;
		if (captures.size() >= settings.min_captures)
			calibrateCamera();
	}

	if (settings.do_undistort == true &&
		camera.undistMap != NULL)
	{
		cvUnDistort(input.getCvImage(),
					output.getCvImage(),
					camera.undistMap,
					settings.do_interpolate);
	}
}
Exemplo n.º 3
0
void makeCfg()
{
	int i,j;
	//initialize matrix with zero
	for(i=0;i<bc;i++)
		for(j=0;j<bc;j++)
			cfg[i][j]=0;
	
	for(i=0;i<bc;i++)
	{
		if(hasGoto(block[i].end)>=0)
		{
			int tb=findTargetBlock(findTarget(block[i].end));
			cfg[i][tb]=1;
		}
		if(hasGoto(block[i].end)!=0&&i!=bc-1)
			cfg[i][i+1]=1;
		
	}
	printf("CFG is \n==========\n");
	for(i=0;i<bc;i++)
	{
		for(j=0;j<bc;j++)
		{
			printf("%d ",cfg[i][j]);
		}
		printf("\n");
	}
}
Exemplo n.º 4
0
void publishTarget(const geometry_msgs::Pose2D msg ) {

    geometry_msgs::Pose2D temp1;
    temp1.x=msg.x * 513 / SIM_X;
    temp1.y=msg.y * 513 / SIM_Y;
    cv::Mat rec;
    rec=image(cv::Rect(temp1.x,temp1.y,101,101));

    if(temp1.x>250 * 513 / SIM_X)
    {
        for(int i=0;i<rec.rows/2;i++)
        {
            for(int j=0;j<rec.cols;j++)
            {
                int temp=rec.at<uchar>(i,j);
                rec.at<uchar>(i,j)=rec.at<uchar>(rec.rows-i,j);
                rec.at<uchar>(rec.rows-i,j)=temp;
            }
        }
    }
    geometry_msgs::Pose2D result=findTarget(rec);
    if(temp1.x>250 * 513 / SIM_X)
    {
        result.y=100-result.y;
        if(result.y<0)
            result.y=0;
        result.theta*=-1;
    }
    pub_point.publish(result);
}
Exemplo n.º 5
0
/**
 * One frame of logic for this behavior
 */
void BehaviorStandard::logic() {

	// skip all logic if the enemy is dead and no longer animating
	if (e->stats.corpse) {
		if (e->stats.corpse_ticks > 0)
			e->stats.corpse_ticks--;
		return;
	}

	if (!e->stats.hero_ally) {
		if (calcDist(e->stats.pos, pc->stats.pos) <= ENCOUNTER_DIST)
			e->stats.encountered = true;

		if (!e->stats.encountered)
			return;
	}

	doUpkeep();
	findTarget();
	checkPower();
	checkMove();
	updateState();

	fleeing = false;
}
Exemplo n.º 6
0
/* finds proper rule object and adds the appropriate attribute. The parser
 * handles calling parsed_new_target() for the dependencies.
 *
 * @param - string name of target and its dependency to add
 * @return - nothing? function type still requires the void pointer
 */
void* parsed_new_dependency(char *target, char *dependency)
{
	queue_enqueue(queue_at(rules, findTarget(target, rules))->deps, dependency);


	return NULL;
}
Exemplo n.º 7
0
/* finds proper rule object and adds the appropriate attribute.
 *
 * @param - string name of target and its command to add
 * @return - nothing? function type still requires the void pointer
 */
void* parsed_new_command(char *target, char *command)
{
	queue_enqueue(queue_at(rules, findTarget(target, rules))->commands, command);


	return NULL;
}
void publishTarget(const sensor_msgs::ImageConstPtr msg ) {
    if (debug){ROS_INFO("Listened for the %d time\n", count++);
    cv::namedWindow("listening", CV_WINDOW_AUTOSIZE);}
    cv::Mat img;
    

    cv_bridge::CvImagePtr cv_ptr;
    cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::MONO8);
    // img= cv_bridge.imgMsgToCv(msge, "mono8");
    // cv::cvtColor(msg.image,img,CV_BGR2GRAY);
    img = cv_ptr->image;
    msge = findTarget(img);
    geometry_msgs::Pose2D temp1,temp2;
    temp1=msge;
    for(int i=0;i<4;i++)
    {
        temp2=temp[i];
        temp[i]=temp1;
        temp1=temp2;
    }
    pub_point.publish(msge);
    if(debug)
    {
       cv::waitKey(33);
       ROS_INFO("%f %f %f ", msge.x, msge.y, msge.theta);
    }
    if(counter<4)
        counter++;
}
Exemplo n.º 9
0
    void mouseUp (const MouseEvent& e)
    {
        if (e.originalComponent != this)
        {
            if (mouseDragSource != nullptr)
                mouseDragSource->removeMouseListener (this);

            // (note: use a local copy of this in case the callback runs
            // a modal loop and deletes this object before the method completes)
            DragAndDropTarget::SourceDetails details (sourceDetails);
            DragAndDropTarget* finalTarget = nullptr;

            if (! isDoingExternalDrag)
            {
                const bool wasVisible = isVisible();
                setVisible (false);
                Component* unused;
                finalTarget = findTarget (e.getScreenPosition(), details.localPosition, unused);

                if (wasVisible) // fade the component and remove it - it'll be deleted later by the timer callback
                    dismissWithAnimation (finalTarget == nullptr);
            }

            if (getParentComponent() != nullptr)
                getParentComponent()->removeChildComponent (this);

            if (finalTarget != nullptr)
            {
                currentlyOverComp = nullptr;
                finalTarget->itemDropped (details);
            }

            // careful - this object could now be deleted..
        }
    }
Exemplo n.º 10
0
void
makeTarget(
    char *s,
    BOOL firstTarg,
    BUILDBLOCK **block
    )
{
    BUILDLIST  *build;
    MAKEOBJECT *object;

    if (!*block)
        *block = makeNewBuildBlock();

    if (firstTarg) {
        build = makeNewBldListElement();
        build->buildBlock = *block;
    } else
        build = makeBuildList(*block);

    if ((object = findTarget(s))) {
        if (ON(object->flags2, F2_DOUBLECOLON) != ON(currentFlags, F2_DOUBLECOLON))
            makeError(currentLine, MIXED_SEPARATORS);
        appendItem((STRINGLIST**)&(object->buildList), (STRINGLIST*)build);
        FREE(s);
    } else {
        build->next = NULL;
        object = makeNewObject();
        object->name = s;
        object->buildList = build;
        object->flags2 = currentFlags;
        prependItem((STRINGLIST**)targetTable+hash(s, MAXTARGET, (BOOL)TRUE),
                    (STRINGLIST*)object);
    }
}
Exemplo n.º 11
0
void HillHunter::operator()(const Target::AntVector::value_type& hill)
{
    WeightTask nearestAnt;
    if (findTarget(hill, nearestAnt))
    {
//        OUT_PRINT "HILL FOUND: " << hill << " nearest ant " << nearestAnt.first << std::endl;
        assign(nearestAnt.first, std::make_pair(hill,nearestAnt.second));
    }
}
Exemplo n.º 12
0
/**
 * One frame of logic for this behavior
 */
void BehaviorStandard::logic() {

	doUpkeep();
	findTarget();
	checkPower();
	checkMove();
	updateState();

}
Exemplo n.º 13
0
    void mouseUp (const MouseEvent& e)
    {
        if (e.originalComponent != this)
        {
            if (mouseDragSource != nullptr)
                mouseDragSource->removeMouseListener (this);

            bool dropAccepted = false;
            DragAndDropTarget* ddt = nullptr;
            Point<int> relPos;

            if (isVisible())
            {
                setVisible (false);
                ddt = findTarget (e.getScreenPosition(), relPos);

                // fade this component and remove it - it'll be deleted later by the timer callback

                dropAccepted = ddt != nullptr;

                setVisible (true);

                if (dropAccepted || sourceDetails.sourceComponent == nullptr)
                {
                    Desktop::getInstance().getAnimator().fadeOut (this, 120);
                }
                else
                {
                    const Point<int> target (sourceDetails.sourceComponent->localPointToGlobal (sourceDetails.sourceComponent->getLocalBounds().getCentre()));
                    const Point<int> ourCentre (localPointToGlobal (getLocalBounds().getCentre()));

                    Desktop::getInstance().getAnimator().animateComponent (this,
                                                                           getBounds() + (target - ourCentre),
                                                                           0.0f, 120,
                                                                           true, 1.0, 1.0);
                }
            }

            if (getParentComponent() != nullptr)
                getParentComponent()->removeChildComponent (this);

            if (dropAccepted && ddt != nullptr)
            {
                // (note: use a local copy of this in case the callback runs
                // a modal loop and deletes this object before the method completes)
                DragAndDropTarget::SourceDetails details (sourceDetails);
                details.localPosition = relPos;

                currentlyOverComp = nullptr;

                ddt->itemDropped (details);
            }

            // careful - this object could now be deleted..
        }
    }
Exemplo n.º 14
0
void Projectile::initializeFromOwner() {
  findTarget();
  if(target && !isHoming) {
    direction = (target->position() - owner->position()) / (target->position() - owner->position()).length();
  } else {
	  direction = owner->getCamera()->orientation('z');
  }
	setMatrix(owner->rotation());
  setTranslation(owner->position());
}
Exemplo n.º 15
0
	int search(vector<int>& nums, int target) 
	{
		size_t len = nums.size();
		if (len == 0)
			return -1;
		else if (len == 1)
		{
			if (nums[0] == target)
				return 0;
			else return -1;
		}

		//mid必须初始化,以避免初始元素即为最小元素现象
		size_t left = 0, right = len - 1, mid = left;

		//寻找旋转数组中最小的数字
		while (nums[left] >= nums[right]) 
		{
			if (right - left == 1)
			{
				mid = right; break;
			}

			mid = left + (right - left) / 2;
			if (nums[mid] >= nums[left])
				left = mid;
			else if (nums[mid] <= nums[right])
				right = mid;
		}

		if (mid == 0)
			return findTarget(nums, 0, len - 1, target);
		else
		{
			if (nums[0] <= target && nums[mid - 1] >= target)
				return findTarget(nums, 0, mid - 1, target);
			else if (nums[mid] <= target && nums[len - 1] >= target)
				return findTarget(nums, mid, len - 1, target);
		}

		return -1;
	}
Exemplo n.º 16
0
Target *TargetManager::changePath(const char *oldp, const char *newp)
{
	Target *t = findTarget(oldp);
	targets.erase(t);
	free(t->path);
	t->path = strdup(newp);

	targets.insert(t);

	return t;
}
Exemplo n.º 17
0
void publishTarget(const std_msgs::Float64::ConstPtr yaw_msg) {
    geometry_msgs::Pose2D target;
    double heading = yaw_msg->data;

    if (iterations < 5) {
        reference_heading = heading;
        iterations++;
    } else {
        target = findTarget(heading);
        proposed_target_publisher.publish(target);
    }
}
Exemplo n.º 18
0
bool Squad::isAttacking()
{
	if (!isExplorer())
	{
		Unit* target = findTarget();
		if (target != NULL)
		{
			return true;
		}
	}
	return false;
}
Exemplo n.º 19
0
Neighborhood::Neighborhood(SVMData& train, SVMData& test, int nc, int kk[]):sd(&train), sd_test(&test), nclass(nc), k(kk[0]), nfeat(train.nfeat), ninst(train.ninst), ninst_test(test.ninst)
{
  nn[0] = kk[0];
  nn[1] = kk[1];
  nn[2] = kk[2];
  nn[3] = kk[3];
  findTarget();
  deviceInitTarget(target, train.ninst, target_size, &nclass, nn, target_offset);
  deviceInitLabelTrain(train.inst, train.ninst);
  deviceInitLabelTest(test.inst, test.ninst);
  deviceInitInstList(train.inst, train.typecount, train.ninst, nclass, target_size);
}
void TurretClass::doSpecificStuff()
{
	if (target && (target.getObjPointer() != NULL)) {
		if (!canAttack(target.getObjPointer()) || !targetInWeaponRange()) {
			setTarget(NULL);
		} else if (targetInWeaponRange()) {
			Coord closestPoint = target.getObjPointer()->getClosestPoint(location);
			double destAngle = dest_angle(location, closestPoint);
			int wantedAngle = lround(8.0/256.0*destAngle);

			if(wantedAngle == 8) {
				wantedAngle = 0;
			}

			if(angle != wantedAngle) {
				// turn
                double  angleLeft = 0.0;
                double  angleRight = 0.0;

                if(angle > wantedAngle) {
                    angleRight = angle - wantedAngle;
                    angleLeft = fabs(8-angle)+wantedAngle;
                }
                else if (angle < wantedAngle) {
                    angleRight = abs(8-wantedAngle) + angle;
                    angleLeft = wantedAngle - angle;
                }

                if(angleLeft <= angleRight) {
                    turnLeft();
                } else {
                    turnRight();
                }
			}

			if(drawnAngle == wantedAngle) {
				attack();
			}

		} else {
			setTarget(NULL);
		}
	} else if ((attackMode != STOP) && (findTargetTimer == 0)) {
		setTarget(findTarget());
		findTargetTimer = 100;
	}

	if (findTargetTimer > 0)
		findTargetTimer--;
	if (weaponTimer > 0)
		weaponTimer--;
}
Exemplo n.º 21
0
// 플라스틱2
void set_Position(int gathered_Type, int obj_Flag)
{
	// 세부조정 루프
	while(1){
		printf("see down\n");
		// 내려다 보기
		seeDown();
		
		usleep(200000);	// delay 1sec, camera buffer update
		 

		// 내려다 본 결과로 판단

		Target obj = findTarget(&bufCopy, obj_Flag);
		
		printf("see up\n");
		// 몸을 다시 일으키고
		seeUp();
		usleep(500000);
			
		printf("x : %d, y : %d, flag : %d\n", obj.x_point, obj.y_point, obj.flag);
		
		
		// 못 찾았을 경우에 대한 예외처리가 없음 현재는
		if(obj.flag == obj_Flag){
		      if(obj.x_point < detail_minX)
		      {
			  rightOneStep();
			  usleep(200000);
		      }
		      else if(obj.x_point > detail_maxX)
		      {
			  leftOneStep();
			  usleep(200000);
		      }
		      else if(obj.y_point > detail_Y)	
		      {    
			  frontOneStep();
			  usleep(200000);
		      }
		      else
		      {
			  gathered_Touch(gathered_Type);
			  usleep(800000);
			  
			  break;
		      }
		}
	}
}
Exemplo n.º 22
0
/**
 * One frame of logic for this behavior
 */
void BehaviorStandard::logic() {

	// skip all logic if the enemy is dead and no longer animating
	if (e->stats.corpse) {
		if (e->stats.corpse_ticks > 0)
			e->stats.corpse_ticks--;
		return;
	}
	doUpkeep();
	findTarget();
	checkPower();
	checkMove();
	updateState();

}
Exemplo n.º 23
0
bool Klondike::tryToDrop(Card *t)
{
    if (!t || !t->realFace() || t->takenDown())
        return false;

//    kdDebug(11111) << "tryToDrop " << t->name() << endl;

    Pile *tgt = findTarget(t);
    if (tgt) {
        newHint
            (new MoveHint(t, tgt, noLongerNeeded(t->rank(), t->suit())));
        return true;
    }
    return false;
}
Exemplo n.º 24
0
void CannonTower::update() {

	for (int i = 0; i < projectiles.size(); i++) {
		if (projectiles[i]->destroyProjectile == true) {
			gameEngine->addRemovableObjectToList(projectiles[i]);
			projectiles[i] = nullptr;
			projectiles.erase(projectiles.begin() + i);
			i--;
		}
	}


	for (auto current : projectiles) {
		current->update();
	}


	if (reloadTimer.getElapsedTime().asMilliseconds() > reloadTimeMS) {
		reloading = false;
	}

	

	// If it is time to attack
	if (!reloading) {
		// If tower has a previous target, check if that target is still within range
		if (currentTarget != nullptr) {
			if (!targetWithinRange(currentTarget) || currentTarget->isDead()) {
				currentTarget = nullptr;
			}
		}

		// If tower has no target, find one
		if (currentTarget == nullptr) {
			currentTarget = findTarget();
		}
		// If it has a viable target by now, attack it
		if (currentTarget != nullptr) {

			auto sprite = new VortexSprite(gameEngine, projectileSpritePath, posX + width / 2, posY - towerSpriteOffsetY);
			auto projectile = new Projectile(gameEngine, posX + towerSprite->getSize().x / 2, posY, sprite, currentTarget, projectileSpeed, damage, splashRadius, enemyList, particleList, effectsHandler);

			projectiles.push_back(projectile);
			reloading = true;
			reloadTimer.restart();
		}
	}
}
Exemplo n.º 25
0
/** This is the main entry point for the AI.
 *  It is called once per frame for each AI and determines the behaviour of
 *  the AI, e.g. steering, accelerating/braking, firing.
 */
void ArenaAI::update(float dt)
{
    // This is used to enable firing an item backwards.
    m_controls->m_look_back = false;
    m_controls->m_nitro     = false;

    // Don't do anything if there is currently a kart animations shown.
    if (m_kart->getKartAnimation())
        return;

    if (isWaiting())
    {
        AIBaseController::update(dt);
        return;
    }

    checkIfStuck(dt);
    if (handleArenaUnstuck(dt))
        return;

    findClosestKart(true);
    findTarget();
    handleArenaItems(dt);
    handleArenaBanana();

    if (m_kart->getSpeed() > 15.0f && m_cur_kart_pos_data.angle < 0.2f)
    {
        // Only use nitro when target is straight
        m_controls->m_nitro = true;
    }

    if (m_is_uturn)
    {
        handleArenaUTurn(dt);
    }
    else
    {
        handleArenaAcceleration(dt);
        handleArenaSteering(dt);
        handleArenaBraking();
    }

    AIBaseController::update(dt);

}   // update
Exemplo n.º 26
0
void Squad::checkAttack()
{
	if (!isExplorer())
	{
		Unit* target = findTarget();
		
		if (target != NULL)
		{
			for (int i = 0; i < (int)agents.size(); i++)
			{
				BaseAgent* agent = agents.at(i);
				if (agent->isAlive() && agent->canAttack(target) && !(agent->getUnit()->isAttacking() || agent->getUnit()->isStartingAttack()))
				{
					agent->getUnit()->attack(target);
				}
			}
		}
	}
}
Exemplo n.º 27
0
void RpgPlayer::putAtkSkill(const std::string& skillname,const RpgSkillData &skillData)
{
	if (skillname=="speed")
	{
		// 给予10秒的加速
		monsterData.step = 128;
		speedTime = 0.4;
		this->addTime(MOVE_SPEED_UP,10);
	}
	else
	{
		RpgMap * map = (RpgMap*) this->getParent();
		stFindTargetAttack findTarget((RpgSkillData *)&skillData,this);
		
		if (map)
		{
			map->execTargets(this->getGridPoint(),((RpgSkillData*)&skillData)->getAtkDistance(),&findTarget);
		}
		RpgMonster::putAtkSkill(skillname);
	}
}
Exemplo n.º 28
0
void TargetingAgent::checkTarget(BaseAgent* agent)
{
    Unit* cTarget = agent->getUnit()->getTarget();
    if (cTarget == NULL)
    {
        cTarget = agent->getUnit()->getOrderTarget();
    }

    if (cTarget != NULL)
    {
        Unit* pTarget = findTarget(agent);
        if (pTarget != NULL && pTarget->getPlayer()->isEnemy(Broodwar->self()))
        {
            if (pTarget->getType().getID() != cTarget->getType().getID())
            {
                //Show debug info for selected unit, or first
                //in list if mulitple units are selected.
                set<Unit*> units = Broodwar->getSelectedUnits();
                if ((int)units.size() > 0)
                {
                    int unitID = (*units.begin())->getID();
                    if (agent->getUnitID() == unitID)
                    {
                        int uX = agent->getUnit()->getPosition().x();
                        int uY = agent->getUnit()->getPosition().y();
                        int tX = pTarget->getPosition().x();
                        int tY = pTarget->getPosition().y();
                        Broodwar->drawLineMap(uX,uY,tX,tY,Colors::Yellow);
                    }
                }
                UnitAgent* ua = (UnitAgent*)agent;
                if (ua->canSwitchTarget())
                {
                    agent->getUnit()->attack(pTarget, true);
                    agent->getUnit()->rightClick(pTarget, true);
                }
            }
        }
    }
}
Exemplo n.º 29
0
void TargetTracker::tracking(std::vector<TargetState> states)
{
    std::vector<TargetState>::const_iterator iter;
    TargetState tState;
    KalmanFilter *filter;
    SingleTarget *target;
    qDebug() << "测量值:";

    for (iter = states.begin(); iter != states.end(); ++iter)
    {
        tState = *iter;
        tState.state.print();

        filter = findFilter(tState.groupId, tState.targetId);
        target = findTarget(tState.groupId, tState.targetId);
        if (target == NULL) continue;
        if (filter == NULL) continue;
        if (target->getStateCount() == 0) {
            // 第一次获取目标的状态,直接保存,不做任何计算。
            target->addState(tState.state);
            filter->setState(tState.state.getData());
            continue;
        }
        //计算一步预测值
        Matrix matrix = filter->estimate();
        // 根据测量值更新预测数据
        filter->updateByMeasure(tState.state.getData());
        State s;
        s.setData(matrix);
        s.setTime(tState.time);
        target->addState(s);
    }

    //项目验收后去掉
    initMessage();

    printTargetGroups();
}
Exemplo n.º 30
0
 vector<vector<int> > fourSum(vector<int> &num, int target) {
     answer.clear();
     sort(num.begin(), num.end());
     if (num.size() < 4) return answer;
     for (int i = 0; i < num.size() - 3;)
     {
         for (int j = num.size() - 1; i < j; )
         {
             findTarget(i, j, num, target - num[i] - num[j]);
             j--;
             while(j > i && num[j] == num[j + 1])
             {
                 j--;
             }
         }
         i++;
         while(i < num.size() - 4 && num[i] == num[i - 1])
         {
             i++;
         }
     }
     return answer;
 }