BVB Source Codes

CRYENGINE Show FlowNodeStereoparameters.cpp Source code

Return Download CRYENGINE: download FlowNodeStereoparameters.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.  
  5. #include <CryFlowGraph/IFlowBaseNode.h>
  6.  
  7. //////////////////////////////////////////////////////////////////////////
  8. class CFlowNode_ReadStereoParameters : public CFlowBaseNode<eNCT_Singleton>
  9. {
  10. public:
  11.         enum EInputs
  12.         {
  13.                 EIP_Read,
  14.                 EIP_Stop,
  15.         };
  16.  
  17.         enum EOutputs
  18.         {
  19.                 EOP_CurrentEyeDistance,
  20.                 EOP_CurrentScreenDistance,
  21.                 EOP_CurrentHUDDistance,
  22.                 EOP_Flipped,
  23.         };
  24.  
  25.         CFlowNode_ReadStereoParameters(SActivationInfo* activationInfo)
  26.         {
  27.         };
  28.  
  29.         virtual void GetConfiguration(SFlowNodeConfig& config)
  30.         {
  31.                 static const SInputPortConfig in_config[] = {
  32.                         InputPortConfig_Void("Read", _HELP("Starts reading stereo values")),
  33.                         InputPortConfig_Void("Stop", _HELP("Stops reading stereo values")),
  34.                         { 0 }
  35.                 };
  36.  
  37.                 static const SOutputPortConfig out_config[] = {
  38.                         OutputPortConfig<float>("EyeDistance",    _HELP("Current value of eye distance")),
  39.                         OutputPortConfig<float>("ScreenDistance", _HELP("Current value of screen distance")),
  40.                         OutputPortConfig<float>("HUDDistance",    _HELP("Current value of HUD distance")),
  41.                         OutputPortConfig<bool>("Flipped",         _HELP("Is stereo flipped?")),
  42.                         { 0 }
  43.                 };
  44.  
  45.                 config.pInputPorts = in_config;
  46.                 config.pOutputPorts = out_config;
  47.                 config.SetCategory(EFLN_ADVANCED);
  48.         }
  49.  
  50.         virtual void ProcessEvent(EFlowEvent event, SActivationInfo* activationInfo)
  51.         {
  52.                 switch (event)
  53.                 {
  54.                 case eFE_Initialize:
  55.                         activationInfo->pGraph->SetRegularlyUpdated(activationInfo->myID, false);
  56.                         break;
  57.  
  58.                 case eFE_Activate:
  59.                         if (IsPortActive(activationInfo, EIP_Read))
  60.                                 activationInfo->pGraph->SetRegularlyUpdated(activationInfo->myID, true);
  61.                         if (IsPortActive(activationInfo, EIP_Stop))
  62.                                 activationInfo->pGraph->SetRegularlyUpdated(activationInfo->myID, false);
  63.                         break;
  64.  
  65.                 case eFE_Update:
  66.                         ActivateOutput(activationInfo, EOP_CurrentEyeDistance, gEnv->pConsole->GetCVar("r_StereoEyeDist")->GetFVal());
  67.                         ActivateOutput(activationInfo, EOP_CurrentScreenDistance, gEnv->pConsole->GetCVar("r_StereoScreenDist")->GetFVal());
  68.                         ActivateOutput(activationInfo, EOP_CurrentHUDDistance, gEnv->pConsole->GetCVar("r_StereoHudScreenDist")->GetFVal());
  69.                         ActivateOutput(activationInfo, EOP_Flipped, gEnv->pConsole->GetCVar("r_StereoFlipEyes")->GetIVal() != 0);
  70.  
  71.                         bool test = gEnv->pConsole->GetCVar("r_StereoFlipEyes")->GetIVal() != 0;
  72.                         float v = gEnv->pConsole->GetCVar("r_StereoEyeDist")->GetFVal();
  73.                         int x = 0;
  74.                         break;
  75.                 }
  76.         }
  77.  
  78.         virtual void GetMemoryUsage(ICrySizer* s) const
  79.         {
  80.                 s->Add(*this);
  81.         }
  82. };
  83.  
  84. //////////////////////////////////////////////////////////////////////////
  85. class CFlowNode_StereoParameters : public CFlowBaseNode<eNCT_Instanced>
  86. {
  87. public:
  88.         enum EInputs
  89.         {
  90.                 EIP_EyeDistance,
  91.                 EIP_ScreenDistance,
  92.                 EIP_HUDDistance,
  93.                 EIP_Duration,
  94.                 EIP_Start,
  95.         };
  96.         enum EOutputs
  97.         {
  98.                 EOP_CurrentEyeDistance,
  99.                 EOP_CurrentScreenDistance,
  100.                 EOP_CurrentHUDDistance,
  101.                 EOP_TimeLeft,
  102.                 EOP_Done,
  103.         };
  104.  
  105.         CFlowNode_StereoParameters(SActivationInfo* activationInfo)
  106.                 : m_duration(0.0f)
  107.                 , m_startTime(0.0f)
  108.         {
  109.                 m_startEyeDistance = m_targetEyeDistance = m_currentEyeDistance = gEnv->pConsole->GetCVar("r_StereoEyeDist")->GetFVal();
  110.                 m_startScreenDistance = m_targetScreenDistance = m_currentScreenDistance = gEnv->pConsole->GetCVar("r_StereoScreenDist")->GetFVal();
  111.                 m_startHUDDistance = m_targetHUDDistance = m_currentHUDDistance = gEnv->pConsole->GetCVar("r_StereoHudScreenDist")->GetFVal();
  112.         };
  113.  
  114.         virtual IFlowNodePtr Clone(SActivationInfo* pActInfo) { return new CFlowNode_StereoParameters(pActInfo); }
  115.  
  116.         virtual void         GetConfiguration(SFlowNodeConfig& config)
  117.         {
  118.                 static const SInputPortConfig in_config[] = {
  119.                         InputPortConfig<float>("EyeDistance",    _HELP("Set stereo eye distance")),
  120.                         InputPortConfig<float>("ScreenDistance", 1.0f,                             _HELP("Set stereo screen distance")),
  121.                         InputPortConfig<float>("HUDDistance",    1.0f,                             _HELP("Set stereo HUD distance")),
  122.                         InputPortConfig<float>("Duration",       1.0f,                             _HELP("Duration of the interpolation in seconds (0 = set immediately)")),
  123.                         InputPortConfig_Void("Start",            _HELP("Starts interpolation")),
  124.                         { 0 }
  125.                 };
  126.                 static const SOutputPortConfig out_config[] = {
  127.                         OutputPortConfig<float>("CurrentEyeDistance",    _HELP("Current value of eye distance")),
  128.                         OutputPortConfig<float>("CurrentScreenDistance", _HELP("Current value of screen distance")),
  129.                         OutputPortConfig<float>("CurrentHUDDistance",    _HELP("Current value of HUD distance")),
  130.                         OutputPortConfig<float>("TimeLeft",              _HELP("Time left to the end of the interpolation")),
  131.                         OutputPortConfig_Void("Done",                    _HELP("Interpolation is done.")),
  132.                         { 0 }
  133.                 };
  134.  
  135.                 config.pInputPorts = in_config;
  136.                 config.pOutputPorts = out_config;
  137.                 config.SetCategory(EFLN_ADVANCED);
  138.         }
  139.  
  140.         virtual void ProcessEvent(EFlowEvent event, SActivationInfo* activationInfo)
  141.         {
  142.                 switch (event)
  143.                 {
  144.                 case eFE_Initialize:
  145.                         activationInfo->pGraph->SetRegularlyUpdated(activationInfo->myID, false);
  146.  
  147.                         m_targetEyeDistance = GetPortFloat(activationInfo, EIP_EyeDistance);
  148.                         m_targetScreenDistance = GetPortFloat(activationInfo, EIP_ScreenDistance);
  149.                         m_targetHUDDistance = GetPortFloat(activationInfo, EIP_HUDDistance);
  150.                         m_duration = GetPortFloat(activationInfo, EIP_Duration);
  151.  
  152.                         break;
  153.  
  154.                 case eFE_Activate:
  155.                         if (IsPortActive(activationInfo, EIP_Start))
  156.                         {
  157.                                 activationInfo->pGraph->SetRegularlyUpdated(activationInfo->myID, true);
  158.  
  159.                                 m_startTime = gEnv->pTimer->GetFrameStartTime().GetMilliSeconds();
  160.  
  161.                                 m_startEyeDistance = gEnv->pConsole->GetCVar("r_StereoEyeDist")->GetFVal();
  162.                                 m_startScreenDistance = gEnv->pConsole->GetCVar("r_StereoScreenDist")->GetFVal();
  163.                                 m_startHUDDistance = gEnv->pConsole->GetCVar("r_StereoHudScreenDist")->GetFVal();
  164.                         }
  165.  
  166.                         if (IsPortActive(activationInfo, EIP_EyeDistance))
  167.                                 m_targetEyeDistance = GetPortFloat(activationInfo, EIP_EyeDistance);
  168.                         if (IsPortActive(activationInfo, EIP_ScreenDistance))
  169.                                 m_targetScreenDistance = GetPortFloat(activationInfo, EIP_ScreenDistance);
  170.                         if (IsPortActive(activationInfo, EIP_HUDDistance))
  171.                                 m_targetHUDDistance = GetPortFloat(activationInfo, EIP_HUDDistance);
  172.                         if (IsPortActive(activationInfo, EIP_Duration))
  173.                                 m_duration = GetPortFloat(activationInfo, EIP_Duration);
  174.  
  175.                         break;
  176.  
  177.                 case eFE_Update:
  178.                         float currentTime = gEnv->pTimer->GetFrameStartTime().GetMilliSeconds();
  179.                         float endTime = m_startTime + m_duration * 1000.0f;
  180.  
  181.                         if (currentTime > endTime)
  182.                         {
  183.                                 ActivateOutput(activationInfo, EOP_Done, true);
  184.                                 activationInfo->pGraph->SetRegularlyUpdated(activationInfo->myID, false);
  185.                                 currentTime = endTime;
  186.                         }
  187.  
  188.                         float s = 1.0f;
  189.                         if (endTime - m_startTime > 0.0f)
  190.                         {
  191.                                 s = CLAMP((currentTime - m_startTime) / (endTime - m_startTime), 0.0f, 1.0f);
  192.                         }
  193.  
  194.                         m_currentEyeDistance = LERP(m_startEyeDistance, m_targetEyeDistance, s);
  195.                         m_currentScreenDistance = LERP(m_startScreenDistance, m_targetScreenDistance, s);
  196.                         m_currentHUDDistance = LERP(m_startHUDDistance, m_targetHUDDistance, s);
  197.  
  198.                         ActivateOutput(activationInfo, EOP_CurrentEyeDistance, m_currentEyeDistance);
  199.                         ActivateOutput(activationInfo, EOP_CurrentScreenDistance, m_currentScreenDistance);
  200.                         ActivateOutput(activationInfo, EOP_CurrentHUDDistance, m_currentHUDDistance);
  201.                         ActivateOutput(activationInfo, EOP_TimeLeft, (currentTime - m_startTime) / 1000.0f);
  202.  
  203.                         gEnv->pConsole->GetCVar("r_StereoEyeDist")->Set(m_currentEyeDistance);
  204.                         gEnv->pConsole->GetCVar("r_StereoScreenDist")->Set(m_currentScreenDistance);
  205.                         gEnv->pConsole->GetCVar("r_StereoHudScreenDist")->Set(m_currentHUDDistance);
  206.  
  207.                         break;
  208.  
  209.                 }
  210.                 ;
  211.         };
  212.  
  213.         virtual void GetMemoryUsage(ICrySizer* s) const
  214.         {
  215.                 s->Add(*this);
  216.         }
  217.  
  218. private:
  219.         float m_targetEyeDistance;
  220.         float m_targetScreenDistance;
  221.         float m_targetHUDDistance;
  222.  
  223.         float m_startEyeDistance;
  224.         float m_startScreenDistance;
  225.         float m_startHUDDistance;
  226.  
  227.         float m_currentEyeDistance;
  228.         float m_currentScreenDistance;
  229.         float m_currentHUDDistance;
  230.  
  231.         float m_duration;
  232.         float m_startTime;
  233. };
  234.  
  235. REGISTER_FLOW_NODE("Stereo:ReadStereoParameters", CFlowNode_ReadStereoParameters);
  236. REGISTER_FLOW_NODE("Stereo:StereoParameters", CFlowNode_StereoParameters);
  237.  
downloadFlowNodeStereoparameters.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