BVB Source Codes

CRYENGINE Show MFXForceFeedbackFX.cpp Source code

Return Download CRYENGINE: download MFXForceFeedbackFX.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   MFXForceFeedbackEffect.h
  5. //  Version:     v1.00
  6. //  Created:     8/4/2010 by Benito Gangoso Rodriguez
  7. // -------------------------------------------------------------------------
  8. //  History:
  9. //
  10. ////////////////////////////////////////////////////////////////////////////
  11.  
  12. #include "StdAfx.h"
  13. #include "MFXForceFeedbackFX.h"
  14. #include "CryAction.h"
  15. #include "IForceFeedbackSystem.h"
  16.  
  17. CMFXForceFeedbackEffect::CMFXForceFeedbackEffect()
  18.         : CMFXEffectBase(eMFXPF_ForceFeedback)
  19. {
  20. }
  21.  
  22. CMFXForceFeedbackEffect::~CMFXForceFeedbackEffect()
  23. {
  24.  
  25. }
  26.  
  27. void CMFXForceFeedbackEffect::LoadParamsFromXml(const XmlNodeRef& paramsNode)
  28. {
  29.         // Xml data format
  30.         /*
  31.            <ForceFeedback name="..." minFallOffDistance="..." maxFallOffDistance="..." />
  32.          */
  33.         m_forceFeedbackParams.forceFeedbackEventName = paramsNode->getAttr("name");
  34.  
  35.         float minFallOffDistance = 0.0f;
  36.         paramsNode->getAttr("minFallOffDistance", minFallOffDistance);
  37.         float maxFallOffDistance = 5.0f;
  38.         paramsNode->getAttr("maxFallOffDistance", maxFallOffDistance);
  39.  
  40.         m_forceFeedbackParams.intensityFallOffMinDistanceSqr = minFallOffDistance * minFallOffDistance;
  41.         m_forceFeedbackParams.intensityFallOffMaxDistanceSqr = maxFallOffDistance * maxFallOffDistance;
  42. }
  43.  
  44. void CMFXForceFeedbackEffect::Execute(const SMFXRunTimeEffectParams& params)
  45. {
  46.         FUNCTION_PROFILER(gEnv->pSystem, PROFILE_ACTION);
  47.  
  48.         float distanceToPlayerSqr = FLT_MAX;
  49.         IActor* pClientActor = gEnv->pGameFramework->GetClientActor();
  50.         if (pClientActor)
  51.         {
  52.                 distanceToPlayerSqr = (pClientActor->GetEntity()->GetWorldPos() - params.pos).GetLengthSquared();
  53.         }
  54.  
  55.         const float testDistanceSqr = clamp_tpl(distanceToPlayerSqr, m_forceFeedbackParams.intensityFallOffMinDistanceSqr, m_forceFeedbackParams.intensityFallOffMaxDistanceSqr);
  56.         const float minMaxDiffSqr = m_forceFeedbackParams.intensityFallOffMaxDistanceSqr - m_forceFeedbackParams.intensityFallOffMinDistanceSqr;
  57.  
  58.         float effectIntensity = (float)__fsel(-minMaxDiffSqr, 0.0f, 1.0f - (testDistanceSqr - m_forceFeedbackParams.intensityFallOffMinDistanceSqr) / (minMaxDiffSqr + FLT_EPSILON));
  59.         effectIntensity *= effectIntensity;
  60.         if (effectIntensity > 0.01f)
  61.         {
  62.                 IForceFeedbackSystem* pForceFeedback = CCryAction::GetCryAction()->GetIForceFeedbackSystem();
  63.                 assert(pForceFeedback);
  64.                 ForceFeedbackFxId fxId = pForceFeedback->GetEffectIdByName(m_forceFeedbackParams.forceFeedbackEventName.c_str());
  65.                 pForceFeedback->PlayForceFeedbackEffect(fxId, SForceFeedbackRuntimeParams(effectIntensity, 0.0f));
  66.         }
  67. }
  68.  
  69. void CMFXForceFeedbackEffect::GetResources(SMFXResourceList& resourceList) const
  70. {
  71.         SMFXForceFeedbackListNode* listNode = SMFXForceFeedbackListNode::Create();
  72.         listNode->m_forceFeedbackParams.forceFeedbackEventName = m_forceFeedbackParams.forceFeedbackEventName.c_str();
  73.         listNode->m_forceFeedbackParams.intensityFallOffMinDistanceSqr = m_forceFeedbackParams.intensityFallOffMinDistanceSqr;
  74.         listNode->m_forceFeedbackParams.intensityFallOffMaxDistanceSqr = m_forceFeedbackParams.intensityFallOffMaxDistanceSqr;
  75.  
  76.         SMFXForceFeedbackListNode* next = resourceList.m_forceFeedbackList;
  77.  
  78.         if (!next)
  79.                 resourceList.m_forceFeedbackList = listNode;
  80.         else
  81.         {
  82.                 while (next->pNext)
  83.                         next = next->pNext;
  84.  
  85.                 next->pNext = listNode;
  86.         }
  87. }
  88.  
  89. void CMFXForceFeedbackEffect::GetMemoryUsage(ICrySizer* pSizer) const
  90. {
  91.         pSizer->Add(*this);
  92.         pSizer->Add(m_forceFeedbackParams.forceFeedbackEventName);
  93. }
  94.  
downloadMFXForceFeedbackFX.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