コード例 #1
0
Vector2D SteeringBehavior::Wander() {
  // This behavior is dependent on the update rate, so this line must
  // be included when using time independent framerate.
  unsigned int JitterThisTimeSlice = m_dWanderJitter * vehicle_->TimeElapsed();

  // First, add a small random vector to the target's position
  m_vWanderTarget += Vector2D(RandomClamped() * JitterThisTimeSlice,
    RandomClamped() * JitterThisTimeSlice);

  // Reproject this new vector back on to a unit circle
  m_vWanderTarget.Normalize();

  // Increase the length of the vector to the same as the radius
  // of the wander circle
  m_vWanderTarget *= m_dWanderRadius;

  // Move the target into a position WanderDist in front of the agent
  Vector2D target = m_vWanderTarget + Vector2D(m_dWanderDistance, 0);

  // Project the target into world space
  Vector2D Target = PointToWorldSpace(target,
    vehicle_->Heading(),
    vehicle_->Side(),
    vehicle_->Position());

  // And steer towards it
  return Target - vehicle_->Position();
}
コード例 #2
0
//--------------------------- Wander -------------------------------------
//
//  This behavior makes the agent wander about randomly
//------------------------------------------------------------------------
Vector2D SteeringBehavior::Wander(float dt)
{ 
	//this behavior is dependent on the update rate, so this line must
	//be included when using time independent framerate.
	double JitterThisTimeSlice = WanderJitterPerSec * dt;

	//first, add a small random vector to the target's position
	m_vWanderTarget += Vector2D(RandomClamped() * JitterThisTimeSlice,
		RandomClamped() * JitterThisTimeSlice);

	//reproject this new vector back on to a unit circle
	m_vWanderTarget.Normalize();

	//increase the length of the vector to the same as the radius
	//of the wander circle
	m_vWanderTarget *= WanderRad;

	//move the target into a position WanderDist in front of the agent
	Vector2D target = m_vWanderTarget + Vector2D(WanderDist, 0);

	//project the target into world space
	Vector2D Target = PointToWorldSpace(target,
		m_pMovingEntity->Heading(),
		m_pMovingEntity->Pos());

	//and steer towards it
	Vector2D Origin = m_pMovingEntity->Pos();
	Vector2D Ret = Target - Origin;

	return Ret;
}
Vector2D B020612E_Steering::Wander()
{
	float timeElapsed = 0.0;
	timeElapsed += _pTank->GetElapsedTime();
	double jitterTime = _pWanderJitter * timeElapsed;

	_pWanderTarget += Vector2D(RandomClamped() * jitterTime, RandomClamped() * jitterTime);
	_pWanderTarget.Normalize();
	_pWanderTarget *= _pWanderRadius;

	Vector2D target = _pWanderTarget + Vector2D(_pWanderDistance, 0);
	Vector2D targetWS = PointToWorldSpace(target, _pTank->GetHeading(), _pTank->GetSide(), _pTank->GetCentrePosition());

	return targetWS - _pTank->GetCentrePosition();
}
コード例 #4
0
//------------------------- Offset Pursuit -------------------------------
//
//  Produces a steering force that keeps a MovingEntity at a specified offset
//  from a leader MovingEntity
//------------------------------------------------------------------------
Vector2D SteeringBehavior::OffsetPursuit(const MovingEntity*  leader,
	const float offset)
{
	Vector2D displacement = leader->Heading() * - offset;

	//calculate the offset's position in world space
	Vector2D WorldOffsetPos = PointToWorldSpace(displacement,
		leader->Heading(),
		leader->Pos());

	Vector2D ToOffset = WorldOffsetPos - m_pMovingEntity->Pos();

	//the lookahead time is propotional to the distance between the leader
	//and the pursuer; and is inversely proportional to the sum of both
	//agent's velocities
	double LookAheadTime = ToOffset.Length() / 
		(m_pMovingEntity->MaxSpeed() + leader->Speed());

	//now Arrive at the predicted future position of the offset
	return Arrive(WorldOffsetPos + leader->Velocity() * LookAheadTime, fast);
}
コード例 #5
0
ファイル: TikiSteering.cpp プロジェクト: IreNox/tiki2
		Vector2 TikiSteering::Wander()
		{
			// first, add a small random vector to the target's position
			wanderTarget += Vector2(RandomClamped() * wanderJitter,
									RandomClamped() * wanderJitter);

			// reproject this TIKI_NEW vector back on to a unit circle
			wanderTarget.Normalize();

			// increase the length of the vector to the same as the radius of the wander circle
			wanderTarget = wanderTarget * wanderRadius;

			// move the target into a position WanderDist in front of the agent
			Vector2 theTarget = wanderTarget + Vector2(wanderDistance, 0);

			// project the target into world space
			Vector2 projectedTarget = PointToWorldSpace(theTarget, 
														tikiBot->Heading(),
														tikiBot->Side(),
														tikiBot->Pos());
			//and steer towards it
			return projectedTarget - tikiBot->Pos();
		}