BVB Source Codes

CRYENGINE Show VehicleViewThirdPerson_Bone.cpp Source code

Return Download CRYENGINE: download VehicleViewThirdPerson_Bone.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "VehicleViewThirdPerson_Bone.h"
  5.  
  6. const char* CVehicleViewThirdPersonBone::m_name = "ThirdPersonBone";
  7.  
  8. CVehicleViewThirdPersonBone::CVehicleViewThirdPersonBone() : m_directionBoneId(-1), m_offset(0.f, 0.f, 0.f), m_distance(0.f), m_position(ZERO), m_baseRotation(ZERO)
  9. {
  10.         m_additionalRotation.SetIdentity();
  11. }
  12.  
  13. CVehicleViewThirdPersonBone::~CVehicleViewThirdPersonBone()
  14. {
  15.  
  16. }
  17.  
  18. bool CVehicleViewThirdPersonBone::Init(IVehicleSeat* pSeat, const CVehicleParams& table)
  19. {
  20.         if (!CVehicleViewBase::Init(pSeat, table))
  21.                 return false;
  22.  
  23.         if (ICharacterInstance* pCharacterInstance = m_pVehicle->GetEntity()->GetCharacter(0))
  24.         {
  25.                 IDefaultSkeleton& rIDefaultSkeleton = pCharacterInstance->GetIDefaultSkeleton();
  26.                 {
  27.                         if (table.haveAttr("DirectionBone"))
  28.                         {
  29.                                 const char* boneName = table.getAttr("DirectionBone");
  30.                                 m_directionBoneId = rIDefaultSkeleton.GetJointIDByName(boneName);
  31.                         }
  32.  
  33.                         if (CVehicleParams paramsTable = table.findChild(m_name))
  34.                         {
  35.                                 if (paramsTable.haveAttr("rotation"))
  36.                                 {
  37.                                         Vec3 angles;
  38.                                         paramsTable.getAttr("rotation", angles);
  39.                                         angles *= gf_PI / 180.0f;
  40.  
  41.                                         m_additionalRotation.SetRotationXYZ((Ang3)angles);
  42.                                 }
  43.  
  44.                                 paramsTable.getAttr("offset", m_offset);
  45.                                 paramsTable.getAttr("distance", m_distance);
  46.                         }
  47.                 }
  48.         }
  49.  
  50.         return true;
  51. }
  52.  
  53. void CVehicleViewThirdPersonBone::OnAction(const TVehicleActionId actionId, int activationMode, float value)
  54. {
  55.         //ToDo: Zoom
  56. }
  57.  
  58. void CVehicleViewThirdPersonBone::UpdateView(SViewParams& viewParams, EntityId playerId)
  59. {
  60.         viewParams.position = m_position;
  61.         viewParams.rotation = m_baseRotation;
  62.  
  63.         IActor* pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(playerId);
  64.         if (pActor && pActor->IsClient())
  65.         {
  66.                 pActor->SetViewInVehicle(viewParams.rotation);
  67.         }
  68. }
  69.  
  70. void CVehicleViewThirdPersonBone::OnStartUsing(EntityId passengerId)
  71. {
  72.         CVehicleViewBase::OnStartUsing(passengerId);
  73. }
  74.  
  75. void CVehicleViewThirdPersonBone::Update(const float frameTime)
  76. {
  77.         CVehicleViewBase::Update(frameTime);
  78.  
  79.         IEntity* pVehicleEntity = m_pVehicle->GetEntity();
  80.         const Matrix34& rWorldTM = pVehicleEntity->GetWorldTM();
  81.  
  82.         QuatT worldRot(rWorldTM);
  83.         Vec3 worldPos(ZERO);
  84.  
  85.         Vec3 vTotalOffset = m_offset;
  86.         vTotalOffset.y -= m_distance;
  87.  
  88.         if (ICharacterInstance* pCharacterInstance = pVehicleEntity->GetCharacter(0))
  89.         {
  90.                 ISkeletonPose* pSkeletonPose = pCharacterInstance->GetISkeletonPose();
  91.                 if (pSkeletonPose)
  92.                 {
  93.                         const QuatT& rJointWorld = pSkeletonPose->GetAbsJointByID(m_directionBoneId);
  94.                         worldRot = (worldRot * rJointWorld * QuatT(m_additionalRotation, Vec3(ZERO)));
  95.                         worldPos = worldRot * vTotalOffset;
  96.                 }
  97.         }
  98.  
  99.         m_position = worldPos;
  100.         m_baseRotation = worldRot.q;
  101. }
  102.  
  103. //------------------------------------------------------------------------
  104. void CVehicleViewThirdPersonBone::OffsetPosition(const Vec3& delta)
  105. {
  106. #ifdef SEG_WORLD
  107.         m_position += delta;
  108. #endif
  109. }
  110.  
  111. DEFINE_VEHICLEOBJECT(CVehicleViewThirdPersonBone);
  112.  
downloadVehicleViewThirdPerson_Bone.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