//------------------------------------------------------------------------------ // Purpose: MoveDone function for the SetPosition input handler. Tracks our // progress toward a movement goal and updates our outputs. //------------------------------------------------------------------------------ void CMomentaryRotButton::SetPositionMoveDone(void) { float flCurPos = GetPos( GetLocalAngles() ); if ((( flCurPos >= m_IdealYaw ) && ( m_direction == 1 )) || (( flCurPos <= m_IdealYaw ) && ( m_direction == -1 ))) { // // We reached or surpassed our movement goal. // SetLocalAngularVelocity( vec3_angle ); // BUGBUG: Won't this get the player stuck? SetLocalAngles( m_start + m_vecMoveAng * ( m_IdealYaw * m_flMoveDistance ) ); SetNextThink( TICK_NEVER_THINK ); SetMoveDoneTime( -1 ); UpdateTarget( m_IdealYaw, this ); OutputMovementComplete(); return; } // TODO: change this to use a Think function like ReturnThink. QAngle vecNewAngles = m_start + m_vecMoveAng * ( m_IdealYaw * m_flMoveDistance ); float flAngleDelta = fabs( AxisDelta( m_spawnflags, vecNewAngles, GetLocalAngles() )); float dt = flAngleDelta / m_flSpeed; if ( dt < TICK_INTERVAL ) { dt = TICK_INTERVAL; float speed = flAngleDelta / TICK_INTERVAL; SetLocalAngularVelocity( speed * m_vecMoveAng * m_direction ); } dt = clamp( dt, TICK_INTERVAL, TICK_INTERVAL * 6); SetMoveDoneTime( dt ); }
void CMomentaryRotButton :: SetPosition( float value ) { pev->ideal_yaw = bound( 0.0f, value, 1 ); float flCurPos = GetPos( GetLocalAngles( )); if( flCurPos < pev->ideal_yaw ) { // moving forward (from start to end). SetLocalAvelocity( pev->speed * pev->movedir ); m_direction = 1; } else if( flCurPos > pev->ideal_yaw ) { // moving backward (from end to start). SetLocalAvelocity( -pev->speed * pev->movedir ); m_direction = -1; } else { // we're there already; nothing to do. SetLocalAvelocity( g_vecZero ); return; } // g-cont. to avoid moving by user in back direction if( FBitSet( pev->spawnflags, SF_MOMENTARY_ROT_BUTTON_AUTO_RETURN ) && m_returnSpeed > 0 ) m_lastUsed = 1; // play sound on set new pos PlaySound(); SetMoveDone( &CMomentaryRotButton::SetPositionMoveDone ); SetThink( &CMomentaryRotButton::UpdateThink ); SetNextThink( 0 ); // Think again in 0.1 seconds or the time that it will take us to reach our movement goal, // whichever is the shorter interval. This prevents us from overshooting and stuttering when we // are told to change position in very small increments. Vector vecNewAngles = m_start + pev->movedir * ( pev->ideal_yaw * m_flMoveDistance ); float flAngleDelta = fabs( AxisDelta( pev->spawnflags, vecNewAngles, GetLocalAngles( ))); float dt = flAngleDelta / pev->speed; if( dt < gpGlobals->frametime ) { dt = gpGlobals->frametime; float speed = flAngleDelta / gpGlobals->frametime; SetLocalAvelocity( speed * pev->movedir * m_direction ); } dt = bound( gpGlobals->frametime, dt, gpGlobals->frametime * 6 ); SetMoveDoneTime( dt ); }
float CMomentaryRotButton::GetPos( const Vector &vecAngles ) { float flScale; if(( pev->movedir.x < 0 ) || ( pev->movedir.y < 0 ) || ( pev->movedir.z < 0 )) flScale = -1; else flScale = 1; float flPos = flScale * AxisDelta( pev->spawnflags, vecAngles, m_start ) / m_flMoveDistance; return bound( 0.0f, flPos, 1.0f ); }
//------------------------------------------------------------------------------ // Purpose : // Input : flPosition //------------------------------------------------------------------------------ void CMomentaryRotButton::InputSetPosition( inputdata_t &inputdata ) { m_IdealYaw = clamp( inputdata.value.Float(), 0, 1 ); float flCurPos = GetPos( GetLocalAngles() ); if ( flCurPos < m_IdealYaw ) { // Moving forward (from start to end). SetLocalAngularVelocity( m_flSpeed * m_vecMoveAng ); m_direction = 1; } else if ( flCurPos > m_IdealYaw ) { // Moving backward (from end to start). SetLocalAngularVelocity( -m_flSpeed * m_vecMoveAng ); m_direction = -1; } else { // We're there already; nothing to do. SetLocalAngularVelocity( vec3_angle ); return; } SetMoveDone( &CMomentaryRotButton::SetPositionMoveDone ); SetThink( &CMomentaryRotButton::UpdateThink ); SetNextThink( gpGlobals->curtime ); // // Think again in 0.1 seconds or the time that it will take us to reach our movement goal, // whichever is the shorter interval. This prevents us from overshooting and stuttering when we // are told to change position in very small increments. // QAngle vecNewAngles = m_start + m_vecMoveAng * ( m_IdealYaw * m_flMoveDistance ); float flAngleDelta = fabs( AxisDelta( m_spawnflags, vecNewAngles, GetLocalAngles() )); float dt = flAngleDelta / m_flSpeed; if ( dt < TICK_INTERVAL ) { dt = TICK_INTERVAL; float speed = flAngleDelta / TICK_INTERVAL; SetLocalAngularVelocity( speed * m_vecMoveAng * m_direction ); } dt = clamp( dt, TICK_INTERVAL, TICK_INTERVAL * 6); SetMoveDoneTime( dt ); }
void CMomentaryRotButton :: SetPositionMoveDone( void ) { float flCurPos = GetPos( GetLocalAngles( )); if((( flCurPos >= pev->ideal_yaw ) && ( m_direction == 1 )) || (( flCurPos <= pev->ideal_yaw ) && ( m_direction == -1 ))) { // g-cont. we need auto return after direct set position? if( FBitSet( pev->spawnflags, SF_MOMENTARY_ROT_BUTTON_AUTO_RETURN ) && m_returnSpeed > 0 ) { SetMoveDone( &CMomentaryRotButton::ReturnMoveDone ); m_direction = -1; if( flCurPos >= 1.0f ) { // disable use until button is waiting SetUse( NULL ); // delay before autoreturn. SetMoveDoneTime( m_flDelay + 0.1f ); } else SetMoveDoneTime( 0.1f ); } else { m_iState = STATE_OFF; // we reached or surpassed our movement goal. SetLocalAvelocity( g_vecZero ); // BUGBUG: Won't this get the player stuck? SetLocalAngles( m_start + pev->movedir * ( pev->ideal_yaw * m_flMoveDistance )); SetNextThink( -1 ); SetMoveDoneTime( -1 ); UpdateTarget( pev->ideal_yaw ); } m_lastUsed = 0; return; } // set right state if( flCurPos >= pev->ideal_yaw ) m_iState = STATE_TURN_OFF; if( flCurPos <= pev->ideal_yaw ) m_iState = STATE_TURN_ON; Vector vecNewAngles = m_start + pev->movedir * ( pev->ideal_yaw * m_flMoveDistance ); float flAngleDelta = fabs( AxisDelta( pev->spawnflags, vecNewAngles, GetLocalAngles( ))); float dt = flAngleDelta / pev->speed; if( dt < gpGlobals->frametime ) { dt = gpGlobals->frametime; float speed = flAngleDelta / gpGlobals->frametime; SetLocalAvelocity( speed * pev->movedir * m_direction ); } dt = bound( gpGlobals->frametime, dt, gpGlobals->frametime * 6 ); SetMoveDoneTime( dt ); }