bool CAnimationProxyDualCharacterUpper::RemoveAnimationInLayer(IEntity *entity, int32 nLayer, uint32 token) { ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; ICharacterInstance* pICharacter = pIShadowCharacter ? pIShadowCharacter : entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); if (pIShadowCharacter) { ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim(); int nAnimsInFIFO = pIShadowSkeletonAnim->GetNumAnimsInFIFO(nLayer); for (int i=0; i<nAnimsInFIFO; ++i) { const CAnimation& anim = pIShadowSkeletonAnim->GetAnimFromFIFO(nLayer, i); if (anim.HasUserToken(token)) { pIShadowSkeletonAnim->RemoveAnimFromFIFO(nLayer, i); } } } int nAnimsInFIFO = pISkeletonAnim->GetNumAnimsInFIFO(nLayer); for (int i=0; i<nAnimsInFIFO; ++i) { const CAnimation& anim = pISkeletonAnim->GetAnimFromFIFO(nLayer, i); if (anim.HasUserToken(token)) { return pISkeletonAnim->RemoveAnimFromFIFO(nLayer, i); } } } return false; }
//------------------------------------------------------------------------ void CItem::PlayLayer(const ItemString &layerName, int flags, bool record) { TLayerMap::iterator it = m_sharedparams->layers.find(CONST_TEMPITEM_STRING(layerName)); if(it == m_sharedparams->layers.end()) return; TempResourceName tempResourceName; for(int i=0; i<eIGS_Last; i++) { if(!(flags&1<<i)) continue; SLayer &layer = it->second; if(!layer.name[i].empty()) { ICharacterInstance *pCharacter = GetEntity()->GetCharacter(i); if(pCharacter) { CryCharAnimationParams params; float blend = 0.125f; if(flags&eIPAF_NoBlend) blend = 0.0f; params.m_fTransTime = blend; params.m_nLayerID = layer.id[i]; params.m_nFlags = CA_LOOP_ANIMATION; FixResourceName(layer.name[i], tempResourceName, flags); ISkeletonAnim *pSkeletonAnim=pCharacter->GetISkeletonAnim(); pSkeletonAnim->StartAnimation(tempResourceName, params); if(layer.bones.empty()) { pCharacter->GetISkeletonAnim()->SetLayerMask(layer.id[i], 1); } else { pCharacter->GetISkeletonAnim()->SetLayerMask(layer.id[i], 0); for(std::vector<ItemString>::iterator bit = layer.bones.begin(); bit != layer.bones.end(); bit++) pCharacter->GetISkeletonAnim()->SetJointMask(bit->c_str(), layer.id[i], 1); } } } } if(record) { TActiveLayerMap::iterator ait = m_activelayers.find(CONST_TEMPITEM_STRING(layerName)); if(ait == m_activelayers.end()) m_activelayers.insert(TActiveLayerMap::value_type(layerName, flags)); } }
bool CAnimationProxyDualCharacter::StartAnimationById(IEntity *entity, int animId, const CryCharAnimationParams& Params, float speedMultiplier) { ICharacterInstance* pICharacter = entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; IAnimationSet* pAnimSet = pICharacter->GetIAnimationSet(); SPlayParams playParams; GetPlayParams(animId, speedMultiplier, pAnimSet, playParams); bool shadowLocomotion = !(((Params.m_nFlags & CA_DISABLE_MULTILAYER) || (Params.m_nLayerID != 0)) || !m_killMixInFirst); bool bAnimStarted = false; bool bShouldPlayShadow = true; CryCharAnimationParams localParams = Params; if (!m_firstPersonMode || !shadowLocomotion) { localParams.m_fPlaybackSpeed *= m_firstPersonMode ? playParams.speedFP : playParams.speedTP; bAnimStarted = pISkeletonAnim->StartAnimationById(m_firstPersonMode ? playParams.animIDFP : playParams.animIDTP, localParams); if (bAnimStarted) { pISkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f); } else bShouldPlayShadow = false; } if (bShouldPlayShadow && pIShadowCharacter != NULL) { ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim(); localParams.m_fPlaybackSpeed = Params.m_fPlaybackSpeed * playParams.speedTP; if (pIShadowSkeletonAnim->StartAnimationById(playParams.animIDTP, localParams)) { bAnimStarted = true; pIShadowSkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f); } } if (bAnimStarted && (Params.m_nLayerID == 0)) { m_allowsMix = (Params.m_nFlags & CA_DISABLE_MULTILAYER) == 0; } return bAnimStarted; } return false; }
bool CAnimationProxyDualCharacterUpper::StartAnimationById(IEntity *entity, int animId, const CryCharAnimationParams& Params, float speedMultiplier) { ICharacterInstance* pICharacter = entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; IAnimationSet* pAnimSet = pICharacter->GetIAnimationSet(); SPlayParams playParams; GetPlayParams(animId, speedMultiplier, pAnimSet, playParams); CryCharAnimationParams localParams = Params; bool startedMain = false; if (m_firstPersonMode) { localParams.m_fPlaybackSpeed *= playParams.speedFP; startedMain = pISkeletonAnim->StartAnimationById(playParams.animIDFP, localParams); } else { localParams.m_fPlaybackSpeed *= playParams.speedTP; startedMain = pISkeletonAnim->StartAnimationById(playParams.animIDTP, localParams); } if (startedMain) { pISkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f); } if (pIShadowCharacter != NULL && (Params.m_nLayerID != 0)) { ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim(); localParams.m_fPlaybackSpeed = Params.m_fPlaybackSpeed * playParams.speedTP; if (pIShadowSkeletonAnim->StartAnimationById(playParams.animIDTP, localParams)) { pIShadowSkeletonAnim->SetLayerBlendWeight(Params.m_nLayerID, 1.0f); } } return startedMain; } return false; }
CAnimation *CAnimationProxyDualCharacter::GetAnimation(IEntity *entity, int32 layer, uint32 token) { ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; ICharacterInstance* pICharacter = pIShadowCharacter ? pIShadowCharacter : entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); int nAnimsInFIFO = pISkeletonAnim->GetNumAnimsInFIFO(layer); if (nAnimsInFIFO == 0) { return NULL; } if (token == INVALID_ANIMATION_TOKEN) { return &pISkeletonAnim->GetAnimFromFIFO(layer, 0); } else { return pISkeletonAnim->FindAnimInFIFO(token, layer); } } return NULL; }
//------------------------------------------------------------------------ void CReplayActor::PlayUpperAnimation(int animId, const CryCharAnimationParams& params, float speedMultiplier, float animTime) { float adjustedLayerTime = 0; ICharacterInstance* pCharacterInstance = GetEntity()->GetCharacter(0); if (animTime == 0 || GetAdjustedLayerTime(pCharacterInstance, animId, params, speedMultiplier, animTime, adjustedLayerTime)) { m_animationProxyUpper.StartAnimationById(GetEntity(), animId, params, speedMultiplier); ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); pSkeletonAnim->SetLayerNormalizedTime(params.m_nLayerID, adjustedLayerTime); ICharacterInstance* pShadowCharacter = GetShadowCharacter(); if (pShadowCharacter) { pShadowCharacter->GetISkeletonAnim()->SetLayerNormalizedTime(params.m_nLayerID, adjustedLayerTime); } } }
bool CProceduralContextTurretAimPose::InitialiseCharacter( const int characterSlot ) { if ( m_entity == NULL ) { return false; } ICharacterInstance* pCharacterInstance = m_entity->GetCharacter( characterSlot ); if ( pCharacterInstance == NULL ) { return false; } ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); if ( pSkeletonAnim == NULL ) { return false; } ISkeletonPose* pSkeletonPose = pCharacterInstance->GetISkeletonPose(); if ( pSkeletonPose == NULL ) { return false; } ICharacterModelSkeleton* pICharacterModelSkeleton = pCharacterInstance->GetICharacterModel()->GetICharacterModelSkeleton(); m_pCharacterInstance = pCharacterInstance; m_pSkeletonAnim = pSkeletonAnim; m_pSkeletonPose = pSkeletonPose; m_pICharacterModelSkeleton = pICharacterModelSkeleton; return true; }
//------------------------------------------------------------------------ void CItem::UpdateFPCharacter(float frameTime) { if (IsClient()) { ICharacterInstance *pCharacter = GetEntity()->GetCharacter(eIGS_FirstPerson); if (pCharacter && !m_idleAnimation[eIGS_FirstPerson].empty() && pCharacter->GetISkeletonAnim()->GetNumAnimsInFIFO(0)<1) PlayAction(m_idleAnimation[eIGS_FirstPerson], 0, true); } // need to explicitly update characters at this point // cause the entity system update occered earlier, with the last position for (int i=0; i<eIGS_Last; i++) { if (GetEntity()->GetSlotFlags(i)&ENTITY_SLOT_RENDER) { ICharacterInstance *pCharacter = GetEntity()->GetCharacter(i); if (pCharacter) { Matrix34 mloc = GetEntity()->GetSlotLocalTM(i,false); Matrix34 m34=GetEntity()->GetWorldTM()*mloc; QuatT renderLocation = QuatT(m34); pCharacter->GetISkeletonPose()->SetForceSkeletonUpdate(8); pCharacter->SkeletonPreProcess(renderLocation, renderLocation, GetISystem()->GetViewCamera(),0x55 ); pCharacter->SetPostProcessParameter(renderLocation, renderLocation, 0, 1.0f, 0x55 ); } } } IEntityRenderProxy *pProxy=GetRenderProxy(); if (pProxy) pProxy->InvalidateLocalBounds(); }
void CAnimatedCharacter::CalculateParamsForCurrentMotions() { if(m_doMotionParams) { ANIMCHAR_PROFILE; IEntity* pEntity = GetEntity(); CRY_ASSERT(pEntity); ICharacterInstance* pCharacterInstance = pEntity->GetCharacter(0); if (pCharacterInstance == NULL) return; ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); if (pSkeletonAnim == NULL) return; SetDesiredLocalLocation(pSkeletonAnim, m_desiredLocalLocation, (float)m_curFrameTime); if (m_pShadowSkeletonAnim) SetDesiredLocalLocation(m_pShadowSkeletonAnim, m_desiredLocalLocation, (float)m_curFrameTime); #ifdef _DEBUG DebugGraphQT(m_desiredLocalLocation, "eDH_DesiredLocalLocationTX", "eDH_DesiredLocalLocationTY", "eDH_DesiredLocalLocationRZ"); //DebugGraphMotionParams(pSkeletonAnim); #endif } }
//------------------------------------------------------------------------ void CItem::StopLayer(const ItemString &layerName, int flags, bool record) { TLayerMap::iterator it = m_sharedparams->layers.find(CONST_TEMPITEM_STRING(layerName)); if(it == m_sharedparams->layers.end()) return; for(int i=0; i<eIGS_Last; i++) { if(!(flags&1<<i)) continue; ICharacterInstance *pCharacter = GetEntity()->GetCharacter(i); if(pCharacter) pCharacter->GetISkeletonAnim()->StopAnimationInLayer(it->second.id[i],0.0f); } if(record) { TActiveLayerMap::iterator ait = m_activelayers.find(CONST_TEMPITEM_STRING(layerName)); if(ait != m_activelayers.end()) m_activelayers.erase(ait); } }
void CLivingEntitySample::UpdateAnimationParams( const float frameTime ) { IEntity* pEntity = GetEntity(); const int slot = 0; ICharacterInstance* pCharacterInstance = pEntity->GetCharacter( slot ); if ( pCharacterInstance == NULL ) { return; } ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); if ( pSkeletonAnim == NULL ) { return; } ISkeletonPose* pSkeletonPose = pCharacterInstance->GetISkeletonPose(); if ( pSkeletonPose == NULL ) { return; } const Vec2 localVelocity( m_localEntityVelocity.x, m_localEntityVelocity.y ); const float speed = localVelocity.GetLength(); const float angle = atan2f( -localVelocity.x, localVelocity.y ); pSkeletonAnim->SetDesiredMotionParam( eMotionParamID_TravelSpeed, speed, frameTime ); pSkeletonAnim->SetDesiredMotionParam( eMotionParamID_TravelAngle, angle, frameTime ); }
void CLivingEntitySample::ResetCharacterModel() { IEntity* pEntity = GetEntity(); const int slot = 0; const char* modelFilename = DEFAULT_MODEL_NAME; pEntity->LoadCharacter( slot, modelFilename ); ICharacterInstance* pCharacterInstance = pEntity->GetCharacter( slot ); if ( pCharacterInstance == NULL ) { return; } ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); if ( pSkeletonAnim == NULL ) { return; } ISkeletonPose* pSkeletonPose = pCharacterInstance->GetISkeletonPose(); if ( pSkeletonPose == NULL ) { return; } pSkeletonPose->SetFootAnchoring( 1 ); pSkeletonAnim->SetAnimationDrivenMotion( 1 ); // We will want to set motion parameters directly ourselves for this sample: pSkeletonAnim->SetCharEditMode( 1 ); }
//------------------------------------------------------------------------ void CItem::PlayAnimationEx(const char* animationName, int slot, int layer, bool loop, float blend, float speed, uint32 flags) { bool start=true; ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot); if (!pCharacter && slot==eIGS_FirstPerson && ((m_stats.viewmode&eIVM_FirstPerson)==0)) { start=false; int idx = 0; if (m_stats.hand == eIH_Right) idx = 1; else if (m_stats.hand == eIH_Left) idx = 2; if (m_fpgeometry[idx].name.empty()) idx = 0; pCharacter = m_pItemSystem->GetCachedCharacter(m_fpgeometry[idx].name.c_str()); } if (pCharacter && animationName) { ISkeletonAnim* pSkeletonAnim = pCharacter->GetISkeletonAnim(); if (flags&eIPAF_CleanBlending) { while(pSkeletonAnim->GetNumAnimsInFIFO(layer)>1) { if (!pSkeletonAnim->RemoveAnimFromFIFO(layer, pSkeletonAnim->GetNumAnimsInFIFO(layer)-1)) break; } } if (flags&eIPAF_NoBlend) blend = 0.0f; if (start) { CryCharAnimationParams params; params.m_fTransTime = blend; params.m_nLayerID = layer; params.m_nFlags = (loop?CA_LOOP_ANIMATION:0)|(flags&eIPAF_RestartAnimation?CA_ALLOW_ANIM_RESTART:0)|(flags&eIPAF_RepeatLastFrame?CA_REPEAT_LAST_KEY:0); pSkeletonAnim->StartAnimation(animationName, params); pSkeletonAnim->SetLayerUpdateMultiplier(layer, speed); //pCharacter->GetISkeleton()->SetDebugging( true ); } float duration=0.0f; int animationId = pCharacter->GetIAnimationSet()->GetAnimIDByName(animationName); if (animationId>=0) duration = pCharacter->GetIAnimationSet()->GetDuration_sec(animationId); m_animationTime[slot] = (uint32)(duration*1000.0f/speed); m_animationEnd[slot] = (uint32)(gEnv->pTimer->GetCurrTime()*1000.0f)+m_animationTime[slot]; m_animationSpeed[slot] = speed; } }
void CVar::EnableDebugAnimText(IConsoleCmdArgs *args) { if (args && args->GetArgCount() > 1) { const char* szFilterName = args->GetArg(1); bool enable = true; if (args->GetArgCount() > 2) { enable = (strcmp(args->GetArg(2), "0") != 0); } CEntitySystem* pEntitySystem = GetIEntitySystem(); IEntity *entity = pEntitySystem->FindEntityByName(szFilterName); if (entity) { uint32 numSlots = entity->GetSlotCount(); for (uint32 i=0; i<numSlots; i++) { ICharacterInstance *charInst = entity->GetCharacter(i); if (charInst) { charInst->GetISkeletonAnim()->SetDebugging(enable); IAttachmentManager* pAttachmentManager = charInst->GetIAttachmentManager(); for(int32 attachmentIndex=0; attachmentIndex<pAttachmentManager->GetAttachmentCount(); ++attachmentIndex) { IAttachment* pAttachment = pAttachmentManager->GetInterfaceByIndex(attachmentIndex); assert(pAttachment); IAttachmentObject* pObject = pAttachment->GetIAttachmentObject(); if (pObject) { ICharacterInstance* pObjectCharInst = pObject->GetICharacterInstance(); if (pObjectCharInst) { pObjectCharInst->GetISkeletonAnim()->SetDebugging(enable); } } } } } } } }
bool CAnimationProxyDualCharacterUpper::StopAnimationInLayer(IEntity *entity, int32 nLayer, f32 BlendOutTime) { ICharacterInstance* pICharacter = entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; if (pIShadowCharacter) { ISkeletonAnim* pIShadowSkeletonAnim = pIShadowCharacter->GetISkeletonAnim(); pIShadowSkeletonAnim->StopAnimationInLayer(nLayer, BlendOutTime); } return pISkeletonAnim->StopAnimationInLayer(nLayer, BlendOutTime); } return false; }
int CScriptBind_Actor::TrackViewControlled( IFunctionHandler *pH, int characterSlot ) { CActor *pActor = GetActor(pH); if (pActor) { ICharacterInstance *pCharacter = pActor->GetEntity()->GetCharacter(characterSlot); if (pCharacter) return pH->EndFunction((pCharacter->GetISkeletonAnim()->GetTrackViewStatus()?true:false)); } return pH->EndFunction(); }
void CScriptbind_Entity::StopAnimationsInAllLayers(IEntity *pEntity, int slot) { ICharacterInstance *pCharacter = pEntity->GetCharacter(slot); if(!pCharacter) return; ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); if(!pSkeletonAnim) return; pSkeletonAnim->StopAnimationsAllLayers(); }
void CScriptbind_Entity::StopAnimationInLayer(IEntity *pEntity, int slot, int layer, float blendOutTime) { ICharacterInstance *pCharacter = pEntity->GetCharacter(slot); if(!pCharacter) return; ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); if(!pSkeletonAnim) return; pSkeletonAnim->StopAnimationInLayer(layer, blendOutTime); }
//------------------------------------------------------------------------ void CItem::ResetAnimation(int layer, uint32 flags) { for (int i=0; i<eIGS_Last; i++) { if (!(flags&1<<i)) continue; if ((i == eIGS_Owner) || (i == eIGS_OwnerLooped)) continue; ICharacterInstance *pCharacter = GetEntity()->GetCharacter(i); if (pCharacter) pCharacter->GetISkeletonAnim()->StopAnimationsAllLayers(); } }
const CAnimation *CAnimationProxyDualCharacter::GetAnimation(IEntity *entity, int32 layer) { ICharacterInstance* pIShadowCharacter = m_firstPersonMode ? entity->GetCharacter(m_characterShadow) : NULL; ICharacterInstance* pICharacter = pIShadowCharacter ? pIShadowCharacter : entity->GetCharacter(m_characterMain); if (pICharacter) { ISkeletonAnim* pISkeletonAnim = pICharacter->GetISkeletonAnim(); int nAnimsInFIFO = pISkeletonAnim->GetNumAnimsInFIFO(layer); if (nAnimsInFIFO > 0) { return &pISkeletonAnim->GetAnimFromFIFO(layer, nAnimsInFIFO-1); } } return NULL; }
void CScriptbind_Entity::PlayAnimation(IEntity *pEntity, mono::string animationName, int slot, int layer, float blend, float speed, EAnimationFlags flags) { // Animation graph input /*if(IGameObject *pGameObject = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetGameObject(pEntity->GetId())) { if(IAnimatedCharacter *pAniamtedCharacter = static_cast<IAnimatedCharacter*>(pGameObject->AcquireExtension("AnimatedCharacter"))) { pAniamtedCharacter->GetAnimationGraphState()->SetInput("Action / "Signal" } }*/ ICharacterInstance *pCharacter = pEntity->GetCharacter(slot); if(!pCharacter) return; ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); if(!pSkeletonAnim) return; if(flags & EAnimFlag_CleanBending) { while(pSkeletonAnim->GetNumAnimsInFIFO(layer)>1) { if (!pSkeletonAnim->RemoveAnimFromFIFO(layer, pSkeletonAnim->GetNumAnimsInFIFO(layer)-1)) break; } } if (flags & EAnimFlag_NoBlend) blend = 0.0f; CryCharAnimationParams params; params.m_fTransTime = blend; params.m_nLayerID = layer; params.m_fPlaybackSpeed = speed; params.m_nFlags = (flags & EAnimFlag_Loop ? CA_LOOP_ANIMATION : 0) | (flags & EAnimFlag_RestartAnimation ? CA_ALLOW_ANIM_RESTART : 0) | (flags & EAnimFlag_RepeatLastFrame ? CA_REPEAT_LAST_KEY : 0); pSkeletonAnim->StartAnimation(ToCryString(animationName), params); }
void CProceduralWeaponAnimationContext::Update(float timePassed) { ICharacterInstance* pCharacter = m_pScope->GetCharInst(); if (m_instanceCount <= 0 || pCharacter == 0) return; m_weaponSway.Update(timePassed); const QuatT rightOffset = m_weaponSway.GetRightOffset(); const QuatT leftOffset = m_weaponSway.GetLeftOffset(); const int PWALayer = GetGameConstCVar(g_pwaLayer); pCharacter->GetISkeletonAnim()->PushPoseModifier(PWALayer, cryinterface_cast<IAnimationPoseModifier>(m_pPoseModifier), "ProceduralWeapon"); m_pPoseModifier->Clear(); const IAnimationOperatorQueue::EOp set = IAnimationOperatorQueue::eOp_OverrideRelative; const IAnimationOperatorQueue::EOp additive = IAnimationOperatorQueue::eOp_Additive; ISkeletonPose* pPose = pCharacter->GetISkeletonPose(); Vec3 relBlendPos = Vec3(1.0f, 0.0f, 0.0f); m_pPoseModifier->PushPosition(m_params.m_rightBlendIkIdx, set, relBlendPos); Quat view = Quat::CreateRotationVDir(m_aimDirection); Quat invView = view.GetInverted(); QuatT rightHand; rightHand.t = view * rightOffset.t; rightHand.q = view * (rightOffset.q * invView); m_pPoseModifier->PushPosition(m_params.m_weaponTargetIdx, additive, rightHand.t); m_pPoseModifier->PushOrientation(m_params.m_weaponTargetIdx, additive, rightHand.q); QuatT leftHand; leftHand.t = view * leftOffset.t; leftHand.q = view * (leftOffset.q * invView); m_pPoseModifier->PushPosition(m_params.m_leftHandTargetIdx, additive, leftHand.t); m_pPoseModifier->PushOrientation(m_params.m_leftHandTargetIdx, additive, leftHand.q); }
void CLivingEntitySample::StartAnimationForCurrentAnimationState() { IEntity* pEntity = GetEntity(); const int slot = 0; ICharacterInstance* pCharacterInstance = pEntity->GetCharacter( slot ); if ( pCharacterInstance == NULL ) { return; } ISkeletonAnim* pSkeletonAnim = pCharacterInstance->GetISkeletonAnim(); if ( pSkeletonAnim == NULL ) { return; } CryCharAnimationParams animationParams; animationParams.m_nFlags |= CA_LOOP_ANIMATION; animationParams.m_nLayerID = 0; animationParams.m_fTransTime = 0.3f; const char* animationName = IDLE_ANIMATION_NAME; switch ( m_animationState ) { case None: case Idle: animationName = IDLE_ANIMATION_NAME; break; case Walk: animationName = WALK_ANIMATION_NAME; break; } pSkeletonAnim->StartAnimation( animationName, animationParams ); }
//------------------------------------------------------------------------ void CItem::UpdateMounted(float frameTime) { IRenderAuxGeom* pAuxGeom = gEnv->pRenderer->GetIRenderAuxGeom(); if (!m_ownerId || !m_stats.mounted) return; CActor *pActor = GetOwnerActor(); if (!pActor) return; CheckViewChange(); if (true) { if (IsClient()) { ICharacterInstance *pCharacter = GetEntity()->GetCharacter(eIGS_FirstPerson); if (pCharacter && !m_idleAnimation[eIGS_FirstPerson].empty() && pCharacter->GetISkeletonAnim()->GetNumAnimsInFIFO(0)<1) PlayAction(m_idleAnimation[eIGS_FirstPerson], 0, true); } // need to explicitly update characters at this point // cause the entity system update occered earlier, with the last position for (int i=0; i<eIGS_Last; i++) { if (GetEntity()->GetSlotFlags(i)&ENTITY_SLOT_RENDER) { ICharacterInstance *pCharacter = GetEntity()->GetCharacter(i); if (pCharacter) { Matrix34 mloc = GetEntity()->GetSlotLocalTM(i,false); Matrix34 m34 = GetEntity()->GetWorldTM()*mloc; QuatT renderLocation = QuatT(m34); pCharacter->GetISkeletonPose()->SetForceSkeletonUpdate(9); pCharacter->SkeletonPreProcess(renderLocation, renderLocation, GetISystem()->GetViewCamera(),0x55 ); pCharacter->SetPostProcessParameter(renderLocation, renderLocation, 0, 0.0f, 0x55 ); } } } // f32 fColor[4] = {1,1,0,1}; // f32 g_YLine=60.0f; // gEnv->pRenderer->Draw2dLabel( 1,g_YLine, 1.3f, fColor, false, "Mounted Gun Code" ); //adjust the orientation of the gun based on the aim-direction SMovementState info; IMovementController* pMC = pActor->GetMovementController(); pMC->GetMovementState(info); Vec3 dir = info.aimDirection.GetNormalized(); Matrix34 tm = Matrix33::CreateRotationVDir(dir); Vec3 vGunXAxis=tm.GetColumn0(); if (pActor->GetLinkedVehicle()==0) { if (pMC) { if(!pActor->IsPlayer()) { // prevent snapping direction Vec3 currentDir = GetEntity()->GetWorldRotation().GetColumn1(); float dot = currentDir.Dot(dir); dot = CLAMP(dot,-1,1); float reqAngle = cry_acosf(dot); const float maxRotSpeed = 2.0f; float maxAngle = frameTime * maxRotSpeed; if(fabs(reqAngle) > maxAngle) { Vec3 axis = currentDir.Cross(dir); if(axis.GetLengthSquared()>0.001f) // current dir and new dir are enough different dir = currentDir.GetRotated(axis.GetNormalized(),sgn(reqAngle)*maxAngle); } } //adjust the orientation of the gun based on the aim-direction tm = Matrix33::CreateRotationVDir(dir); Vec3 vWPos=GetEntity()->GetWorldPos(); tm.SetTranslation(vWPos); GetEntity()->SetWorldTM(tm); //set the new orientation of the mounted gun vGunXAxis=tm.GetColumn0(); Vec3 vInitialAimDirection = m_stats.mount_dir; Matrix33 vInitialPlayerOrientation = Matrix33::CreateRotationVDir(vInitialAimDirection); assert( vInitialAimDirection.IsUnit() ); Vec3 newp; if (pActor->IsThirdPerson()) { //third person f32 dist = m_mountparams.body_distance*1.3f; Vec3 oldp = pActor->GetEntity()->GetWorldPos(); newp = GetEntity()->GetWorldPos()-vInitialAimDirection*dist; //mounted gun newp.z = oldp.z; } else { //first person f32 fMoveBack = (1.0f+(dir.z*dir.z*dir.z*dir.z*4.0f))*0.75f; f32 dist = m_mountparams.eye_distance*fMoveBack; Vec3 oldp = pActor->GetEntity()->GetWorldPos(); newp = GetEntity()->GetWorldPos()-dir*dist; //mounted gun //newp.z -= 0.75f; newp.z = oldp.z; } Matrix34 actortm(pActor->GetEntity()->GetWorldTM()); //if (pActor->IsThirdPerson()) actortm=vInitialPlayerOrientation; actortm.SetTranslation(newp); pActor->GetEntity()->SetWorldTM(actortm, ENTITY_XFORM_USER); pActor->GetAnimationGraphState()->SetInput("Action","gunnerMounted"); //f32 g_YLine=80.0f; //gEnv->pRenderer->Draw2dLabel( 1,g_YLine, 1.3f, fColor, false, "Mounted Gun Active for FP and AI" ); if (ICharacterInstance *pCharacter = pActor->GetEntity()->GetCharacter(0)) { ISkeletonAnim *pSkeletonAnim = pCharacter->GetISkeletonAnim(); assert(pSkeletonAnim); uint32 numAnimsLayer = pSkeletonAnim->GetNumAnimsInFIFO(0); for(uint32 i=0; i<numAnimsLayer; i++) { CAnimation &animation = pSkeletonAnim->GetAnimFromFIFO(0, i); if (animation.m_AnimParams.m_nFlags & CA_MANUAL_UPDATE) { f32 aimrad = Ang3::CreateRadZ(Vec2(vInitialAimDirection),Vec2(dir)); animation.m_fAnimTime = clamp_tpl(aimrad/gf_PI,-1.0f,+1.0f)*0.5f+0.5f; //if (pActor->IsThirdPerson()==0) //animation.m_fAnimTime=0.6f; //Ivo & Benito: high advanced future code. don't ask what it is //Benito - Not needed any more ;) //f32 g_YLine=100.0f; //gEnv->pRenderer->Draw2dLabel( 1,g_YLine, 1.3f, fColor, false, "AnimTime: %f MyAimAngle: %f deg:% distance:%f", animation.m_fAnimTime, aimrad, RAD2DEG(aimrad),m_mountparams.body_distance ); } } } m_stats.mount_last_aimdir = dir; } } if (ICharacterInstance* pCharInstance = pActor->GetEntity()->GetCharacter(0)) { if (ISkeletonAnim* pSkeletonAnim = pCharInstance->GetISkeletonAnim()) { OldBlendSpace ap; if (GetAimBlending(ap)) { pSkeletonAnim->SetBlendSpaceOverride(eMotionParamID_TurnSpeed, 0.5f + 0.5f * ap.m_turn, true); } } } UpdateIKMounted(pActor, vGunXAxis*0.1f); RequireUpdate(eIUS_General); } }