BVB Source Codes

CRYENGINE Show VehicleSeatActionPassengerIK.cpp Source code

Return Download CRYENGINE: download VehicleSeatActionPassengerIK.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description: Implements a seat action to handle IK on the passenger body
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 10:01:2006: Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15. #include "CryAction.h"
  16. #include "IActorSystem.h"
  17. #include "IVehicleSystem.h"
  18. #include "Vehicle.h"
  19. #include "VehicleSeatActionPassengerIK.h"
  20.  
  21. #include <CryRenderer/IRenderAuxGeom.h>
  22.  
  23. //------------------------------------------------------------------------
  24. bool CVehicleSeatActionPassengerIK::Init(IVehicle* pVehicle, IVehicleSeat* pSeat, const CVehicleParams& table)
  25. {
  26.         m_pVehicle = pVehicle;
  27.         m_passengerId = 0;
  28.  
  29.         CVehicleParams ikTable = table.findChild("PassengerIK");
  30.         if (!ikTable)
  31.                 return false;
  32.  
  33.         CVehicleParams limbsTable = ikTable.findChild("Limbs");
  34.         if (!limbsTable)
  35.                 return false;
  36.  
  37.         if (!ikTable.getAttr("waitShortlyBeforeStarting", m_waitShortlyBeforeStarting))
  38.                 m_waitShortlyBeforeStarting = false;
  39.  
  40.         int i = 0;
  41.         int c = limbsTable.getChildCount();
  42.         m_ikLimbs.reserve(c);
  43.  
  44.         for (; i < c; i++)
  45.         {
  46.                 if (CVehicleParams limbTable = limbsTable.getChild(i))
  47.                 {
  48.                         SIKLimb limb;
  49.  
  50.                         if (limbTable.haveAttr("limb"))
  51.                         {
  52.                                 limb.limbName = limbTable.getAttr("limb");
  53.                                 if (limbTable.haveAttr("helper"))
  54.                                 {
  55.                                         if (limb.pHelper = m_pVehicle->GetHelper(limbTable.getAttr("helper")))
  56.                                                 m_ikLimbs.push_back(limb);
  57.                                 }
  58.                         }
  59.                 }
  60.         }
  61.  
  62.         return !m_ikLimbs.empty();
  63. }
  64.  
  65. //------------------------------------------------------------------------
  66. void CVehicleSeatActionPassengerIK::Reset()
  67. {
  68.  
  69. }
  70.  
  71. //------------------------------------------------------------------------
  72. void CVehicleSeatActionPassengerIK::StartUsing(EntityId passengerId)
  73. {
  74.         m_passengerId = passengerId;
  75.  
  76.         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_Visible);
  77. }
  78.  
  79. //------------------------------------------------------------------------
  80. void CVehicleSeatActionPassengerIK::StopUsing()
  81. {
  82.         m_passengerId = 0;
  83.  
  84.         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
  85. }
  86.  
  87. //------------------------------------------------------------------------
  88. void CVehicleSeatActionPassengerIK::Update(float frameTime)
  89. {
  90.         if (!m_passengerId)
  91.                 return;
  92.  
  93.         IActor* pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(m_passengerId);
  94.         if (!pActor)
  95.         {
  96.                 CRY_ASSERT(!"Invalid entity id for the actor id, Actor System didn't know it");
  97.                 return;
  98.         }
  99.  
  100.         if (ICharacterInstance* pCharInstance = pActor->GetEntity()->GetCharacter(0))
  101.         {
  102.                 ISkeletonAnim* pSkeletonAnim = pCharInstance->GetISkeletonAnim();
  103.                 CRY_ASSERT(pSkeletonAnim);
  104.  
  105.                 if (pSkeletonAnim->GetNumAnimsInFIFO(0) >= 1)
  106.                 {
  107.                         const CAnimation& anim = pSkeletonAnim->GetAnimFromFIFO(0, 0);
  108.                         const uint16 loopCount = anim.GetLoop();
  109.                         const f32 animationTime = pSkeletonAnim->GetAnimationNormalizedTime(&anim);
  110.                         if (!m_waitShortlyBeforeStarting || (loopCount > 0 || animationTime > 0.9f))
  111.                         {
  112.                                 for (TIKLimbVector::iterator ite = m_ikLimbs.begin(); ite != m_ikLimbs.end(); ++ite)
  113.                                 {
  114.                                         const SIKLimb& limb = *ite;
  115.  
  116.                                         Vec3 helperPos = limb.pHelper->GetWorldSpaceTranslation();
  117.                                         pActor->SetIKPos(limb.limbName.c_str(), helperPos, 1);
  118.                                 }
  119.                         }
  120.                 }
  121.         }
  122.  
  123. }
  124.  
  125. void CVehicleSeatActionPassengerIK::GetMemoryUsage(ICrySizer* s) const
  126. {
  127.         s->Add(*this);
  128.         s->AddObject(m_ikLimbs);
  129. }
  130.  
  131. DEFINE_VEHICLEOBJECT(CVehicleSeatActionPassengerIK);
  132.  
downloadVehicleSeatActionPassengerIK.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