BVB Source Codes

CRYENGINE Show ControllerPQLog.h Source code

Return Download CRYENGINE: download ControllerPQLog.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #include <Cry3DEngine/CGF/CGFContent.h>
  6.  
  7. class CControllerPQLog : public IController
  8. {
  9. public:
  10.  
  11.         /**
  12.          * Default constructor.
  13.          */
  14.         CControllerPQLog();
  15.  
  16.         /**
  17.          * Assigns a data payload to this controller object.
  18.          */
  19.         void SetControllerData(const DynArray<PQLogS>& arrKeys, const DynArray<int>& arrTimes)
  20.         {
  21.                 m_arrKeys = arrKeys;
  22.                 m_arrTimes = arrTimes;
  23.         }
  24.  
  25.         //////////////////////////////////////////////////////////
  26.         // IController implementation
  27.         virtual JointState GetOPS(f32 key, Quat& quat, Vec3& pos, Diag33& scl) const override;
  28.         virtual JointState GetOP(f32 key, Quat& quat, Vec3& pos) const override;
  29.         virtual JointState GetO(f32 key, Quat& quat) const override;
  30.         virtual JointState GetP(f32 key, Vec3& pos) const override;
  31.         virtual JointState GetS(f32 key, Diag33& scl) const override;
  32.         virtual int32      GetO_numKey() const override;
  33.         virtual int32      GetP_numKey() const override;
  34.         virtual size_t     GetRotationKeysNum() const override;
  35.         virtual size_t     GetPositionKeysNum() const override;
  36.         virtual size_t     GetScaleKeysNum() const override;
  37.         virtual size_t     SizeOfController() const override;
  38.         virtual size_t     ApproximateSizeOfThis() const override;
  39.         //////////////////////////////////////////////////////////
  40.  
  41. private:
  42.  
  43.         const QuatTNS& DecodeKey(f32 keyTime) const;
  44.  
  45. public:
  46.  
  47.         // TODO: make these members private
  48.         DynArray<PQLogS> m_arrKeys;
  49.         DynArray<int>    m_arrTimes;
  50.  
  51. private:
  52.  
  53.         mutable float   m_lastTime;
  54.         mutable QuatTNS m_lastValue;
  55. };
  56.  
  57. TYPEDEF_AUTOPTR(CControllerPQLog);
  58.  
  59. inline const QuatTNS& CControllerPQLog::DecodeKey(f32 keyTime) const
  60. {
  61. #ifdef DEFINE_PROFILER_FUNCTION
  62.         DEFINE_PROFILER_FUNCTION();
  63. #endif
  64.  
  65.         if (keyTime == m_lastTime)
  66.         {
  67.                 return m_lastValue;
  68.         }
  69.         m_lastTime = keyTime;
  70.  
  71.         // Use local variables to spare checking the this pointer everytime
  72.         const PQLogS* const __restrict arrKeys = &m_arrKeys[0];
  73.         const int* const __restrict arrTimes = &m_arrTimes[0];
  74.         const int nNumKeysPQ = m_arrKeys.size();
  75.  
  76.         assert(m_arrKeys.size() > 0);
  77.  
  78.         const f32 keytimeStart = (f32)arrTimes[0];
  79.         if (keyTime < keytimeStart)
  80.         {
  81.                 const PQLogS& value = arrKeys[0];
  82.                 m_lastValue = QuatTNS(!Quat::exp(value.rotationLog), value.position, value.scale);
  83.                 return m_lastValue;
  84.         }
  85.  
  86.         const f32 keytimeEnd = (f32)arrTimes[nNumKeysPQ - 1];
  87.         if (keyTime >= keytimeEnd)
  88.         {
  89.                 const PQLogS& value = arrKeys[nNumKeysPQ - 1];
  90.                 m_lastValue = QuatTNS(!Quat::exp(value.rotationLog), value.position, value.scale);
  91.                 return m_lastValue;
  92.         }
  93.  
  94.         assert(m_arrKeys.size() > 1);
  95.  
  96.         int nPos = nNumKeysPQ >> 1;
  97.         int nStep = nNumKeysPQ >> 2;
  98.  
  99.         // use binary search
  100.         while (nStep)
  101.         {
  102.                 const int time = arrTimes[nPos];
  103.                 if (keyTime < time)
  104.                 {
  105.                         nPos = nPos - nStep;
  106.                 }
  107.                 else if (keyTime > time)
  108.                 {
  109.                         nPos = nPos + nStep;
  110.                 }
  111.                 else
  112.                 {
  113.                         break;
  114.                 }
  115.                 nStep = nStep >> 1;
  116.         }
  117.  
  118.         // fine-tuning needed since time is not linear
  119.         while (keyTime > arrTimes[nPos])
  120.         {
  121.                 nPos++;
  122.         }
  123.  
  124.         while (keyTime < arrTimes[nPos - 1])
  125.         {
  126.                 nPos--;
  127.         }
  128.  
  129.         assert(nPos > 0 && nPos < (int)nNumKeysPQ);
  130.  
  131.         PQLogS pKeys[2] = { arrKeys[nPos - 1], arrKeys[nPos] };
  132.  
  133.         const int32 k0 = arrTimes[nPos];
  134.         const int32 k1 = arrTimes[nPos - 1];
  135.  
  136.         if (k0 == k1)
  137.         {
  138.                 m_lastValue = QuatTNS(!Quat::exp(pKeys[1].rotationLog), pKeys[1].position, pKeys[1].scale);
  139.                 return m_lastValue;
  140.         }
  141.  
  142.         AdjustLogRotations(pKeys[0].rotationLog, pKeys[1].rotationLog);
  143.  
  144.         PQLogS value;
  145.         const f32 blendFactor = (f32(keyTime - k1)) / (k0 - k1);
  146.         value.Blend(pKeys[0], pKeys[1], blendFactor);
  147.  
  148.         m_lastValue = QuatTNS(!Quat::exp(value.rotationLog), value.position, value.scale);
  149.         return m_lastValue;
  150. }
  151.  
downloadControllerPQLog.h 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