BVB Source Codes

CRYENGINE Show VehiclePartPulsingLight.cpp Source code

Return Download CRYENGINE: download VehiclePartPulsingLight.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 "VehiclePartPulsingLight.h"
  5.  
  6. CVehiclePartPulsingLight::CVehiclePartPulsingLight()
  7.         : m_colorMult(0.f)
  8.         , m_minColorMult(0.f)
  9.         , m_currentColorMultSpeed(0.f)
  10.         , m_colorMultSpeed(0.f)
  11.         , m_colorMultSpeedStageTwo(0.f)
  12.         , m_toggleOnMinDamageRatio(0.f)
  13.         , m_toggleStageTwoMinDamageRatio(0.f)
  14.         , m_colorChangeTimer(0.f)
  15. {
  16. }
  17.  
  18. bool CVehiclePartPulsingLight::Init(IVehicle* pVehicle, const CVehicleParams& table, IVehiclePart* parent, CVehicle::SPartInitInfo& initInfo, int partType)
  19. {
  20.         if (!CVehiclePartLight::Init(pVehicle, table, parent, initInfo, eVPT_Light))
  21.                 return false;
  22.  
  23.         if (CVehicleParams lightTable = table.findChild("PulsingLight"))
  24.         {
  25.                 lightTable.getAttr("minColorMult", m_minColorMult);
  26.                 lightTable.getAttr("toggleOnMinDamageRatio", m_toggleOnMinDamageRatio);
  27.                 lightTable.getAttr("colorMultSpeed", m_colorMultSpeed);
  28.                 lightTable.getAttr("toggleStageTwoMinDamageRatio", m_toggleStageTwoMinDamageRatio);
  29.                 lightTable.getAttr("colorMultSpeedStageTwo", m_colorMultSpeedStageTwo);
  30.         }
  31.  
  32.         return true;
  33. }
  34.  
  35. void CVehiclePartPulsingLight::UpdateLight(const float frameTime)
  36. {
  37.         CVehiclePartLight::UpdateLight(frameTime);
  38.  
  39.         SEntitySlotInfo info;
  40.         if (m_pVehicle->GetEntity()->GetSlotInfo(m_slot, info) && info.pLight)
  41.         {
  42.                 float fNewColorTimer = m_colorChangeTimer + (frameTime * m_currentColorMultSpeed);
  43.  
  44.                 float timerScaledToWavelength = fNewColorTimer * gf_PI;
  45.                 timerScaledToWavelength = (float)__fsel(timerScaledToWavelength - gf_PI2, timerScaledToWavelength - gf_PI2, timerScaledToWavelength);
  46.  
  47.                 m_colorMult = sinf(timerScaledToWavelength) * 0.5f + 0.5f;
  48.  
  49.                 m_colorMult *= 1.0f - m_minColorMult;
  50.                 m_colorMult += m_minColorMult;
  51.                 m_colorChangeTimer = fNewColorTimer;
  52.  
  53.                 CDLight& light = info.pLight->GetLightProperties();
  54.                 light.SetLightColor(ColorF(m_diffuseCol * m_diffuseMult[0] * m_colorMult));
  55.         }
  56. }
  57.  
  58. void CVehiclePartPulsingLight::ToggleLight(bool enable)
  59. {
  60.         CVehiclePartLight::ToggleLight(enable);
  61.  
  62.         if (enable)
  63.         {
  64.                 m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);
  65.         }
  66. }
  67.  
  68. void CVehiclePartPulsingLight::OnEvent(const SVehiclePartEvent& event)
  69. {
  70.         if (event.type == eVPE_Damaged)
  71.         {
  72.                 if (event.fparam < 1.0f)
  73.                 {
  74.                         if (m_toggleOnMinDamageRatio && !IsEnabled() && event.fparam >= m_toggleOnMinDamageRatio)
  75.                         {
  76.                                 ToggleLight(true);
  77.                                 m_currentColorMultSpeed = m_colorMultSpeed;
  78.                         }
  79.                         else if (m_toggleStageTwoMinDamageRatio && event.fparam >= m_toggleStageTwoMinDamageRatio)
  80.                         {
  81.                                 m_currentColorMultSpeed = m_colorMultSpeedStageTwo;
  82.                         }
  83.                 }
  84.                 else //fParam >= 1.f (Vehicle destroyed)
  85.                 {
  86.                         ToggleLight(false);
  87.                 }
  88.         }
  89.  
  90.         CVehiclePartLight::OnEvent(event);
  91. }
  92.  
  93. DEFINE_VEHICLEOBJECT(CVehiclePartPulsingLight);
  94.  
downloadVehiclePartPulsingLight.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