BVB Source Codes

CRYENGINE Show FirstPersonHandIKContext.cpp Source code

Return Download CRYENGINE: download FirstPersonHandIKContext.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. //
  4. ////////////////////////////////////////////////////////////////////////////
  5. #include "StdAfx.h"
  6. #include <CryExtension/CryCreateClassInstance.h>
  7. #include "FirstPersonHandIKContext.h"
  8.  
  9. CFirstPersonHandIKContext::SParams::SParams()
  10.         : m_weaponTargetIdx(-1)
  11.         , m_leftHandTargetIdx(-1)
  12.         , m_rightBlendIkIdx(-1)
  13. {
  14. }
  15.  
  16. CFirstPersonHandIKContext::SParams::SParams(IDefaultSkeleton* pIDefaultSkeleton)
  17. {
  18.         m_weaponTargetIdx = pIDefaultSkeleton->GetJointIDByName("Bip01 RHand2RiflePos_IKTarget");
  19.         m_leftHandTargetIdx = pIDefaultSkeleton->GetJointIDByName("Bip01 LHand2Weapon_IKTarget");
  20.         m_rightBlendIkIdx = pIDefaultSkeleton->GetJointIDByName("Bip01 RHand2RiflePos_IKBlend");
  21.  
  22.         assert(m_weaponTargetIdx != -1);
  23.         assert(m_leftHandTargetIdx != -1);
  24.         assert(m_rightBlendIkIdx != -1);
  25. }
  26.  
  27. CFirstPersonHandIKContext::CFirstPersonHandIKContext()
  28.         : m_pCharacterInstance(0)
  29.         , m_rightOffset(IDENTITY)
  30.         , m_leftOffset(IDENTITY)
  31.         , m_aimDirection(1.0f, 0.0f, 0.0f)
  32.         , m_instanceCount(0)
  33. {
  34. }
  35.  
  36. void CFirstPersonHandIKContext::Initialize(ICharacterInstance* pCharacterInstance)
  37. {
  38.         ++m_instanceCount;
  39.  
  40.         if (m_pCharacterInstance != 0)
  41.                 return;
  42.  
  43.         m_pCharacterInstance = pCharacterInstance;
  44.         CryCreateClassInstance("AnimationPoseModifier_OperatorQueue", m_pPoseModifier);
  45.         m_params = SParams(&m_pCharacterInstance->GetIDefaultSkeleton());
  46. }
  47.  
  48. void CFirstPersonHandIKContext::Finalize()
  49. {
  50.         --m_instanceCount;
  51.         CRY_ASSERT(m_instanceCount >= 0);
  52. }
  53.  
  54. void CFirstPersonHandIKContext::Update(float timePassed)
  55. {
  56.         if (m_instanceCount <= 0)
  57.                 return;
  58.  
  59.         m_pCharacterInstance->GetISkeletonAnim()->PushPoseModifier(15, m_pPoseModifier, "FirstPersonHandIKContext");
  60.  
  61.         const IAnimationOperatorQueue::EOp set = IAnimationOperatorQueue::eOp_Override;
  62.         const IAnimationOperatorQueue::EOp additive = IAnimationOperatorQueue::eOp_Additive;
  63.  
  64.         int16 blendParentId = m_pCharacterInstance->GetIDefaultSkeleton().GetJointParentIDByID(m_params.m_rightBlendIkIdx);
  65.         QuatT absBlendParentPose = m_pCharacterInstance->GetISkeletonPose()->GetAbsJointByID(blendParentId);
  66.         Vec3 relBlandPos = Vec3(1.0f, 0.0f, 0.0f);
  67.         m_pPoseModifier->PushPosition(m_params.m_rightBlendIkIdx, set, absBlendParentPose * relBlandPos);
  68.  
  69.         Quat view = Quat::CreateRotationVDir(m_aimDirection);
  70.         Quat invView = view.GetInverted();
  71.  
  72.         QuatT rightHand = QuatT(IDENTITY);
  73.         rightHand.t = view * m_rightOffset.t;
  74.         rightHand.q = view * (m_rightOffset.q * invView);
  75.         m_pPoseModifier->PushPosition(m_params.m_weaponTargetIdx, additive, rightHand.t);
  76.         m_pPoseModifier->PushOrientation(m_params.m_weaponTargetIdx, additive, rightHand.q);
  77.  
  78.         QuatT leftHand = QuatT(IDENTITY);
  79.         leftHand.t = view * m_leftOffset.t;
  80.         leftHand.q = view * (m_leftOffset.q * invView);
  81.         m_pPoseModifier->PushPosition(m_params.m_leftHandTargetIdx, additive, leftHand.t);
  82.         m_pPoseModifier->PushOrientation(m_params.m_leftHandTargetIdx, additive, leftHand.q);
  83.  
  84.         m_rightOffset = QuatT(IDENTITY);
  85.         m_leftOffset = QuatT(IDENTITY);
  86. }
  87.  
  88. void CFirstPersonHandIKContext::SetAimDirection(Vec3 aimDirection)
  89. {
  90.         m_aimDirection = aimDirection;
  91. }
  92.  
  93. void CFirstPersonHandIKContext::AddRightOffset(QuatT offset)
  94. {
  95.         m_rightOffset = m_rightOffset * offset;
  96. }
  97.  
  98. void CFirstPersonHandIKContext::AddLeftOffset(QuatT offset)
  99. {
  100.         m_leftOffset = m_leftOffset * offset;
  101. }
  102.  
  103. CRYREGISTER_CLASS(CFirstPersonHandIKContext);
  104.  
downloadFirstPersonHandIKContext.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top