// asw - test always advancing the frames void C_ASW_Alien::ASWUpdateClientSideAnimation() { if ( GetSequence() != -1 ) { // latch old values //OnLatchInterpolatedVariables( LATCH_ANIMATION_VAR ); // move frame forward //FrameAdvance( 0.0f ); // 0 means to use the time we last advanced instead of a constant CStudioHdr *hdr = GetModelPtr(); float cyclerate = hdr ? GetSequenceCycleRate( hdr, GetSequence() ) : 1.0f; float addcycle = gpGlobals->frametime * cyclerate * m_flPlaybackRate; float flNewCycle = GetCycle() + addcycle; m_flAnimTime = gpGlobals->curtime; if ( (flNewCycle < 0.0f) || (flNewCycle >= 1.0f) ) { if (flNewCycle >= 1.0f) // asw ReachedEndOfSequence(); // asw if ( IsSequenceLooping( hdr, GetSequence() ) ) { flNewCycle -= (int)(flNewCycle); } else { flNewCycle = (flNewCycle < 0.0f) ? 0.0f : 1.0f; } } SetCycle( flNewCycle ); } }
unsigned int C_DynamicProp::ComputeClientSideAnimationFlags() { if ( GetSequence() != -1 ) { CStudioHdr *pStudioHdr = GetModelPtr(); if ( GetSequenceCycleRate(pStudioHdr, GetSequence()) != 0.0f ) { return BaseClass::ComputeClientSideAnimationFlags(); } } // no sequence or no cycle rate, don't do any per-frame calcs return 0; }
//----------------------------------------------------------------------------- // Purpose: // Output : //----------------------------------------------------------------------------- float CAnimating::GetInstantaneousVelocity( float flInterval ) { CStudioHdr *pstudiohdr = GetModelPtr( ); if (! pstudiohdr) return 0; // FIXME: someone needs to check for last frame, etc. float flNextCycle = GetCycle() + flInterval * GetSequenceCycleRate( GetSequence() ) * m_flPlaybackRate; Vector vecVelocity; Studio_SeqVelocity( pstudiohdr, GetSequence(), flNextCycle, GetPoseParameterArray(), vecVelocity ); vecVelocity *= m_flPlaybackRate; return vecVelocity.Length(); }
bool C_BaseViewModel::Interpolate( float currentTime ) { CStudioHdr *pStudioHdr = GetModelPtr(); // Make sure we reset our animation information if we've switch sequences UpdateAnimationParity(); bool bret = BaseClass::Interpolate( currentTime ); // Hack to extrapolate cycle counter for view model float elapsed_time = currentTime - m_flAnimTime; C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); // Predicted viewmodels have fixed up interval if ( GetPredictable() || IsClientCreated() ) { Assert( pPlayer ); float curtime = pPlayer ? pPlayer->GetFinalPredictedTime() : gpGlobals->curtime; elapsed_time = curtime - m_flAnimTime; // Adjust for interpolated partial frame if ( !engine->IsPaused() ) { elapsed_time += ( gpGlobals->interpolation_amount * TICK_INTERVAL ); } } // Prediction errors? if ( elapsed_time < 0 ) { elapsed_time = 0; } float dt = elapsed_time * GetSequenceCycleRate( pStudioHdr, GetSequence() ) * GetPlaybackRate(); if ( dt >= 1.0f ) { if ( !IsSequenceLooping( GetSequence() ) ) { dt = 0.999f; } else { dt = fmod( dt, 1.0f ); } } SetCycle( dt ); return bret; }
bool C_CFPlayer::GetIntervalMovement( float flIntervalUsed, bool &bMoveSeqFinished, Vector &newPosition, QAngle &newAngles ) { CStudioHdr *pstudiohdr = GetModelPtr( ); if (! pstudiohdr || !pstudiohdr->SequencesAvailable()) return false; float flComputedCycleRate = GetSequenceCycleRate( pstudiohdr, GetSequence() ); float flNextCycle = GetCycle() + flIntervalUsed * flComputedCycleRate * m_flPlaybackRate; if ((!SequenceLoops()) && flNextCycle > 1.0) { flIntervalUsed = GetCycle() / (flComputedCycleRate * m_flPlaybackRate); flNextCycle = 1.0; bMoveSeqFinished = true; } else { bMoveSeqFinished = false; } Vector deltaPos; QAngle deltaAngles; float poseParameters[MAXSTUDIOPOSEPARAM]; GetPoseParameters(pstudiohdr, poseParameters); if (Studio_SeqMovement( pstudiohdr, GetSequence(), GetCycle(), flNextCycle, poseParameters, deltaPos, deltaAngles )) { VectorYawRotate( deltaPos, GetLocalAngles().y, deltaPos ); newPosition = GetLocalOrigin() + deltaPos; newAngles.Init(); newAngles.y = GetLocalAngles().y + deltaAngles.y; return true; } else { newPosition = GetLocalOrigin(); newAngles = GetLocalAngles(); return false; } }
void C_FirstpersonBody::StudioFrameAdvance() { BaseClass::StudioFrameAdvance(); for ( int i = 0; i < GetNumAnimOverlays(); i++ ) { C_AnimationLayer *pLayer = GetAnimOverlay( i ); if ( pLayer->m_nSequence < 0 ) { continue; } float rate = GetSequenceCycleRate( GetModelPtr(), pLayer->m_nSequence ); pLayer->m_flCycle += pLayer->m_flPlaybackRate * rate * gpGlobals->frametime; if ( pLayer->m_flCycle > 1.0f ) { pLayer->m_nSequence = -1; pLayer->m_flWeight = 0.0f; } } }
//----------------------------------------------------------------------------- // Purpose: Render the weapon. Draw the Viewmodel if the weapon's being carried // by this player, otherwise draw the worldmodel. //----------------------------------------------------------------------------- int C_BaseViewModel::DrawModel( int flags, const RenderableInstance_t &instance ) { if ( !m_bReadyToDraw ) return 0; if ( flags & STUDIO_RENDER ) { // Determine blending amount and tell engine float blend = (float)( instance.m_nAlpha / 255.0f ); // Totally gone if ( blend <= 0.0f ) return 0; // Tell engine render->SetBlend( blend ); float color[3]; GetColorModulation( color ); render->SetColorModulation( color ); } CMatRenderContextPtr pRenderContext( materials ); if ( ShouldFlipViewModel() ) pRenderContext->CullMode( MATERIAL_CULLMODE_CW ); int ret = 0; C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); C_BaseCombatWeapon *pWeapon = GetOwningWeapon(); // If the local player's overriding the viewmodel rendering, let him do it if ( pPlayer && pPlayer->IsOverridingViewmodel() ) { ret = pPlayer->DrawOverriddenViewmodel( this, flags, instance ); } else if ( pWeapon && pWeapon->IsOverridingViewmodel() ) { ret = pWeapon->DrawOverriddenViewmodel( this, flags, instance ); } else { ret = BaseClass::DrawModel( flags, instance ); } pRenderContext->CullMode( MATERIAL_CULLMODE_CCW ); // Now that we've rendered, reset the animation restart flag if ( flags & STUDIO_RENDER ) { if ( m_nOldAnimationParity != m_nAnimationParity ) { m_nOldAnimationParity = m_nAnimationParity; } // Tell the weapon itself that we've rendered, in case it wants to do something if ( pWeapon ) { pWeapon->ViewModelDrawn( this ); } if ( vm_debug.GetBool() ) { MDLCACHE_CRITICAL_SECTION(); int line = 16; CStudioHdr *hdr = GetModelPtr(); engine->Con_NPrintf( line++, "%s: %s(%d), cycle: %.2f cyclerate: %.2f playbackrate: %.2f\n", (hdr)?hdr->pszName():"(null)", GetSequenceName( GetSequence() ), GetSequence(), GetCycle(), GetSequenceCycleRate( hdr, GetSequence() ), GetPlaybackRate() ); if ( hdr ) { for( int i=0; i < hdr->GetNumPoseParameters(); ++i ) { const mstudioposeparamdesc_t &Pose = hdr->pPoseParameter( i ); engine->Con_NPrintf( line++, "pose_param %s: %f", Pose.pszName(), GetPoseParameter( i ) ); } } // Determine blending amount and tell engine float blend = (float)( instance.m_nAlpha / 255.0f ); float color[3]; GetColorModulation( color ); engine->Con_NPrintf( line++, "blend=%f, color=%f,%f,%f", blend, color[0], color[1], color[2] ); engine->Con_NPrintf( line++, "GetRenderMode()=%d", GetRenderMode() ); engine->Con_NPrintf( line++, "m_nRenderFX=0x%8.8X", GetRenderFX() ); color24 c = GetRenderColor(); unsigned char a = GetRenderAlpha(); engine->Con_NPrintf( line++, "rendercolor=%d,%d,%d,%d", c.r, c.g, c.b, a ); engine->Con_NPrintf( line++, "origin=%f, %f, %f", GetRenderOrigin().x, GetRenderOrigin().y, GetRenderOrigin().z ); engine->Con_NPrintf( line++, "angles=%f, %f, %f", GetRenderAngles()[0], GetRenderAngles()[1], GetRenderAngles()[2] ); if ( IsEffectActive( EF_NODRAW ) ) { engine->Con_NPrintf( line++, "EF_NODRAW" ); } } } return ret; }