Example #1
0
//-----------------------------------------------------------------------------
// Purpose: Think function. Accelerates a func_rotating to a higher angular velocity.
//-----------------------------------------------------------------------------
void CFuncRotating::SpinUpMove( void )
{
	//
	// Calculate our new speed.
	//
	bool bSpinUpDone = false;
	float flNewSpeed = fabs( m_flSpeed ) + 0.2 * m_flMaxSpeed * m_flFanFriction;
	if ( fabs( flNewSpeed ) >=  fabs( m_flTargetSpeed ) )
	{
		// Reached our target speed.
		flNewSpeed = m_flTargetSpeed;
		bSpinUpDone = !m_bStopAtStartPos;
	}
	else if ( m_flTargetSpeed < 0 )
	{
		// Spinning up in reverse - negate the speed.
		flNewSpeed *= -1;
	}

	//
	// Apply the new speed, adjust sound pitch and volume.
	//
	UpdateSpeed( flNewSpeed );

	//
	// If we've met or exceeded target speed, stop spinning up.
	//
	if ( bSpinUpDone )
	{
		SetMoveDone( &CFuncRotating::RotateMove );
		RotateMove();
	} 

	SetMoveDoneTime( GetNextMoveInterval() );
}
Example #2
0
//-----------------------------------------------------------------------------
// Purpose: Sets a new angular velocity to achieve.
// Input  : flSpeed - Target angular velocity in degrees per second.
//-----------------------------------------------------------------------------
void CFuncRotating::SetTargetSpeed( float flSpeed )
{
	//
	// Make sure the sign is correct - positive for forward rotation,
	// negative for reverse rotation.
	//
	flSpeed = fabs( flSpeed );
	if ( m_bReversed )
	{
		flSpeed *= -1;
	}

	m_flTargetSpeed = flSpeed;

	//
	// If we don't accelerate, change to the new speed instantly.
	//
	if ( !HasSpawnFlags(SF_BRUSH_ACCDCC ) )
	{
		UpdateSpeed( m_flTargetSpeed );
		SetMoveDone( &CFuncRotating::RotateMove );
	}
	//
	// Otherwise deal with acceleration/deceleration:
	//
	else
	{
		//
		// Check for reversing directions.
		//
		if ((( m_flSpeed > 0 ) && ( m_flTargetSpeed < 0 )) || 
			(( m_flSpeed < 0 ) && ( m_flTargetSpeed > 0 )))
		{
			SetMoveDone( &CFuncRotating::ReverseMove );
		}
		//
		// If we are below the new target speed, spin up to the target speed.
		//
		else if ( fabs( m_flSpeed ) < fabs( m_flTargetSpeed ) )
		{
			SetMoveDone( &CFuncRotating::SpinUpMove );
		}
		//
		// If we are above the new target speed, spin down to the target speed.
		//
		else if ( fabs( m_flSpeed ) > fabs( m_flTargetSpeed ) )
		{
			SetMoveDone( &CFuncRotating::SpinDownMove );
		}
		//
		// We are already at the new target speed. Just keep rotating.
		//
		else
		{
			SetMoveDone( &CFuncRotating::RotateMove );
		}
	}

	SetMoveDoneTime( GetNextMoveInterval() );
}
Example #3
0
//
// SpinUp - accelerates a non-moving func_rotating up to it's speed
//
void CFuncRotating :: SpinUp( void )
{
	// calculate our new speed.
	float flNewSpeed = fabs( pev->speed ) + 0.2f * m_flMaxSpeed * m_flFanFriction;
	bool bSpinUpDone = false;

	if( fabs( flNewSpeed ) >= fabs( m_flTargetSpeed ))
	{
		// Reached our target speed.
		flNewSpeed = m_flTargetSpeed;
		bSpinUpDone = !m_bStopAtStartPos;
	}
	else if( m_flTargetSpeed < 0 )
	{
		// spinning up in reverse - negate the speed.
		flNewSpeed *= -1;
	}

	m_iState = STATE_TURN_ON;

	// Apply the new speed, adjust sound pitch and volume.
	UpdateSpeed( flNewSpeed );

	// If we've met or exceeded target speed, stop spinning up.
	if( bSpinUpDone )
	{
		SetMoveDone( Rotate );
		Rotate();
	} 

	SetMoveDoneTime( GetNextMoveInterval() );
}
Example #4
0
//-----------------------------------------------------------------------------
// Purpose: Think function. Called while rotating at a constant angular velocity.
//-----------------------------------------------------------------------------
void CFuncRotating::RotateMove( void )
{
	SetMoveDoneTime( 10 );

	if ( m_bStopAtStartPos )
	{
		SetMoveDoneTime( GetNextMoveInterval() );
		int checkAxis = 2;

		// See if we got close to the starting orientation
		if ( m_vecMoveAng[0] != 0 )
		{
			checkAxis = 0;
		}
		else if ( m_vecMoveAng[1] != 0 )
		{
			checkAxis = 1;
		}

		float angDelta = anglemod( GetLocalAngles()[ checkAxis ] - m_angStart[ checkAxis ] );
		if ( angDelta > 180.0f )
			angDelta -= 360.0f;

		QAngle avel = GetLocalAngularVelocity();
		// Delta per tick
		QAngle avelpertick = avel * TICK_INTERVAL;

		if ( fabs( angDelta ) < fabs( avelpertick[ checkAxis ] ) )
		{
			SetTargetSpeed( 0 );
			SetLocalAngles( m_angStart );
			m_bStopAtStartPos = false;
		}
	}
}
Example #5
0
//-----------------------------------------------------------------------------
// Purpose: Think function for reversing directions. Spins down to zero, then
//			starts spinning up to the target speed.
//-----------------------------------------------------------------------------
void CFuncRotating::ReverseMove( void )
{
	if ( SpinDown( 0 ) )
	{
		// We've reached zero - spin back up to the target speed.
		SetTargetSpeed( m_flTargetSpeed );
	}
	else
	{
		SetMoveDoneTime( GetNextMoveInterval() );
	}
}
Example #6
0
void CFuncRotating::SetTargetSpeed( float flSpeed )
{
	if( flSpeed == 0.0f && FBitSet( pev->spawnflags, SF_ROTATING_STOP_AT_START_POS ))
		m_bStopAtStartPos = true;

	// make sure the sign is correct - positive for forward rotation,
	// negative for reverse rotation.
	flSpeed = fabs( flSpeed );

	if( pev->impulse )
	{
		flSpeed *= -1;
	}

	m_flTargetSpeed = flSpeed;
	pev->friction = 0.0f; // clear impulse friction

	// If we don't accelerate, change to the new speed instantly.
	if( !FBitSet( pev->spawnflags, SF_ROTATING_ACCDCC ))
	{
		UpdateSpeed( m_flTargetSpeed );
		SetMoveDone( Rotate );
	}
	else
	{
		// Otherwise deal with acceleration/deceleration:
		if((( pev->speed > 0 ) && ( m_flTargetSpeed < 0 )) || (( pev->speed < 0 ) && ( m_flTargetSpeed > 0 )))
		{
			// check for reversing directions.
			SetMoveDone( ReverseMove );
		}
		else if( fabs( pev->speed ) < fabs( m_flTargetSpeed ))
		{
			// If we are below the new target speed, spin up to the target speed.
			SetMoveDone( SpinUp );
		}
		else if( fabs( pev->speed ) > fabs( m_flTargetSpeed ))
		{
			// If we are above the new target speed, spin down to the target speed.
			SetMoveDone( SpinDown );
		}
		else
		{
			// we are already at the new target speed. Just keep rotating.
			SetMoveDone( Rotate );
		}
	}

	SetMoveDoneTime( GetNextMoveInterval() );
}
Example #7
0
//-----------------------------------------------------------------------------
// Purpose: Think function. Decelerates a func_rotating to a lower angular velocity.
//-----------------------------------------------------------------------------
void CFuncRotating::SpinDownMove( void )
{
	//
	// If we've met or exceeded target speed, stop spinning down.
	//
	if ( SpinDown( m_flTargetSpeed ) )
	{
		SetMoveDone( &CFuncRotating::RotateMove );
		RotateMove();
	}
	else
	{
		SetMoveDoneTime( GetNextMoveInterval() );
	}
}
Example #8
0
//
// SpinDown - decelerates a moving func_rotating to a standstill.
//
void CFuncRotating :: SpinDown( void )
{
	// If we've met or exceeded target speed, stop spinning down.
	if( SpinDown( m_flTargetSpeed ))
	{
		if( m_iState != STATE_OFF )
		{
			SetMoveDone( Rotate );
			Rotate();
		}
	}
	else
	{
		SetMoveDoneTime( GetNextMoveInterval() );
	}
}
Example #9
0
void CFuncRotating :: Rotate( void )
{
	// NOTE: only full speed moving set state to "On"
	if( fabs( pev->speed ) == fabs( m_flMaxSpeed ))
		m_iState = STATE_ON;

	SetMoveDoneTime( 0.1f );

	if( m_bStopAtStartPos )
	{
		SetMoveDoneTime( GetNextMoveInterval() );

		int checkAxis = 2;

		// see if we got close to the starting orientation
		if( pev->movedir[0] != 0 )
		{
			checkAxis = 0;
		}
		else if( pev->movedir[1] != 0 )
		{
			checkAxis = 1;
		}

		float angDelta = anglemod( GetLocalAngles()[checkAxis] - m_angStart[checkAxis] );
		if( angDelta > 180.0f )
			angDelta -= 360.0f;

		Vector avel = GetLocalAvelocity();

		// delta per tick
		Vector avelpertick = avel * gpGlobals->frametime;

		if( fabs( angDelta ) < fabs( avelpertick[checkAxis] ))
		{
			SetTargetSpeed( 0 );
			SetLocalAngles( m_angStart );
			m_bStopAtStartPos = false;
		}
	}
}
Example #10
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &inputdata - 
//-----------------------------------------------------------------------------
void CFuncRotating::InputStopAtStartPos( inputdata_t &inputdata )
{
	m_bStopAtStartPos = true;
	SetTargetSpeed( 0 );
	SetMoveDoneTime( GetNextMoveInterval() );
}