BVB Source Codes

CRYENGINE Show VehiclePartStatic.cpp Source code

Return Download CRYENGINE: download VehiclePartStatic.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 uses static objects
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 23:08:2005: Created by Mathieu Pinard
  12.  
  13. *************************************************************************/
  14. #include "StdAfx.h"
  15.  
  16. #include <CryAnimation/ICryAnimation.h>
  17. #include "IVehicleSystem.h"
  18.  
  19. #include "CryAction.h"
  20. #include "Vehicle.h"
  21. #include "VehiclePartBase.h"
  22. #include "VehiclePartStatic.h"
  23.  
  24. //------------------------------------------------------------------------
  25. bool CVehiclePartStatic::Init(IVehicle* pVehicle, const CVehicleParams& table, IVehiclePart* parent, CVehicle::SPartInitInfo& initInfo, int partType)
  26. {
  27.         if (!CVehiclePartBase::Init(pVehicle, table, parent, initInfo, eVPT_Static))
  28.                 return false;
  29.  
  30.         CVehicleParams staticTable = table.findChild("Static");
  31.         if (!staticTable)
  32.                 return false;
  33.  
  34.         if (!staticTable.haveAttr("filename"))
  35.                 return false;
  36.  
  37.         m_filename = staticTable.getAttr("filename");
  38.         m_filenameDestroyed = staticTable.getAttr("filenameDestroyed");
  39.         m_geometry = staticTable.getAttr("geometry");
  40.  
  41.         InitGeometry();
  42.  
  43.         m_state = eVGS_Default;
  44.  
  45.         return true;
  46. }
  47.  
  48. //------------------------------------------------------------------------
  49. void CVehiclePartStatic::Release()
  50. {
  51.         if (m_slot != -1)
  52.                 m_pVehicle->GetEntity()->FreeSlot(m_slot);
  53.  
  54.         CVehiclePartBase::Release();
  55. }
  56.  
  57. //------------------------------------------------------------------------
  58. void CVehiclePartStatic::Reset()
  59. {
  60.         CVehiclePartBase::Reset();
  61. }
  62.  
  63. //------------------------------------------------------------------------
  64. void CVehiclePartStatic::InitGeometry()
  65. {
  66.         if (m_pSharedParameters->m_isPhysicalized && m_slot > -1)
  67.                 GetEntity()->UnphysicalizeSlot(m_slot);
  68.  
  69.         m_slot = GetEntity()->LoadGeometry(m_slot, m_filename, m_geometry);
  70.  
  71.         if (IStatObj* pStatObj = GetEntity()->GetStatObj(m_slot))
  72.         {
  73.                 if (m_hideCount == 0)
  74.                         GetEntity()->SetSlotFlags(m_slot, GetEntity()->GetSlotFlags(m_slot) | ENTITY_SLOT_RENDER);
  75.                 else
  76.                         GetEntity()->SetSlotFlags(m_slot, GetEntity()->GetSlotFlags(m_slot) & ~(ENTITY_SLOT_RENDER | ENTITY_SLOT_RENDER_NEAREST));
  77.         }
  78.  
  79.         if (!m_pSharedParameters->m_helperPosName.empty())
  80.         {
  81.                 if (IVehicleHelper* pHelper = m_pVehicle->GetHelper(m_pSharedParameters->m_helperPosName))
  82.                 {
  83.                         Matrix34 tm;
  84.                         pHelper->GetVehicleTM(tm);
  85.                         GetEntity()->SetSlotLocalTM(m_slot, tm);
  86.                 }
  87.         }
  88.  
  89.         if (m_pParentPart)
  90.         {
  91.                 CVehiclePartBase* pAttachToPart = (CVehiclePartBase*) m_pParentPart;
  92.  
  93.                 IEntity* pEntity = pAttachToPart->GetEntity();
  94.                 if (pEntity == GetEntity())
  95.                 {
  96.                         const Matrix34& pParentTM = GetEntity()->GetSlotLocalTM(pAttachToPart->GetSlot(), false);
  97.                         const Matrix34& pChildTM = GetEntity()->GetSlotLocalTM(m_slot, false);
  98.  
  99.                         GetEntity()->SetSlotLocalTM(m_slot, pParentTM.GetInverted() * pChildTM);
  100.                         GetEntity()->SetParentSlot(pAttachToPart->GetSlot(), m_slot);
  101.                 }
  102.         }
  103. }
  104.  
  105. //------------------------------------------------------------------------
  106. void CVehiclePartStatic::Physicalize()
  107. {
  108.         if (m_pSharedParameters->m_isPhysicalized)
  109.         {
  110.                 SEntityPhysicalizeParams params;
  111.                 params.mass = m_pSharedParameters->m_mass;
  112.                 params.density = m_pSharedParameters->m_density;
  113.                 params.nSlot = m_slot;
  114.                 m_physId = GetEntity()->PhysicalizeSlot(m_slot, params);
  115.  
  116.                 CheckColltypeHeavy(m_physId);
  117.         }
  118.         else if (m_slot != -1)
  119.         {
  120.                 GetEntity()->UnphysicalizeSlot(m_slot);
  121.         }
  122.  
  123.         GetEntity()->SetSlotFlags(m_slot, GetEntity()->GetSlotFlags(m_slot) | ENTITY_SLOT_IGNORE_PHYSICS);
  124. }
  125.  
  126. //------------------------------------------------------------------------
  127. void CVehiclePartStatic::Update(const float frameTime)
  128. {
  129.         CVehiclePartBase::Update(frameTime);
  130.  
  131. #if ENABLE_VEHICLE_DEBUG
  132.         if (IsDebugParts())
  133.         {
  134.                 //VehicleUtils::DrawTM(GetWorldTM());
  135.         }
  136. #endif
  137. }
  138.  
  139. //------------------------------------------------------------------------
  140. void CVehiclePartStatic::SetLocalTM(const Matrix34& localTM)
  141. {
  142.         CVehiclePartBase::SetLocalTM(localTM);
  143.  
  144.         // invalidate, entitysystem doesn't immediately update children otherwise
  145.         GetEntity()->InvalidateTM();
  146. }
  147.  
  148. DEFINE_VEHICLEOBJECT(CVehiclePartStatic);
  149.  
downloadVehiclePartStatic.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