float CBasePlayerAnimState::SetOuterBodyYaw( float flValue ) { int body_yaw = GetOuter()->LookupPoseParameter( "body_yaw" ); if ( body_yaw < 0 ) { return 0; } SetOuterPoseParameter( body_yaw, flValue ); return flValue; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPlayerAnimState::ComputePoseParam_BodyPitch( void ) { // Get pitch from v_angle float flPitch = m_flEyePitch; if ( flPitch > 180.0f ) { flPitch -= 360.0f; } flPitch = clamp( flPitch, -90, 90 ); m_angRender[YAW] = m_flEyeYaw; m_angRender[PITCH] = m_angRender[ROLL] = 0; // See if we have a blender for pitch int pitch = GetOuter()->LookupPoseParameter( "body_pitch" ); if ( pitch < 0 ) return; SetOuterPoseParameter( pitch, flPitch ); }
//----------------------------------------------------------------------------- // Purpose: Override for backpeddling // Input : dt - //----------------------------------------------------------------------------- void CPlayerAnimState::ComputePoseParam_MoveYaw() { int iYaw = GetOuter()->LookupPoseParameter( "move_yaw" ); if ( iYaw < 0 ) return; // view direction relative to movement float flYaw; EstimateYaw(); float ang = m_flEyeYaw; if ( ang > 180.0f ) { ang -= 360.0f; } else if ( ang < -180.0f ) { ang += 360.0f; } // calc side to side turning flYaw = ang - m_flGaitYaw; // Invert for mapping into 8way blend flYaw = -flYaw; flYaw = flYaw - (int)(flYaw / 360) * 360; if (flYaw < -180) { flYaw = flYaw + 360; } else if (flYaw > 180) { flYaw = flYaw - 360; } SetOuterPoseParameter( iYaw, flYaw ); }
void CPlayerAnimState::ComputePoseParam_BodyYaw() { // See if we even have a blender for pitch int upper_body_yaw = GetOuter()->LookupPoseParameter( "body_yaw" ); if ( upper_body_yaw < 0 ) { return; } // Assume upper and lower bodies are aligned and that we're not turning float flGoalTorsoYaw = 0.0f; int turning = TURN_NONE; float turnrate = tf2_feetyawrate.GetFloat(); Vector vel; GetOuterAbsVelocity( vel ); bool isMoving = ( vel.Length() > 0.1f ) ? true : false; if ( isMoving ) { m_flLastTurnTime = 0.0f; m_nTurningInPlace = TURN_NONE; m_flGoalFeetYaw = m_flEyeYaw; flGoalTorsoYaw = 0.0f; turning = ConvergeAngles( m_flGoalFeetYaw, turnrate, gpGlobals->frametime, m_flCurrentFeetYaw ); m_flCurrentTorsoYaw = m_flEyeYaw - m_flCurrentFeetYaw; } else { // Just stopped moving, try and clamp feet if ( m_flLastTurnTime <= 0.0f ) { m_flLastTurnTime = gpGlobals->curtime; m_flLastYaw = m_flEyeYaw; // Snap feet to be perfectly aligned with torso/eyes m_flGoalFeetYaw = m_flEyeYaw; m_flCurrentFeetYaw = m_flGoalFeetYaw; m_nTurningInPlace = TURN_NONE; } // If rotating in place, update stasis timer if ( m_flLastYaw != m_flEyeYaw ) { m_flLastTurnTime = gpGlobals->curtime; m_flLastYaw = m_flEyeYaw; } if ( m_flGoalFeetYaw != m_flCurrentFeetYaw ) { m_flLastTurnTime = gpGlobals->curtime; } turning = ConvergeAngles( m_flGoalFeetYaw, turnrate, gpGlobals->frametime, m_flCurrentFeetYaw ); // See how far off current feetyaw is from true yaw float yawdelta = m_flEyeYaw - m_flCurrentFeetYaw; yawdelta = AngleNormalize( yawdelta ); bool rotated_too_far = false; float yawmagnitude = fabs( yawdelta ); // If too far, then need to turn in place if ( yawmagnitude > MAX_TORSO_ANGLE ) { rotated_too_far = true; } // Standing still for a while, rotate feet around to face forward // Or rotated too far // FIXME: Play an in place turning animation if ( rotated_too_far || ( gpGlobals->curtime > m_flLastTurnTime + tf2_facefronttime.GetFloat() ) ) { m_flGoalFeetYaw = m_flEyeYaw; m_flLastTurnTime = gpGlobals->curtime; float yd = m_flCurrentFeetYaw - m_flGoalFeetYaw; if ( yd > 0 ) { m_nTurningInPlace = TURN_RIGHT; } else if ( yd < 0 ) { m_nTurningInPlace = TURN_LEFT; } else { m_nTurningInPlace = TURN_NONE; } turning = ConvergeAngles( m_flGoalFeetYaw, turnrate, gpGlobals->frametime, m_flCurrentFeetYaw ); yawdelta = m_flEyeYaw - m_flCurrentFeetYaw; } // Snap upper body into position since the delta is already smoothed for the feet flGoalTorsoYaw = yawdelta; m_flCurrentTorsoYaw = flGoalTorsoYaw; } if ( turning == TURN_NONE ) { m_nTurningInPlace = turning; } if ( m_nTurningInPlace != TURN_NONE ) { // If we're close to finishing the turn, then turn off the turning animation if ( fabs( m_flCurrentFeetYaw - m_flGoalFeetYaw ) < MIN_TURN_ANGLE_REQUIRING_TURN_ANIMATION ) { m_nTurningInPlace = TURN_NONE; } } // Counter rotate upper body as needed ConvergeAngles( flGoalTorsoYaw, turnrate, gpGlobals->frametime, m_flCurrentTorsoYaw ); // Rotate entire body into position m_angRender[YAW] = m_flCurrentFeetYaw; m_angRender[PITCH] = m_angRender[ROLL] = 0; SetOuterPoseParameter( upper_body_yaw, clamp( m_flCurrentTorsoYaw, -90.0f, 90.0f ) ); }