BVB Source Codes

CRYENGINE Show ControllerPQ.cpp Source code

Return Download CRYENGINE: download ControllerPQ.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 "ControllerPQ.h"
  5.  
  6. #include <float.h>
  7. #include "CharacterManager.h"
  8. #include "ControllerOpt.h"
  9.  
  10. namespace ControllerHelper
  11. {
  12.  
  13. uint32 GetPositionsFormatSizeOf(uint32 format)
  14. {
  15.         switch (format)
  16.         {
  17.         case eNoCompress:
  18.         case eNoCompressVec3:
  19.                 return sizeof(NoCompressVec3);
  20.  
  21.         default:
  22.                 return 0;
  23.         }
  24. }
  25. uint32 GetScalingFormatSizeOf(uint32 format)
  26. {
  27.         return GetPositionsFormatSizeOf(format);
  28. }
  29.  
  30. uint32 GetRotationFormatSizeOf(uint32 format)
  31. {
  32.         switch (format)
  33.         {
  34.         case eNoCompress:
  35.         case eNoCompressQuat:
  36.                 return sizeof(NoCompressQuat);
  37.  
  38.         case eSmallTree48BitQuat:
  39.                 return sizeof(SmallTree48BitQuat);
  40.  
  41.         case eSmallTree64BitQuat:
  42.                 return sizeof(SmallTree64BitQuat);
  43.  
  44.         case eSmallTree64BitExtQuat:
  45.                 return sizeof(SmallTree64BitExtQuat);
  46.  
  47.         default:
  48.                 return 0;
  49.         }
  50. }
  51.  
  52. uint32 GetKeyTimesFormatSizeOf(uint32 format)
  53. {
  54.         switch (format)
  55.         {
  56.         case eF32:
  57.                 return sizeof(float);
  58.  
  59.         case eUINT16:
  60.                 return sizeof(uint16);
  61.  
  62.         case eByte:
  63.                 return sizeof(uint8);
  64.  
  65.         case eF32StartStop:
  66.                 return sizeof(float);
  67.  
  68.         case eUINT16StartStop:
  69.                 return sizeof(uint16);
  70.  
  71.         case eByteStartStop:
  72.                 return sizeof(uint8);
  73.  
  74.         case eBitset:
  75.                 return sizeof(uint16);
  76.  
  77.         default:
  78.                 return 0;
  79.         }
  80. }
  81.  
  82. ITrackPositionStorage* GetPositionControllerPtr(uint32 format, void* pData, size_t numElements)
  83. {
  84.         switch (format)
  85.         {
  86.         case eNoCompress:
  87.         case eNoCompressVec3:
  88.                 return new NoCompressPosition(reinterpret_cast<NoCompressVec3*>(pData), numElements);
  89.  
  90.         default:
  91.                 return nullptr;
  92.         }
  93. }
  94.  
  95. ITrackPositionStorage* GetScalingControllerPtr(uint32 format, void* pData, size_t numElements)
  96. {
  97.         return GetPositionControllerPtr(format, pData, numElements);
  98. }
  99.  
  100. ITrackRotationStorage* GetRotationControllerPtr(uint32 format, void* pData, size_t numElements)
  101. {
  102.         switch (format)
  103.         {
  104.         case eNoCompress:
  105.         case eNoCompressQuat:
  106.                 return new NoCompressRotation(reinterpret_cast<NoCompressQuat*>(pData), numElements);
  107.  
  108.         case eSmallTree48BitQuat:
  109.                 return new SmallTree48BitQuatRotation(reinterpret_cast<SmallTree48BitQuat*>(pData), numElements);
  110.  
  111.         case eSmallTree64BitQuat:
  112.                 return new SmallTree64BitQuatRotation(reinterpret_cast<SmallTree64BitQuat*>(pData), numElements);
  113.  
  114.         case eSmallTree64BitExtQuat:
  115.                 return new SmallTree64BitExtQuatRotation(reinterpret_cast<SmallTree64BitExtQuat*>(pData), numElements);
  116.  
  117.         default:
  118.                 return nullptr;
  119.         }
  120. }
  121.  
  122. IKeyTimesInformation* GetKeyTimesControllerPtr(uint32 format, void* pData, size_t numElements)
  123. {
  124.         switch (format)
  125.         {
  126.         case eF32:
  127.                 return new F32KeyTimesInformation(reinterpret_cast<f32*>(pData), numElements);
  128.  
  129.         case eUINT16:
  130.                 return new UINT16KeyTimesInformation(reinterpret_cast<uint16*>(pData), numElements);
  131.  
  132.         case eByte:
  133.                 return new ByteKeyTimesInformation(reinterpret_cast<uint8*>(pData), numElements);
  134.  
  135.         case eF32StartStop:
  136.                 return new F32SSKeyTimesInformation(reinterpret_cast<f32*>(pData), numElements);
  137.  
  138.         case eUINT16StartStop:
  139.                 return new UINT16SSKeyTimesInformation(reinterpret_cast<uint16*>(pData), numElements);
  140.  
  141.         case eByteStartStop:
  142.                 return new ByteSSKeyTimesInformation(reinterpret_cast<uint8*>(pData), numElements);
  143.  
  144.         case eBitset:
  145.                 return new CKeyTimesInformationBitSet(reinterpret_cast<uint16*>(pData), numElements);
  146.         }
  147.         return 0;
  148. }
  149.  
  150. }                                                                                // namespace ControllerHelper
  151.  
  152. #if 0 // Currently unused, and needs support for modifiable controllers
  153. void CCompressedController::UnCompress()
  154. {
  155.  
  156.         CWaveletData Rotations[3];
  157.         CWaveletData Positions[3];
  158.  
  159.         //      for (uint32 i = 0; i < 3; ++i)
  160.         if (m_Rotations0.size() > 0)
  161.         {
  162.                 Wavelet::UnCompress(m_Rotations0, Rotations[0]);
  163.                 Wavelet::UnCompress(m_Rotations1, Rotations[1]);
  164.                 Wavelet::UnCompress(m_Rotations2, Rotations[2]);
  165.  
  166.                 uint32 size = m_pRotationController->GetKeyTimesInformation()->GetNumKeys();//Rotations[0].m_Data.size();
  167.  
  168.                 //              m_pRotationController->Reserve(size);
  169.  
  170.                 for (uint32 i = 0; i < size; ++i)
  171.                 {
  172.                         Ang3 ang(Rotations[0].m_Data[i], Rotations[1].m_Data[i], Rotations[2].m_Data[i]);
  173.                         Quat quat;
  174.                         quat.SetRotationXYZ(ang);
  175.                         quat.Normalize();
  176.                         m_pRotationController->GetRotationStorage()->AddValue(quat);
  177.                 }
  178.  
  179.         }
  180.  
  181.         if (m_Positions0.size() > 0)
  182.         {
  183.                 Wavelet::UnCompress(m_Positions0, Positions[0]);
  184.                 Wavelet::UnCompress(m_Positions2, Positions[2]);
  185.                 Wavelet::UnCompress(m_Positions1, Positions[1]);
  186.  
  187.                 uint32 size = m_pPositionController->GetKeyTimesInformation()->GetNumKeys(); //Positions[0].m_Data.size();
  188.                 //              m_pPositionController->Reserve(size);
  189.  
  190.                 for (uint32 i = 0; i < size; ++i)
  191.                 {
  192.                         Vec3 pos(Positions[0].m_Data[i], Positions[1].m_Data[i], Positions[2].m_Data[i]);
  193.                         m_pPositionController->GetPositionStorage()->AddValue(pos);
  194.                 }
  195.  
  196.         }
  197.  
  198.         m_Rotations0.clear();
  199.         m_Rotations1.clear();
  200.         m_Rotations2.clear();
  201.         m_Positions0.clear();
  202.         m_Positions1.clear();
  203.         m_Positions2.clear();
  204.  
  205. }
  206. #endif
  207.  
  208. namespace ControllerHelper
  209. {
  210.  
  211. const CRY_ALIGN(16) uint8 m_byteTable[256] = {
  212.         0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
  213.         1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,1,  2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3,
  214.         4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2,3,  3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3,
  215.         3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4,4,  5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3,
  216.         4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4,5,  4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5,
  217.         4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4,3,  4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5,
  218.         6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5,6,  6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
  219. };
  220.  
  221. const CRY_ALIGN(16) uint8 m_byteLowBit[256] = {
  222.         8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  223.         4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  224.         5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  225.         4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  226.         6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  227.         4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  228.         5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  229.         4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  230.         7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  231.         4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  232.         5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  233.         4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  234.         6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  235.         4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  236.         5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  237.         4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
  238. };
  239.  
  240. const CRY_ALIGN(16) uint8 m_byteHighBit[256] = {
  241.         16, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
  242.         4,  4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  243.         5,  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  244.         5,  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  245.         6,  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  246.         6,  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  247.         6,  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  248.         6,  6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  249.         7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  250.         7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  251.         7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  252.         7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  253.         7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  254.         7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  255.         7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  256.         7,  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  257. };
  258.  
  259. } // namespace ControllerHelper
  260.  
  261. void IPositionController::GetValueFromKey(uint32 key, Vec3& val)
  262. {
  263.         uint32 numKeys = GetNumKeys();
  264.  
  265.         if (key >= numKeys)
  266.         {
  267.                 key = numKeys - 1;
  268.         }
  269.  
  270.         m_pData->GetValue(key, val);
  271. }
  272.  
  273. void IRotationController::GetValueFromKey(uint32 key, Quat& val)
  274. {
  275.         uint32 numKeys = GetNumKeys();
  276.  
  277.         if (key >= numKeys)
  278.         {
  279.                 key = numKeys - 1;
  280.         }
  281.  
  282.         m_pData->GetValue(key, val);
  283. }
  284.  
  285. JointState CControllerOptNonVirtual::GetOPS(f32 normalizedTime, Quat& quat, Vec3& pos, Diag33& scale) const
  286. {
  287.         return
  288.           CControllerOptNonVirtual::GetO(normalizedTime, quat) |
  289.           CControllerOptNonVirtual::GetP(normalizedTime, pos) |
  290.           CControllerOptNonVirtual::GetS(normalizedTime, scale);
  291. }
  292.  
  293. JointState CControllerOptNonVirtual::GetOP(f32 normalized_time, Quat& quat, Vec3& pos) const
  294. {
  295.         return
  296.           CControllerOptNonVirtual::GetO(normalized_time, quat) |
  297.           CControllerOptNonVirtual::GetP(normalized_time, pos);
  298. }
  299.  
  300. JointState CControllerOptNonVirtual::GetO(f32 normalized_time, Quat& quat) const
  301. {
  302.         if (eNoFormat == m_rotation.getTimeFormat())
  303.                 return 0;
  304.         quat = this->CControllerOptNonVirtual::GetRotValue(normalized_time);
  305.         return eJS_Orientation;
  306. }
  307.  
  308. JointState CControllerOptNonVirtual::GetP(f32 normalizedTime, Vec3& pos) const
  309. {
  310.         if (eNoFormat == m_position.getTimeFormat())
  311.                 return 0;
  312.         pos = this->CControllerOptNonVirtual::GetPosValue(normalizedTime);
  313.         return eJS_Position;
  314. }
  315.  
  316. JointState CControllerOptNonVirtual::GetS(f32 normalizedTime, Diag33& pos) const
  317. {
  318.         return 0;
  319. }
  320.  
  321. JointState CController::GetOPS(f32 normalized_time, Quat& quat, Vec3& pos, Diag33& scale) const
  322. {
  323.         return
  324.           CController::GetO(normalized_time, quat) |
  325.           CController::GetP(normalized_time, pos) |
  326.           CController::GetS(normalized_time, scale);
  327. }
  328.  
  329. JointState CController::GetOP(f32 normalized_time, Quat& quat, Vec3& pos) const
  330. {
  331.         return
  332.           CController::GetO(normalized_time, quat) |
  333.           CController::GetP(normalized_time, pos);
  334. }
  335.  
  336. JointState CController::GetO(f32 normalized_time, Quat& quat) const
  337. {
  338.         if (m_pRotationController)
  339.         {
  340.                 m_pRotationController->GetValue(normalized_time, quat);
  341.                 return eJS_Orientation;
  342.         }
  343.  
  344.         return 0;
  345. }
  346.  
  347. JointState CController::GetP(f32 normalized_time, Vec3& pos) const
  348. {
  349.         if (m_pPositionController)
  350.         {
  351.                 m_pPositionController->GetValue(normalized_time, pos);
  352.                 return eJS_Position;
  353.         }
  354.  
  355.         return 0;
  356. }
  357.  
  358. JointState CController::GetS(f32 normalized_time, Diag33& scl) const
  359. {
  360.         if (m_pScaleController)
  361.         {
  362.                 Vec3 tmp;
  363.                 m_pScaleController->GetValue(normalized_time, tmp);
  364.                 scl = Diag33(tmp);
  365.                 return eJS_Scale;
  366.         }
  367.         return 0;
  368. }
  369.  
  370. int32 CController::GetO_numKey() const
  371. {
  372.         // TODO: Remove as a duplicated functionality (GetRotationKeysNum())
  373.         if (m_pRotationController)
  374.                 return m_pRotationController->GetNumKeys();
  375.         return -1;
  376. }
  377.  
  378. int32 CController::GetP_numKey() const
  379. {
  380.         // TODO: Remove as a duplicated functionality (GetPositionKeysNum())
  381.         if (m_pPositionController)
  382.                 return m_pPositionController->GetNumKeys();
  383.         return -1;
  384. }
  385.  
  386. size_t CController::GetRotationKeysNum() const
  387. {
  388.         if (m_pRotationController)
  389.                 return m_pRotationController->GetNumKeys();
  390.         return 0;
  391. }
  392.  
  393. size_t CController::GetPositionKeysNum() const
  394. {
  395.         if (m_pPositionController)
  396.                 return m_pPositionController->GetNumKeys();
  397.         return 0;
  398. }
  399.  
  400. size_t CController::GetScaleKeysNum() const
  401. {
  402.         if (m_pScaleController)
  403.                 return m_pScaleController->GetNumKeys();
  404.         return 0;
  405. }
  406.  
  407. size_t CController::SizeOfController() const
  408. {
  409.         size_t res = sizeof(*this);
  410.         if (m_pPositionController)
  411.                 res += m_pPositionController->SizeOfPosController();
  412.         if (m_pRotationController)
  413.                 res += m_pRotationController->SizeOfRotController();
  414.         if (m_pScaleController)
  415.                 res += m_pScaleController->SizeOfPosController();
  416.         return res;
  417. }
  418.  
  419. size_t CController::ApproximateSizeOfThis() const
  420. {
  421.         return SizeOfController();
  422. }
  423.  
  424. #if CRY_PLATFORM_SSE2 && !defined(_DEBUG)
  425. __m128 SmallTree48BitQuat::div;
  426. __m128 SmallTree48BitQuat::ran;
  427.  
  428. int Init48b = SmallTree48BitQuat::Init();
  429. #endif
  430.  
downloadControllerPQ.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