当前位置: 首页>>代码示例>>C++>>正文


C++ Vector2::Normalized方法代码示例

本文整理汇总了C++中Vector2::Normalized方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2::Normalized方法的具体用法?C++ Vector2::Normalized怎么用?C++ Vector2::Normalized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector2的用法示例。


在下文中一共展示了Vector2::Normalized方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ComputeSeperation

Vector3 CFSM::ComputeSeperation(vector<CFSM*> ListOfCharacters)
{
	Vector2 steer;
	steer.SetZero();

	int count = 0;

	for (int i = 0; i < ListOfCharacters.size(); ++i)
	{
		if (ListOfCharacters[i] != this && ListOfCharacters[i]->GetAlive())
		{
			float distance = (m_CurrentPosition - ListOfCharacters[i]->GetPosition()).Length();
			if (distance < m_seperationZone)
			{
				Vector3 DirectionCopy = m_CurrentPosition - ListOfCharacters[i]->GetPosition();
				Vector2 diff = Vector2(DirectionCopy.x, DirectionCopy.z);
				if (!diff.IsZero())
				{
					diff = diff.Normalized();
					diff.x /= distance;
					diff.y /= distance;
				}
				steer += diff;
				count++;
			}
		}
	}

	if (count > 0)
	{
		steer.x /= (float)count;
		steer.y /= (float)count;
	}

	if (steer.Length() > 0)
	{
		steer = steer.Normalized();
		steer *= m_MovementSpeed;
		Vector2 DirectionCopy = Vector2(m_CurrentDirection.x, m_CurrentDirection.z);
		steer -= DirectionCopy;

		if (steer.Length() >= m_maxforce)
		{
			steer *= (m_maxforce / steer.Length());
		}
	}

	return Vector3(steer.x, 0, steer.y);
}
开发者ID:pongtato,项目名称:AI_ASGN2,代码行数:49,代码来源:FSM.cpp

示例2: Update

void PlayerArrow::Update()
{
	// アングル
	Vector3 playerFront = Vector3(player->GetParameter().mat.GetFront() * Vector3(1, 0, 1)).Normalized();
	if (playerFront.Length() != 0)
	{
		angle_ = Vector3::Inner(playerFront, -Vector3::Forward);
		if (Vector3::Dot(playerFront, Vector3::Left) > 0.0f)
			angle_ *= -1;
	}

	/* プレイヤーデータ */
	// ポジション
	Vector3 playerPos = player->GetParameter().mat.GetPosition();
	Vector2 pos = Vector2(playerPos.x, -playerPos.z);
	if (pos.Length() != 0.0f)
		drawPos_ = MAP_DRAW_POSITION + pos.Normalized() * pos.Length() * RE_SIZE_SCALE;
	else
		drawPos_ = MAP_DRAW_POSITION;

	/* 気流発生 */
	isDash = player->ReturnTackleParameter().dashFlag;
	if (isDash && isDash != prevDash)
		world.UIAdd(UI_ID::FLOWROOT_UI, std::make_shared<FlowRoot>(world, player, &drawPos_, resPiece));
	prevDash = isDash;
}
开发者ID:Jimendaisuki,项目名称:RideTheFlow,代码行数:26,代码来源:PlayerArrow.cpp

示例3: Update

void WanderBehaviour::Update(Agent* a_agent)
{
	Vector2 randomTargetOnCircle;

	if (/*a_agent->WanderTargetCalculated == false*/ true)
	{
		float randomDeg = rand() % 360;
		float randomRadian = randomDeg * PI / 180.0f;

		randomTargetOnCircle =  Vector2(cos(randomRadian), sin(randomRadian));
		randomTargetOnCircle = randomTargetOnCircle * wanderRadius;
	}
	else
	{
		//randomTargetOnCircle = a_agent->prevWanderTarget;
	}
	

	
	//Jitter Vector
    float randomDeg = rand() % 360;
	float randomRadian = randomDeg * PI / 180.0f;
	

	Vector2 jitterVector(cos(randomRadian), sin(randomRadian));
	jitterVector = jitterVector * jitterAmount;

	// Add jitter vector to target vector
	randomTargetOnCircle += jitterVector;
	// Bring target back to circle
	randomTargetOnCircle = randomTargetOnCircle.Normalized() * wanderDistance;

	//Add agent heading * wanderdist
	randomTargetOnCircle;


	//a_agent->prevWanderTarget = randomTargetOnCircle;

	randomTargetOnCircle += a_agent->GetPosition();

	//calculate seek force
	Vector2 vecBetween = randomTargetOnCircle - a_agent->GetPosition();
	Vector2 force = vecBetween.Normalized() * a_agent->m_maxVelocity;
	
	//Add force to agent
	a_agent->AddForce(force - a_agent->m_velocity);
}
开发者ID:ba-ph,项目名称:AIE-AI-Assignment,代码行数:47,代码来源:WanderBehaviour.cpp

示例4: Execute

void SeekAction::Execute(Agent * a_agent)
{
	//calculate force vector
	Vector2 vecBetweenAgentTarget = a_agent->GetTarget() - a_agent->GetPosition();
	Vector2 force = vecBetweenAgentTarget.Normalized() * a_agent->m_maxVelocity;

	//Add the force
	a_agent->AddForce(force - a_agent->m_velocity);
}
开发者ID:ba-ph,项目名称:AIE-AI-Assignment,代码行数:9,代码来源:SeekAction.cpp

示例5: GetPath

Vector2 Wave::GetPath(Vector2 start, Vector2 end, float speed)
{
	if (start == end)
		return Vector2(0, 0);
	
	Vector2 up(0, 1);
	return Vector2(speed, sin(up.AngleBetween((start.Normalized()))) * speed);

}
开发者ID:DreamNex,项目名称:SP4_Moyase,代码行数:9,代码来源:Wave.cpp

示例6: ObjectClicked

void ClickTargetSystem::ObjectClicked(Pocket::TouchData d) {
    if (d.Index != 1) return;
    
    std::vector<GameObject*> objectsToMove;
    for(auto o : selectables->Objects()) {
        if (!o->GetComponent<Selectable>()->Selected()) continue;
        objectsToMove.push_back(o);
       // o->GetComponent<Movable>()->Target = {d.WorldPosition.x, d.WorldPosition.z };
    }
    if (objectsToMove.empty()) return;
    
    Vector2 target = { d.WorldPosition.x, d.WorldPosition.z };
    Vector2 centerPoint = 0;
    for(GameObject* go : objectsToMove) {
        centerPoint += go->GetComponent<Particle>()->position;
    }
    centerPoint *= (1.0f / objectsToMove.size());
    std::vector<Vector2> targets;
    for(GameObject* go : objectsToMove) {
        Vector2 fromCenterPoint = go->GetComponent<Particle>()->position - centerPoint;
        targets.push_back(target + fromCenterPoint.Normalized());
    }
    
    
    for (int iterations=0; iterations<10; iterations++) {
    
        for (int i=0; i<objectsToMove.size(); i++) {
            //Particle* a = objectsToMove[i]->GetComponent<Particle>();
            Vector2& targetA = targets[i];
        
            for (int j=i+1; j<objectsToMove.size(); j++) {
                //Particle* b = objectsToMove[i]->GetComponent<Particle>();
                Vector2& targetB = targets[j];
                const float radius = 2.0f;
                
                Vector2 vector = targetB - targetA;
                float length = vector.Length();
                if (length<radius) {
                    vector *= (1.0f / length);
                    float penetration = radius - length;
                    targetA -= vector * penetration * 0.5f;
                    targetB += vector * penetration * 0.5f;
                }
            }
        }
        /*
        for (int i=0; i<objectsToMove.size(); i++) {
            targets[i] = objectsToMove[i]->GetComponent<Mappable>()->Map->FindNearestValidPosition(targets[i]);
        }
        */
    }
    
    for (int i=0; i<objectsToMove.size(); i++) {
        objectsToMove[i]->GetComponent<Movable>()->Target = targets[i];
    }
}
开发者ID:JeppeNielsen,项目名称:PocketEngine,代码行数:56,代码来源:ClickTargetSystem.cpp

示例7:

Vector2 Vector2::MoveToPoint(Vector2 pos, Vector2 destination, float movement)
{
	if (pos == destination)
	{
		return pos;
	}
	Vector2 relative = (destination - pos);
	float distance = relative.Length();
	if (distance < movement)
	{
		// Reach destination
		return destination;
	}
	else
	{
		return pos + relative.Normalized() * movement;
	}
}
开发者ID:NothingMuch123,项目名称:Multiplayer-Assignment-2,代码行数:18,代码来源:Vector2.cpp

示例8: ComputeAlignment

Vector3 CFSM::ComputeAlignment(vector<CFSM*> ListOfCharacters)
{
	Vector2 sum;
	int count = 0;

	for (int i = 0; i < ListOfCharacters.size(); ++i)
	{
		if (ListOfCharacters[i] != this && ListOfCharacters[i]->GetAlive())
			//if (ListOfCharacters[i] != this && ListOfCharacters[i]->TYPE != "BOSS")
		{
			float distance = (m_CurrentPosition - ListOfCharacters[i]->GetPosition()).Length();
			if (distance < m_flockZone)
			{
				Vector2 VelCopy = Vector2(ListOfCharacters[i]->GetCurrentDirection().x, ListOfCharacters[i]->GetCurrentDirection().z);
				sum += VelCopy;
				count++;
			}
		}
	}

	if (count > 0)
	{
		sum.x /= (float)count;
		sum.y /= (float)count;
		if (!sum.IsZero())
		{
			sum = sum.Normalized();
			sum *= m_MovementSpeed;
		}
		Vector2 DirectionCopy = Vector2(m_CurrentDirection.x, m_CurrentDirection.z);
		Vector2 steer = sum - DirectionCopy;

		if (steer.Length() >= m_maxforce)
		{
			steer *= (m_maxforce / steer.Length());
		}
		return Vector3(steer.x, 0, steer.y);

	}
	else
	{
		return Vector3(0, 0, 0);
	}
}
开发者ID:pongtato,项目名称:AI_ASGN2,代码行数:44,代码来源:FSM.cpp

示例9: seek

Vector2 CFSM::seek(Vector2 target)
{
	Vector2 PositionCopy = Vector2(m_CurrentPosition.x, m_CurrentPosition.z);
	Vector2 direction = target - PositionCopy;
	if (!direction.IsZero())
	{
		direction = direction.Normalized();
		direction *= m_MovementSpeed;
	}

	Vector2 DirectionCopy = Vector2(m_CurrentDirection.x, m_CurrentDirection.z);
	Vector2 steer = direction - DirectionCopy;

	if (steer.Length() >= m_maxforce)
	{
		steer *= (m_maxforce / steer.Length());
	}

	return steer;
}
开发者ID:pongtato,项目名称:AI_ASGN2,代码行数:20,代码来源:FSM.cpp

示例10: AddForces

void Fluid::AddForces(const Vector2& position, const Vector2& direction, 
                      float sigma, float amplitude,
                      View2f* velocities) const {
  if (direction.LengthSquared() < 1e-4f) {
    return AddForces(position, sigma, amplitude, velocities);
  }
  
  const int x = std::lroundf(position.x * Width());
  const int y = std::lroundf((1.0f - position.y) * Height());
  const int radius = std::lround(3.3f * sigma);
  const Vector2 dn = direction.Normalized();
  const float sigmaSq = sigma * sigma;
  for (int j = y - radius; j <= y + radius; ++j) {
    for (int i = x - radius; i <= x + radius; ++i) {
      const int s = i - x;
      const int t = y - j;  // Flips at y-axis.
      const float e = amplitude * std::exp(-(0.5f / sigmaSq) * (s * s + t * t));
      AddValue(i, j, e * dn, velocities);
    }
  }
}
开发者ID:ingo2,项目名称:gargleblaster,代码行数:21,代码来源:Fluid.cpp

示例11: FindCollideNormal

/*************************************************************************************************************
	AFTER-COLLISION EFFECT : Change Variables after Collision
*************************************************************************************************************/
bool CollisionHandler::FindCollideNormal(Box* b1, Vector2 origin)
{
	Vector2 up(0, 1);
	Vector2 down(0, -1);
	Vector2 right(1, 0);
	Vector2 left(-1, 0);
	Vector2 max = b1->GetOrigin() + Vector2(b1->GetWidth() / 2, b1->GetHeight() / 2);
	Vector2 dir = (origin - b1->GetOrigin());

	if ((origin - b1->GetOrigin()).IsZero())
	{
		b1->SetCollideNormal(Vector2(0, 1));
		return true;
	}
	else
		dir = dir.Normalized();

	if ((max - b1->GetOrigin()).IsZero())
	{
		b1->SetCollideNormal((dir.unary()));
		return true;
	}
	float horizontalDotLimit = right.Dot((max - b1->GetOrigin()).Normalized());
	float verticalDotLimit = up.Dot((max - b1->GetOrigin()).Normalized());

	if (up.Dot(dir) > verticalDotLimit && up.Dot(dir) < 1)//Up
		b1->SetCollideNormal(up);
	else if (down.Dot(dir) > verticalDotLimit && down.Dot(dir) < 1)//Down
		b1->SetCollideNormal(down);
	else if (right.Dot(dir) > horizontalDotLimit && right.Dot(dir) < 1)//Right
		b1->SetCollideNormal(right);
	else if (left.Dot(dir) > horizontalDotLimit && left.Dot(dir) < 1)//Left
		b1->SetCollideNormal(left);
	else //Corner
		b1->SetCollideNormal((dir.unary()));

	return true;
}
开发者ID:DreamNex,项目名称:SP4_Moyase,代码行数:41,代码来源:CollisionHandler.cpp

示例12: BruteForceVoronoi

void MainWindow::BruteForceVoronoi()
{
  vector<Edge> halfPlanes;
  for (int i = 0; i < points.size(); i++)
  {
    halfPlanes.clear();
    for (int j = 0; j < points.size(); j++)
    {
      if (i == j)
      {
        continue;
      }
      Vector2 center = (points[i] + points[j]) * 0.5f;
      Vector2 perp = (points[i] - points[j]).GetPerpendicular();
      if (perp.Length() == 0.0f)
      {
        continue;
      }
      Vector2 n = perp.Normalized();
      halfPlanes.push_back(Edge(center - n * 50.0f, center + n * 50.0f));
    }

    vector<Vector2> isectPoints;
    for (int k = 0; k < halfPlanes.size(); k++)
    {
      for (int l = k + 1; l < halfPlanes.size(); l++)
      {
        Vector2 r(0.0f, 0.0f);
        if (IntersectLines(halfPlanes[k].p0, halfPlanes[k].p1
                         , halfPlanes[l].p0, halfPlanes[l].p1
                         , r))
        {
          bool inside = true;
          for (int j = 0; j < halfPlanes.size(); j++)
          {
            if (j == k || j == l)
            {
              continue;
            }
            if (HalfPlaneSign(halfPlanes[j].p0, halfPlanes[j].p1, points[i]) *
                HalfPlaneSign(halfPlanes[j].p0, halfPlanes[j].p1, r) <= 0.0f)
            {
              inside = false;
            }
          }
          if (inside)
          {
            isectPoints.push_back(r);
          }
        }
      }
    }

    CalcConvexHull(isectPoints);
    for (int j = 0; j < isectPoints.size(); j++)
    {
//      gIsectPoints.push_back(isectPoints[j]);
      edges.push_back(Edge(isectPoints[j], isectPoints[(j + 1) % isectPoints.size()]));
    }

  }
}
开发者ID:rotanov,项目名称:way-station,代码行数:62,代码来源:MainWindow.cpp


注:本文中的Vector2::Normalized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。