BVB Source Codes

CRYENGINE Show VehicleSeatActionOrientatePartToView.cpp Source code

Return Download CRYENGINE: download VehicleSeatActionOrientatePartToView.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 "IVehicleSystem.h"
  5. #include "Vehicle.h"
  6. #include "VehicleSeat.h"
  7. #include "VehicleSeatActionOrientatePartToView.h"
  8.  
  9. CVehicleSeatActionOrientatePartToView::CVehicleSeatActionOrientatePartToView()
  10.         : m_pSeat(NULL)
  11.         , m_pVehicle(NULL)
  12. {
  13. }
  14.  
  15. //------------------------------------------------------------------------
  16. bool CVehicleSeatActionOrientatePartToView::Init(IVehicle* pVehicle, IVehicleSeat* pSeat, const CVehicleParams& table)
  17. {
  18.         m_pVehicle = pVehicle;
  19.         m_pSeat = pSeat;
  20.  
  21.         CVehicleParams partsTable = table.findChild("Parts");
  22.  
  23.         if (partsTable)
  24.         {
  25.                 const int partCount = partsTable.getChildCount();
  26.  
  27.                 m_controlledParts.reserve(partCount);
  28.  
  29.                 for (int partIdx = 0; partIdx < partCount; ++partIdx)
  30.                 {
  31.                         CVehicleParams controlledPart = partsTable.getChild(partIdx);
  32.  
  33.                         if (!strcmp(controlledPart.getTag(), "Part"))
  34.                         {
  35.                                 const char* controlledPartName = controlledPart.getAttr("name");
  36.  
  37.                                 IVehiclePart* pControlledPart = m_pVehicle->GetPart(controlledPartName);
  38.                                 if (pControlledPart)
  39.                                 {
  40.                                         SOrientatePartInfo orientationPartInfo;
  41.                                         orientationPartInfo.partIndex = pControlledPart->GetIndex();
  42.                                         controlledPart.getAttr("orientationAxis", orientationPartInfo.orientationAxis);
  43.  
  44.                                         m_controlledParts.push_back(orientationPartInfo);
  45.  
  46.                                         pControlledPart->SetMoveable();
  47.                                 }
  48.                         }
  49.                 }
  50.         }
  51.  
  52.         return true;
  53. }
  54.  
  55. void CVehicleSeatActionOrientatePartToView::StartUsing(EntityId passengerId)
  56. {
  57.         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);
  58. }
  59.  
  60. void CVehicleSeatActionOrientatePartToView::StopUsing()
  61. {
  62.         m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
  63. }
  64.  
  65. void CVehicleSeatActionOrientatePartToView::Update(const float deltaTime)
  66. {
  67.         const Vec3 viewDirection = GetViewDirection();
  68.  
  69.         for (TPartIndices::const_iterator partCit = m_controlledParts.begin(); partCit != m_controlledParts.end(); ++partCit)
  70.         {
  71.                 IVehiclePart* pPart = m_pVehicle->GetPart((unsigned int)partCit->partIndex);
  72.                 IVehiclePart* pParentPart = pPart ? pPart->GetParent() : NULL;
  73.                 if (pPart && pParentPart)
  74.                 {
  75.                         const Matrix34& baseTM = pPart->GetLocalBaseTM();
  76.                         Ang3 currentBaseAngles(baseTM);
  77.                         const Vec3 orientationAxis = partCit->orientationAxis;
  78.                         const Vec3 localViewDirection = pParentPart->GetWorldTM().GetInverted().TransformVector(viewDirection);
  79.  
  80.                         Ang3 newBaseAngles(Quat::CreateRotationVDir(localViewDirection, 0.0f));
  81.                         newBaseAngles.x = newBaseAngles.x * orientationAxis.x;
  82.                         newBaseAngles.y = newBaseAngles.y * orientationAxis.y;
  83.                         newBaseAngles.z = newBaseAngles.z * orientationAxis.z;
  84.  
  85.                         Interpolate(currentBaseAngles, newBaseAngles, 5.0f, deltaTime, 0.01f);
  86.  
  87.                         Matrix34 newBaseTM;
  88.                         newBaseTM.SetRotationXYZ(newBaseAngles);
  89.                         newBaseTM.SetTranslation(baseTM.GetTranslation());
  90.                         pPart->SetLocalBaseTM(newBaseTM);
  91.  
  92.                         //const Vec3 partPos = pPart->GetWorldTM().GetTranslation();
  93.                         //gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(partPos, ColorB(0,255,0), partPos + (viewDirection * 3.0f), ColorB(0, 255, 0), 3.0f);
  94.                 }
  95.         }
  96. }
  97.  
  98. Vec3 CVehicleSeatActionOrientatePartToView::GetViewDirection() const
  99. {
  100.         IActor* pPassenger = gEnv->pGameFramework->GetIActorSystem()->GetActor(m_pSeat->GetPassenger());
  101.         IMovementController* pPassengerMC = pPassenger ? pPassenger->GetMovementController() : NULL;
  102.  
  103.         if (pPassengerMC)
  104.         {
  105.                 SMovementState movementState;
  106.                 pPassengerMC->GetMovementState(movementState);
  107.  
  108.                 return movementState.aimDirection;
  109.         }
  110.  
  111.         return m_pVehicle->GetEntity()->GetWorldTM().GetColumn1();
  112. }
  113.  
  114. void CVehicleSeatActionOrientatePartToView::GetMemoryUsage(ICrySizer* s) const
  115. {
  116.         s->AddObject(this, sizeof(*this));
  117.         s->AddContainer(m_controlledParts);
  118. }
  119.  
  120. DEFINE_VEHICLEOBJECT(CVehicleSeatActionOrientatePartToView);
  121.  
downloadVehicleSeatActionOrientatePartToView.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