void
ctCameraScript_LooseLead::Update( float timeStep )
{
	float delta = m_targetPosition.x - m_position.x;
	
	if ( vsFabs(delta) > 4.f )
	{
		m_following = true;
	}
	
	if ( m_following )
	{
		vsVector2D predictedPosition = m_targetPosition;
		predictedPosition.x += ctPlayer::Instance()->GetVelocity().x * 2.f;
		m_spring.SetCenter( predictedPosition );
		
		if ( vsFabs(ctPlayer::Instance()->GetVelocity().x) <= 0.f )
		{
			m_following = false;
		}
	}
	else
	{
		m_spring.SetCenter( m_position );
	}
	
	m_position = m_spring.Update( timeStep );
}
Beispiel #2
0
float
vsVector2D::ApproximateLength() const
{
	const float factor = (1.0f + 1.0f/(4.0f-2.0f*SQRT_TWO))/2.0f;

	float ax = vsFabs(x);
	float ay = vsFabs(y);

	return factor * vsMin((1.0f / SQRT_TWO)*(ax+ay), vsMax(ax, ay));
}
void
astPlayerShip::HandleSpawnTimer( float timeStep )
{
	m_timeSinceSpawn += timeStep;

	const float c_invulnerableTime = 3.0f;	// three seconds of invulnerability

	if ( m_spawnInvulnerable )
	{
		float scale = 1.0f;
		vsColor c = vsColor::Blue;
		if ( m_timeSinceSpawn > c_invulnerableTime )
		{
			SetCollisionsActive(true);
			m_spawnInvulnerable = false;
		}
		else if ( m_timeSinceSpawn > 2.0f )
		{
			float frac = (m_timeSinceSpawn - 2.0f);

			float theta = frac * TWOPI;
			float pulseAmt = vsFabs(vsSin(theta));

			c = vsInterpolate(pulseAmt, vsColor::LightBlue, vsColor::White);
		}
		else if ( m_timeSinceSpawn > 1.0f )
		{
			float frac = (m_timeSinceSpawn - 1.0f);

			float theta = frac * TWOPI;
			float pulseAmt = vsFabs(vsSin(theta));

			c = vsInterpolate(pulseAmt, vsColor::LightBlue, vsColor::White);
		}
		else
		{
			c = vsInterpolate(m_timeSinceSpawn, vsColor::Black, vsColor::LightBlue);
		}

		const float c_scaleTime = 3.0f;
		if ( m_timeSinceSpawn < c_scaleTime )
		{
			float frac = m_timeSinceSpawn / c_scaleTime;
			frac = 1.0f - ((frac-1.f) * (frac-1.f));									// slam in, ease out
			//frac = (3.0f * frac * frac) - (2.0f * frac * frac * frac);			// ease in, ease out

			scale = vsInterpolate( frac, 5.0f, 1.0f );
		}

		SetColor(c);
		m_transform.SetScale( vsVector2D(scale,scale) );
	}
}
Beispiel #4
0
float
vsSpline3D::ClosestTimeTo( const vsVector3D& position )
{
	//lastBestT is a composite value;
	//the whole part is the "before" knot, and the fraction
	//is the 't' for that segment.

	float lastBestT = 0.5f;
	float lastMove = 1.f;
	float scale = 0.75f;
	vsVector3D lastBestPoint;
	vsVector3D lastBestTangent;
	int iterations = 0;

	while ( lastMove > 0.0001f )
	{
		lastBestPoint = PositionAtTime(lastBestT);
		lastBestTangent = VelocityAtTime(lastBestT);

		vsVector3D delta = position - lastBestPoint;
		float move = lastBestTangent.Dot(delta) / lastBestTangent.SqLength();

		move = vsClamp(move, -lastMove*scale, lastMove*scale);
		lastBestT = vsClamp( lastBestT+move, 0.f, 1.f );
		lastMove = vsFabs(move);
		iterations++;
	}
	return lastBestT;
}