當前位置: 首頁>>代碼示例>>C++>>正文


C++ GetDistance函數代碼示例

本文整理匯總了C++中GetDistance函數的典型用法代碼示例。如果您正苦於以下問題:C++ GetDistance函數的具體用法?C++ GetDistance怎麽用?C++ GetDistance使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetDistance函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: D3DXMatrixInverse

route_node* CRouter::InitCurDest(const D3DXMATRIX *mat)
{
	route_node *pDest = NULL;
	route_node *temp = m_pRouteList->GetRouteList();
	if (temp == NULL)
		return NULL;

	D3DXVECTOR3 vCur, vPrev;
	D3DXMATRIX mInverse;
	D3DXMatrixInverse(&mInverse, NULL, mat);
	float	fDistance = 1e10;
	do 
	{
		D3DXVec3TransformCoord(&vCur, temp->pPos, &mInverse);
		D3DXVec3TransformCoord(&vPrev, temp->pPrev->pPos, &mInverse);
		if ((vCur.z > 0) && (vPrev.z < 0))
		{
			vCur.y = vPrev.y = 0.0f;//消除俯仰偏角
			//避免存在平行街道,如果存在,取最近的一條
			if (fDistance > GetDistance(&vCur, &vPrev))
			{
				fDistance = GetDistance(&vCur, &vPrev);
				pDest = temp;
			}
		}
		temp = temp->pNext;

	}	while (temp != m_pRouteList->GetRouteList());

	return pDest;
}
開發者ID:flair2005,項目名稱:vr-bike,代碼行數:31,代碼來源:Router.cpp

示例2: GetDistance

void InterpolatorDistance2::GetInterpolationWeight(NNCandidate candidates[3], 
	int* indices, float* weights, Vertex v) 
{
	int K=3;
	float dist_v_c1 = GetDistance(v.pos, candidates[0].vertex.pos);
	float dist_v_c2 = GetDistance(v.pos, candidates[1].vertex.pos);
	float dist_v_c3 = GetDistance(v.pos, candidates[2].vertex.pos);
	
	float normalize = dist_v_c1 * dist_v_c2 + 
										dist_v_c1 * dist_v_c3 + 
										dist_v_c2 * dist_v_c3;

	if(normalize == 0.0f){
		for(int i=0; i<K; ++i){
			weights[i] = 1.0f/3.0f;
		}
	}
	else{
		weights[0] = dist_v_c2 * dist_v_c3 / normalize;
		weights[1] = dist_v_c1 * dist_v_c3 / normalize;
		weights[2] = dist_v_c1 * dist_v_c2 / normalize;
	}

	for(int i=0; i<K; ++i){
		indices[i] = candidates[i].index;
	}
}
開發者ID:flosmn,項目名稱:MeshPRT,代碼行數:27,代碼來源:InterpolatorDistance2.cpp

示例3: while

/**
*  @brief
*    Sets the node position
*/
void GraphNode::SetPos(float fX, float fY, float fZ)
{
	// Set new position
	m_vPos.SetXYZ(fX, fY, fZ);

	{ // Calculate all node distances
		Iterator<Neighbour*> cIterator = m_lstNeighbours.GetIterator();
		while (cIterator.HasNext()) {
			Neighbour *pNeighbour = cIterator.Next();
			pNeighbour->fDistance = GetDistance(*pNeighbour->pNode);
		}
	}

	{ // Update all neighbour node distances
		Iterator<GraphNode*> cIterator = m_lstIsNeighbourFrom.GetIterator();
		while (cIterator.HasNext()) {
			// Find this node within the neighbour
			Iterator<Neighbour*> cNeighbourIterator = cIterator.Next()->m_lstNeighbours.GetIterator();
			while (cNeighbourIterator.HasNext()) {
				Neighbour *pNeighbour = cNeighbourIterator.Next();
				if (pNeighbour->pNode == this) {
					pNeighbour->fDistance = GetDistance(*pNeighbour->pNode);
					break;
				}
			}
		}
	}
}
開發者ID:ByeDream,項目名稱:pixellight,代碼行數:32,代碼來源:GraphNode.cpp

示例4: CheckNewPoint

void CheckNewPoint(void) {
    // 檢查是不是有沒有處理的新點
    if (chkedPntsN < spcPntsN && spcPnts[spcPntsN].dist + 4 < GetDistance() ) {
        if (lastAllWhiteDist == 0 || lastAllWhiteDist + 70 < GetDistance()) {
            if (spcPnts[spcPntsN].allWhite > 0) {
                // 進入坡道
                //PORTB = ~(1);
                lastAllWhiteDist = GetDistance();

                ProcRamp();

            }

            if (spcPnts[spcPntsN].allBlack > 0 || spcPnts[spcPntsN].likeStart > 0) {
                // 此處 乘3 因為allBlack 往往比 likeStart 大很多
                if (spcPnts[spcPntsN].allBlack > spcPnts[spcPntsN].likeStart * 3) {
                    // 交叉點
                    //PORTB = ~PORTB;
                    ProcCrossLine();

                } else {
                    // 出發線
                    //PORTB = 0x9;
                    ProcStartLine();


                }
            }
        }
        chkedPntsN++;
    }
}
開發者ID:xfguo,項目名稱:freescalesmartcar,代碼行數:32,代碼來源:cCoreControl.c

示例5:

GameObject* S013010C_Aaron_Smith_Steering::GetClosestObject(Vector2D ahead1, Vector2D ahead2)
{
	GameObject* closestObj = nullptr;

	obstacles = ObstacleManager::Instance()->GetObstacles();
	for (GameObject* obj : obstacles)
	{
		//bool collision = CheckLineInstersect(ahead1, ahead2, obj);
		
		bool collision = Collisions::Instance()->PointInBox(ahead2, obj->GetAdjustedBoundingBox());

		if (collision)
		{
		
			if (closestObj == NULL)
				closestObj = obj;
			else
			{
				if (GetDistance(mTank->GetCentrePosition(), obj->GetCentralPosition()) < GetDistance(mTank->GetCentrePosition(), closestObj->GetCentralPosition()))
					closestObj = obj;
			}
		}
		
	}

	return closestObj;

}
開發者ID:CrohnsAndMe,項目名稱:Test,代碼行數:28,代碼來源:S013010C_Aaron_Smith_Steering.cpp

示例6: GetMinDistance

f32 Toolkit :: GetMinDistance(position2df p, Node2DInfo* pNode2DInfo)
{
	core::line2df l[4];
	f32 minDis = 0.f;
	l[0].start = pNode2DInfo->corner[0];
	l[0].end = pNode2DInfo->corner[1];

	l[1].start = pNode2DInfo->corner[1];
	l[1].end = pNode2DInfo->corner[2];

	l[2].start = pNode2DInfo->corner[2];
	l[2].end = pNode2DInfo->corner[3];

	l[3].start = pNode2DInfo->corner[3];
	l[3].end = pNode2DInfo->corner[0];
	minDis = GetDistance(l[0].getClosestPoint(p), p);
	for (int i = 0; i < 4; i++)
	{
		f32 t = GetDistance(l[i].getClosestPoint(p), p);
		if ( minDis > t )
		{
			minDis = t;
		}
	}
	
	return minDis;
}
開發者ID:HermanYang,項目名稱:Scar,代碼行數:27,代碼來源:Toolkit.cpp

示例7: FindWaypoint

bool NPC::DoWaypointNav (void)
{
	if (m_currentWaypointIndex < 0 || m_currentWaypointIndex >= g_numWaypoints)
		FindWaypoint();

	float waypointDistance = GetDistance(pev->origin, m_waypointOrigin);
	float desiredDistance = g_waypoint->g_waypointPointRadius[m_currentWaypointIndex];

	if (desiredDistance < 16.0f && waypointDistance < 30.0f)
	{
		Vector nextFrameOrigin = pev->origin + (pev->velocity * m_frameInterval);

		if (GetDistance(nextFrameOrigin, m_waypointOrigin) >= waypointDistance)
			desiredDistance = waypointDistance + 1.0f;
	}
	
	if (waypointDistance < desiredDistance)
	{
		if (m_goalWaypoint == m_currentWaypointIndex)
			return true;
		else if (m_navNode == null)
			return false;

		HeadTowardWaypoint();
		return false;
	}

	if (GetDistance(m_waypointOrigin, pev->origin) <= 2.0f)
		HeadTowardWaypoint();

	return false;
}
開發者ID:CCNHsK-Dev,項目名稱:SyPB,代碼行數:32,代碼來源:npc_ai.cpp

示例8: hgeCreate

void Hero::Dash()
{
	HGE *hge = hgeCreate(HGE_VERSION);
	GameObject *temp = GameObject::MakePosObject(TargetX2, TargetY2);
	if (locked == false)
	{

		SowrdCharge -= GetDistance(temp);
		if ((int)SowrdCharge > 0) 
		{
			locked = true;
			adddmg = GetDistance(temp) / 20;
			TargetX = TargetX2;
			TargetY = TargetY2;
		}
		else
		{
			SowrdCharge += GetDistance(temp);
			return;
		}
	}
	if (locked)
	{	
		SetSpeed(SPEED + (GetDistance(temp) * 8));
	}
}
開發者ID:Hiseen,項目名稱:HGE1,代碼行數:26,代碼來源:Hero.cpp

示例9: ClickDoor

void MQ2NavigationPlugin::AttemptClick()
{
	if (!m_isActive && !m_bSpamClick)
		return;

	// don't execute if we've got an item on the cursor.
	if (GetCharInfo2()->pInventoryArray && GetCharInfo2()->pInventoryArray->Inventory.Cursor)
		return;

	clock::time_point now = clock::now();

	// only execute every 500 milliseconds
	if (now < m_lastClick + std::chrono::milliseconds(500))
		return;
	m_lastClick = now;

	if (m_pEndingDoor && GetDistance(m_pEndingDoor->X, m_pEndingDoor->Y) < 25)
	{
		ClickDoor(m_pEndingDoor);
	}
	else if (m_pEndingItem && GetDistance(m_pEndingItem->X, m_pEndingItem->Y) < 25)
	{
		ClickGroundItem(m_pEndingItem);
	}
}
開發者ID:dannuic,項目名稱:MQ2Nav,代碼行數:25,代碼來源:MQ2Navigation.cpp

示例10: ProcStartLine

void ProcStartLine(void) {
    nowLoop++;
    switch (nowLoop) {
    case 1:
        PORTB = ~0x22;

        StartLineDist[0] = GetDistance();
        break;
    case 2:
        StartLineDist[1] = GetDistance();

        PORTB = 0xA5;

        // 跑完第二圈後停下
        DistLimit = ( GetDistance() + (StartLineDist[1] - StartLineDist[0]) ) / 25 + 4;
        /** 在這裏觸發路徑播放 **/
        StartPathPlay();

        //maxSpeed = 110;
        //minSpeed = 75;


        break;
    case 3:
        // 到第三圈後停下
        StartLineDist[2] = GetDistance();

        PORTB = 0x81;
        //DistLimit = GetDistance() / 25 + 2;
        break;
    default:
        break;
    }
}
開發者ID:xfguo,項目名稱:freescalesmartcar,代碼行數:34,代碼來源:cCoreControl.c

示例11: sort

void PreRanker::Filter(bool viewportSearch)
{
  using TSet = set<impl::PreResult1, LessFeatureID>;
  TSet theSet;

  sort(m_results.begin(), m_results.end(), ComparePreResult1());
  m_results.erase(unique(m_results.begin(), m_results.end(), EqualFeatureID()), m_results.end());

  sort(m_results.begin(), m_results.end(), &impl::PreResult1::LessDistance);

  if (m_limit != 0 && m_results.size() > m_limit)
  {
    // Priority is some kind of distance from the viewport or
    // position, therefore if we have a bunch of results with the same
    // priority, we have no idea here which results are relevant.  To
    // prevent bias from previous search routines (like sorting by
    // feature id) this code randomly selects tail of the
    // sorted-by-priority list of pre-results.

    double const last = m_results[m_limit - 1].GetDistance();

    auto b = m_results.begin() + m_limit - 1;
    for (; b != m_results.begin() && b->GetDistance() == last; --b)
      ;
    if (b->GetDistance() != last)
      ++b;

    auto e = m_results.begin() + m_limit;
    for (; e != m_results.end() && e->GetDistance() == last; ++e)
      ;

    // The main reason of shuffling here is to select a random subset
    // from the low-priority results. We're using a linear
    // congruential method with default seed because it is fast,
    // simple and doesn't need an external entropy source.
    //
    // TODO (@y, @m, @vng): consider to take some kind of hash from
    // features and then select a subset with smallest values of this
    // hash.  In this case this subset of results will be persistent
    // to small changes in the original set.
    minstd_rand engine;
    shuffle(b, e, engine);
  }
  theSet.insert(m_results.begin(), m_results.begin() + min(m_results.size(), m_limit));

  if (!viewportSearch)
  {
    size_t n = min(m_results.size(), m_limit);
    nth_element(m_results.begin(), m_results.begin() + n, m_results.end(),
                &impl::PreResult1::LessRank);
    theSet.insert(m_results.begin(), m_results.begin() + n);
  }

  m_results.reserve(theSet.size());
  m_results.clear();
  copy(theSet.begin(), theSet.end(), back_inserter(m_results));
}
開發者ID:igortomko,項目名稱:omim,代碼行數:57,代碼來源:pre_ranker.cpp

示例12: NodeFromWorldPoint

vector<PositionNode*> AstarPathfind::FindPath(Vector2 startPos, Vector2 targetPos)
{
	PositionNode* startNode = NodeFromWorldPoint(startPos);
	PositionNode* targetNode = NodeFromWorldPoint(targetPos);

	vector<PositionNode*> openSet;
	vector<PositionNode*> closeSet;

	openSet.push_back(startNode);

	while(openSet.size() > 0)
	{
		PositionNode* currentNode = openSet[0];
		
		for(int i = 1; i < openSet.size(); ++i)
		{
			if(openSet[i]->GetfCost() < currentNode->GetfCost() || (openSet[i]->GetfCost() == currentNode->GetfCost() && openSet[i]->GethCost() < currentNode->GethCost()))
			{
				currentNode = openSet[i];
			}
		}

		openSet.erase(std::remove(openSet.begin(), openSet.end(), currentNode), openSet.end());
		closeSet.push_back(currentNode);

		if(currentNode == targetNode)
		{
			openSet.clear();
			closeSet.clear();
			return RetracePath(startNode, targetNode);
		}

		vector<PositionNode*> neighbours = GetNeighbours(currentNode);

		for(int i = 0; i < neighbours.size(); ++i)
		{
			if(!neighbours[i]->GetWalkable() || (std::find(closeSet.begin(), closeSet.end(), neighbours[i]) != closeSet.end()))
			{
				continue;
			}

			int newMovementCostToNeighbour = currentNode->GetgCost() + GetDistance(currentNode, neighbours[i]);

			if(newMovementCostToNeighbour < neighbours[i]->GetgCost() || !(std::find(openSet.begin(), openSet.end(), neighbours[i]) != openSet.end()))
			{
				neighbours[i]->SetgCost(newMovementCostToNeighbour);
				neighbours[i]->SethCost(GetDistance(neighbours[i], targetNode));
				neighbours[i]->SetParentNode(currentNode);

				if(!(std::find(openSet.begin(), openSet.end(), neighbours[i]) != openSet.end()))
				{
					openSet.push_back(neighbours[i]);
				}
			}
		}
	}
}
開發者ID:blazetrinity,項目名稱:SP3,代碼行數:57,代碼來源:AstarPathfind.cpp

示例13: ln

double F::DISTANCE::GetLineSegmentPointDistance(const CLineSegment &_ls, const CVector &_p )
{
	CLine ln(_ls);
	double dist = GetLinePointDistance(ln,_p);

	if(F::INTERSECTION::PointProjectionOnLineSegment(_p, _ls))
		return dist;

	return F::MISC::Min(GetDistance(_ls.a,_p), GetDistance(_ls.b,_p));
}
開發者ID:vladamakaric,項目名稱:softBodyDynamics,代碼行數:10,代碼來源:f_distance.cpp

示例14: NewSpecialPoint

// 檢測是不是同一個點, 不是則新開一個
void NewSpecialPoint(void) {
    if (GetDistance() - spcPnts[spcPntsN].dist > 8) {
        if (spcPntsN > 28) return;
        spcPntsN++;
        spcPnts[spcPntsN].allWhite = 0;
        spcPnts[spcPntsN].allBlack = 0;
        spcPnts[spcPntsN].likeStart = 0;
        spcPnts[spcPntsN].dist = GetDistance();
    }
}
開發者ID:xfguo,項目名稱:freescalesmartcar,代碼行數:11,代碼來源:cCoreControl.c

示例15: IsInside

	Side Plane::IsInside(const BoxBounds& aabb) const
	{
		if (GetDistance(aabb.GetVertexP(mNormal)) < 0) {
			return Side::Out;
		}
		if (GetDistance(aabb.GetVertexN(mNormal)) > 0)
		{
			return Side::In;
		}
		return Side::Cross;
	}
開發者ID:luxuia,項目名稱:JustEngine,代碼行數:11,代碼來源:Plane.cpp


注:本文中的GetDistance函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。