BVB Source Codes

CRYENGINE Show VehiclePartAttachment.cpp Source code

Return Download CRYENGINE: download VehiclePartAttachment.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 part for vehicles which is the an attachment
  8.    of a parent Animated part
  9.  
  10.    -------------------------------------------------------------------------
  11.    History:
  12.    - 25:08:2005: Created by Mathieu Pinard
  13.  
  14. *************************************************************************/
  15. #include "StdAfx.h"
  16.  
  17. #include <CryAnimation/ICryAnimation.h>
  18. #include "IVehicleSystem.h"
  19.  
  20. #include "CryAction.h"
  21. #include "Vehicle.h"
  22. #include "VehiclePartBase.h"
  23. #include "VehiclePartAnimated.h"
  24. #include "VehiclePartAttachment.h"
  25. #include "VehicleUtils.h"
  26.  
  27. //------------------------------------------------------------------------
  28. bool CVehiclePartEntityAttachment::Init(IVehicle* pVehicle, const CVehicleParams& table, IVehiclePart* parent, CVehicle::SPartInitInfo& initInfo, int partType)
  29. {
  30.         if (!CVehiclePartBase::Init(pVehicle, table, parent, initInfo, eVPT_Attachment))
  31.                 return false;
  32.  
  33.         m_attachmentId = 0;
  34.         m_localTM.SetIdentity();
  35.         m_worldTM.SetIdentity();
  36.  
  37.         return true;
  38. }
  39.  
  40. //------------------------------------------------------------------------
  41. void CVehiclePartEntityAttachment::PostInit()
  42. {
  43.         if (!m_pSharedParameters->m_helperPosName.empty())
  44.         {
  45.                 if (IVehicleHelper* pHelper = m_pVehicle->GetHelper(m_pSharedParameters->m_helperPosName))
  46.                         SetLocalTM(pHelper->GetLocalTM());
  47.                 else
  48.                 {
  49.                         Matrix34 tm(IDENTITY);
  50.                         SetLocalTM(tm);
  51.                 }
  52.         }
  53. }
  54.  
  55. //------------------------------------------------------------------------
  56. void CVehiclePartEntityAttachment::Update(const float frameTime)
  57. {
  58.         CVehiclePartBase::Update(frameTime);
  59.  
  60.         UpdateAttachment();
  61. }
  62.  
  63. //------------------------------------------------------------------------
  64. const Matrix34& CVehiclePartEntityAttachment::GetLocalTM(bool relativeToParentPart, bool forced)
  65. {
  66.         if (relativeToParentPart)
  67.                 return m_localTM;
  68.         else
  69.         {
  70.                 const Matrix34& tm = LocalToVehicleTM(m_localTM);
  71.                 return VALIDATE_MAT(tm);
  72.         }
  73. }
  74.  
  75. //------------------------------------------------------------------------
  76. const Matrix34& CVehiclePartEntityAttachment::GetWorldTM()
  77. {
  78.         const Matrix34& tm = GetLocalTM(false);
  79.         m_worldTM = GetEntity()->GetWorldTM() * tm;
  80.  
  81.         return VALIDATE_MAT(m_worldTM);
  82. }
  83.  
  84. //------------------------------------------------------------------------
  85. void CVehiclePartEntityAttachment::SetLocalTM(const Matrix34& localTM)
  86. {
  87.         m_localTM = VALIDATE_MAT(localTM);
  88.  
  89.         UpdateAttachment();
  90. }
  91.  
  92. //------------------------------------------------------------------------
  93. const AABB& CVehiclePartEntityAttachment::GetLocalBounds()
  94. {
  95.         IEntity* pEntity = GetAttachmentEntity();
  96.  
  97.         if (pEntity)
  98.         {
  99.                 pEntity->GetLocalBounds(m_bounds);
  100.         }
  101.         else
  102.         {
  103.                 m_bounds.Reset();
  104.         }
  105.  
  106.         return m_bounds;
  107. }
  108.  
  109. //------------------------------------------------------------------------
  110. IEntity* CVehiclePartEntityAttachment::GetAttachmentEntity()
  111. {
  112.         if (0 == m_attachmentId)
  113.                 return 0;
  114.  
  115.         return gEnv->pEntitySystem->GetEntity(m_attachmentId);
  116. }
  117.  
  118. //------------------------------------------------------------------------
  119. void CVehiclePartEntityAttachment::UpdateAttachment()
  120. {
  121.         IEntity* pEntity = GetAttachmentEntity();
  122.  
  123.         if (pEntity)
  124.         {
  125.                 const Matrix34& vehicleTM = GetLocalTM(false);
  126.                 pEntity->SetLocalTM(vehicleTM);
  127.  
  128. #if ENABLE_VEHICLE_DEBUG
  129.                 if (IsDebugParts())
  130.                 {
  131.                         VehicleUtils::DrawTM(GetWorldTM());
  132.                 }
  133. #endif
  134.         }
  135. }
  136.  
  137. //------------------------------------------------------------------------
  138. void CVehiclePartEntityAttachment::DetachAttachment()
  139. {
  140.         if (m_attachmentId)
  141.                 m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
  142.  
  143.         IEntity* pEntity = GetAttachmentEntity();
  144.  
  145.         if (pEntity)
  146.         {
  147.                 pEntity->DetachThis();
  148.         }
  149.  
  150.         m_attachmentId = 0;
  151. }
  152.  
  153. //------------------------------------------------------------------------
  154. void CVehiclePartEntityAttachment::SetAttachmentEntity(EntityId entityId)
  155. {
  156.         DetachAttachment();
  157.  
  158.         IEntity* pEntity = gEnv->pEntitySystem->GetEntity(entityId);
  159.  
  160.         if (!pEntity)
  161.                 return;
  162.  
  163.         m_attachmentId = entityId;
  164.         m_pVehicle->GetEntity()->AttachChild(pEntity);
  165.  
  166.         UpdateAttachment();
  167.  
  168.         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);
  169. }
  170.  
  171. DEFINE_VEHICLEOBJECT(CVehiclePartEntityAttachment);
  172.  
downloadVehiclePartAttachment.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