/* ===================== idActor::Event_DisableEyeFocus ===================== */ void idActor::Event_DisableEyeFocus() { allowEyeFocus = false; idEntity* headEnt = head.GetEntity(); if( headEnt ) { headEnt->GetAnimator()->Clear( ANIMCHANNEL_EYELIDS, gameLocal.time, FRAME2MS( 2 ) ); } else { animator.Clear( ANIMCHANNEL_EYELIDS, gameLocal.time, FRAME2MS( 2 ) ); } }
/* ===================== idTestModel::BlendAnim ===================== */ void idTestModel::BlendAnim( const idCmdArgs& args ) { int anim1; int anim2; if( args.Argc() < 4 ) { gameLocal.Printf( "usage: testblend <anim1> <anim2> <frames>\n" ); return; } anim1 = gameLocal.testmodel->animator.GetAnim( args.Argv( 1 ) ); if( !anim1 ) { gameLocal.Printf( "Animation '%s' not found.\n", args.Argv( 1 ) ); return; } anim2 = gameLocal.testmodel->animator.GetAnim( args.Argv( 2 ) ); if( !anim2 ) { gameLocal.Printf( "Animation '%s' not found.\n", args.Argv( 2 ) ); return; } animname = args.Argv( 2 ); animator.CycleAnim( ANIMCHANNEL_ALL, anim1, gameLocal.time, 0 ); animator.CycleAnim( ANIMCHANNEL_ALL, anim2, gameLocal.time, FRAME2MS( atoi( args.Argv( 3 ) ) ) ); anim = anim2; headAnim = 0; }
void idActor::SyncAnimChannels( int channel, int syncToChannel, int blendFrames ) { idAnimator *headAnimator; //idAFAttachment *headEnt; int anim; idAnimBlend *syncAnim; int starttime; int blendTime; int cycle; blendTime = FRAME2MS( blendFrames ); if ( channel == ANIMCHANNEL_HEAD ) { #if 0 headEnt = head.GetEntity(); if ( headEnt ) { headAnimator = headEnt->GetAnimator(); syncAnim = animator.CurrentAnim( syncToChannel ); if ( syncAnim ) { anim = headAnimator->GetAnim( syncAnim->AnimFullName() ); if ( !anim ) { anim = headAnimator->GetAnim( syncAnim->AnimName() ); } if ( anim ) { cycle = animator.CurrentAnim( syncToChannel )->GetCycleCount(); starttime = animator.CurrentAnim( syncToChannel )->GetStartTime(); headAnimator->PlayAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, blendTime ); headAnimator->CurrentAnim( ANIMCHANNEL_ALL )->SetCycleCount( cycle ); headAnimator->CurrentAnim( ANIMCHANNEL_ALL )->SetStartTime( starttime ); } else { headEnt->PlayIdleAnim( blendTime ); } } } #endif } else if ( syncToChannel == ANIMCHANNEL_HEAD ) { #if 0 headEnt = head.GetEntity(); if ( headEnt ) { headAnimator = headEnt->GetAnimator(); syncAnim = headAnimator->CurrentAnim( ANIMCHANNEL_ALL ); if ( syncAnim ) { anim = GetAnim( channel, syncAnim->AnimFullName() ); if ( !anim ) { anim = GetAnim( channel, syncAnim->AnimName() ); } if ( anim ) { cycle = headAnimator->CurrentAnim( ANIMCHANNEL_ALL )->GetCycleCount(); starttime = headAnimator->CurrentAnim( ANIMCHANNEL_ALL )->GetStartTime(); animator.PlayAnim( channel, anim, gameLocal.time, blendTime ); animator.CurrentAnim( channel )->SetCycleCount( cycle ); animator.CurrentAnim( channel )->SetStartTime( starttime ); } } } #endif } else { animator.SyncAnimChannels( channel, syncToChannel, gameLocal.time, blendTime ); } }
/* ================ rvTramGate::CycleAnim ================ */ void rvTramGate::CycleAnim( int channel, const char* animName, int blendFrames ) { int animHandle = GetAnimator()->GetAnim( animName ); if( !animHandle ) { ClearAllAnims( blendFrames ); return; } GetAnimator()->CycleAnim( channel, animHandle, gameLocal.GetTime(), FRAME2MS(blendFrames) ); }
/* ================ rvTramGate::PlayAnim ================ */ int rvTramGate::PlayAnim( int channel, const char* animName, int blendFrames ) { int animHandle = GetAnimator()->GetAnim( animName ); if( !animHandle ) { ClearAllAnims( blendFrames ); return 0; } GetAnimator()->PlayAnim( channel, animHandle, gameLocal.GetTime(), FRAME2MS(blendFrames) ); return GetAnimator()->CurrentAnim(channel)->PlayLength(); }
/* ===================== idAnimState::AnimDone ===================== */ bool idAnimState::AnimDone( int blendFrames ) const { int animDoneTime; animDoneTime = animator->CurrentAnim( channel )->GetEndTime(); if ( animDoneTime < 0 ) { // playing a cycle return false; } else if ( animDoneTime - FRAME2MS( blendFrames ) <= gameLocal.time ) { return true; } else { return false; } }
/* ================ rvTramGate::Event_Touch ================ */ bool rvTramGate::AnimIsPlaying( int channel, int blendFrames ) { return GetAnimator()->CurrentAnim(channel)->GetEndTime() - FRAME2MS(blendFrames) >= gameLocal.GetTime(); }
/* ================ rvTramGate::Event_Touch ================ */ void rvTramGate::ClearAnim( int channel, int blendFrames ) { GetAnimator()->Clear( channel, gameLocal.GetTime(), FRAME2MS(blendFrames) ); }
/* ================ rvTramGate::Event_Touch ================ */ void rvTramGate::ClearAllAnims( int blendFrames ) { GetAnimator()->ClearAllAnims( gameLocal.GetTime(), FRAME2MS(blendFrames) ); }
/* ================ idTestModel::Think ================ */ void idTestModel::Think() { idVec3 pos; idMat3 axis; idAngles ang; int i; if( thinkFlags & TH_THINK ) { if( anim && ( gameLocal.testmodel == this ) && ( mode != g_testModelAnimate.GetInteger() ) ) { StopSound( SND_CHANNEL_ANY, false ); if( head.GetEntity() ) { head.GetEntity()->StopSound( SND_CHANNEL_ANY, false ); } switch( g_testModelAnimate.GetInteger() ) { default: case 0: // cycle anim with origin reset if( animator.NumFrames( anim ) <= 1 ) { // single frame animations end immediately, so just cycle it since it's the same result animator.CycleAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); if( headAnim ) { headAnimator->CycleAnim( ANIMCHANNEL_ALL, headAnim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); } } else { animator.PlayAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); if( headAnim ) { headAnimator->PlayAnim( ANIMCHANNEL_ALL, headAnim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); if( headAnimator->AnimLength( headAnim ) > animator.AnimLength( anim ) ) { // loop the body anim when the head anim is longer animator.CurrentAnim( ANIMCHANNEL_ALL )->SetCycleCount( -1 ); } } } animator.RemoveOriginOffset( false ); break; case 1: // cycle anim with fixed origin animator.CycleAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); animator.RemoveOriginOffset( true ); if( headAnim ) { headAnimator->CycleAnim( ANIMCHANNEL_ALL, headAnim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); } break; case 2: // cycle anim with continuous origin animator.CycleAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); animator.RemoveOriginOffset( false ); if( headAnim ) { headAnimator->CycleAnim( ANIMCHANNEL_ALL, headAnim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); } break; case 3: // frame by frame with continuous origin animator.SetFrame( ANIMCHANNEL_ALL, anim, frame, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); animator.RemoveOriginOffset( false ); if( headAnim ) { headAnimator->SetFrame( ANIMCHANNEL_ALL, headAnim, frame, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); } break; case 4: // play anim once animator.PlayAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); animator.RemoveOriginOffset( false ); if( headAnim ) { headAnimator->PlayAnim( ANIMCHANNEL_ALL, headAnim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); } break; case 5: // frame by frame with fixed origin animator.SetFrame( ANIMCHANNEL_ALL, anim, frame, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); animator.RemoveOriginOffset( true ); if( headAnim ) { headAnimator->SetFrame( ANIMCHANNEL_ALL, headAnim, frame, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); } break; } mode = g_testModelAnimate.GetInteger(); } if( ( mode == 0 ) && ( gameLocal.time >= starttime + animtime ) ) { starttime = gameLocal.time; StopSound( SND_CHANNEL_ANY, false ); animator.PlayAnim( ANIMCHANNEL_ALL, anim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); if( headAnim ) { headAnimator->PlayAnim( ANIMCHANNEL_ALL, headAnim, gameLocal.time, FRAME2MS( g_testModelBlend.GetInteger() ) ); if( headAnimator->AnimLength( headAnim ) > animator.AnimLength( anim ) ) { // loop the body anim when the head anim is longer animator.CurrentAnim( ANIMCHANNEL_ALL )->SetCycleCount( -1 ); } } } if( headAnimator ) { // copy the animation from the body to the head for( i = 0; i < copyJoints.Num(); i++ ) { if( copyJoints[ i ].mod == JOINTMOD_WORLD_OVERRIDE ) { idMat3 mat = head.GetEntity()->GetPhysics()->GetAxis().Transpose(); GetJointWorldTransform( copyJoints[ i ].from, gameLocal.time, pos, axis ); pos -= head.GetEntity()->GetPhysics()->GetOrigin(); headAnimator->SetJointPos( copyJoints[ i ].to, copyJoints[ i ].mod, pos * mat ); headAnimator->SetJointAxis( copyJoints[ i ].to, copyJoints[ i ].mod, axis * mat ); } else { animator.GetJointLocalTransform( copyJoints[ i ].from, gameLocal.time, pos, axis ); headAnimator->SetJointPos( copyJoints[ i ].to, copyJoints[ i ].mod, pos ); headAnimator->SetJointAxis( copyJoints[ i ].to, copyJoints[ i ].mod, axis ); } } } // update rotation RunPhysics(); physicsObj.GetAngles( ang ); physicsObj.SetAngularExtrapolation( extrapolation_t( EXTRAPOLATION_LINEAR | EXTRAPOLATION_NOSTOP ), gameLocal.time, 0, ang, idAngles( 0, g_testModelRotate.GetFloat() * 360.0f / 60.0f, 0 ), ang_zero ); idClipModel* clip = physicsObj.GetClipModel(); if( clip != NULL && animator.ModelDef() ) { idVec3 neworigin; idMat3 axis; jointHandle_t joint; joint = animator.GetJointHandle( "origin" ); animator.GetJointTransform( joint, gameLocal.time, neworigin, axis ); neworigin = ( ( neworigin - animator.ModelDef()->GetVisualOffset() ) * physicsObj.GetAxis() ) + GetPhysics()->GetOrigin(); clip->Link( gameLocal.clip, this, 0, neworigin, clip->GetAxis() ); } } UpdateAnimation(); Present(); if( ( gameLocal.testmodel == this ) && g_showTestModelFrame.GetInteger() && anim ) { gameLocal.Printf( "^5 Anim: ^7%s ^5Frame: ^7%d/%d Time: %.3f\n", animator.AnimFullName( anim ), animator.CurrentAnim( ANIMCHANNEL_ALL )->GetFrameNumber( gameLocal.time ), animator.CurrentAnim( ANIMCHANNEL_ALL )->NumFrames(), MS2SEC( gameLocal.time - animator.CurrentAnim( ANIMCHANNEL_ALL )->GetStartTime() ) ); if( headAnim ) { gameLocal.Printf( "^5 Head: ^7%s ^5Frame: ^7%d/%d Time: %.3f\n\n", headAnimator->AnimFullName( headAnim ), headAnimator->CurrentAnim( ANIMCHANNEL_ALL )->GetFrameNumber( gameLocal.time ), headAnimator->CurrentAnim( ANIMCHANNEL_ALL )->NumFrames(), MS2SEC( gameLocal.time - headAnimator->CurrentAnim( ANIMCHANNEL_ALL )->GetStartTime() ) ); } else { gameLocal.Printf( "\n\n" ); } } }
/* ===================== idAnimState::CycleAnim ===================== */ void idAnimState::CycleAnim( int anim ) { if ( anim ) { animator->CycleAnim( channel, anim, gameLocal.time, FRAME2MS( animBlendFrames ) ); } animBlendFrames = 0; }
/* ===================== idAnimState::StopAnim ===================== */ void idAnimState::StopAnim( int frames ) { animBlendFrames = 0; animator->Clear( channel, gameLocal.time, FRAME2MS( frames ) ); }