BVB Source Codes

CRYENGINE Show FlyHelpers_PathFollower.h Source code

Return Download CRYENGINE: download FlyHelpers_PathFollower.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef __FLY_HELPERS__PATH_FOLLOWER
  4. #define __FLY_HELPERS__PATH_FOLLOWER
  5.  
  6. #include "FlyHelpers_Path.h"
  7. #include "FlyHelpers_PathLocation.h"
  8.  
  9. namespace FlyHelpers
  10. {
  11.  
  12. struct PathEntityIn
  13. {
  14.         Vec3 position;
  15.         Vec3 forward;
  16.         Vec3 velocity;
  17.  
  18.         PathEntityIn()
  19.                 : position(0, 0, 0)
  20.                 , forward(0, 1, 0)
  21.                 , velocity(0, 0, 0)
  22.         {
  23.         }
  24. };
  25.  
  26. struct PathEntityOut
  27. {
  28.         Vec3  moveDirection;
  29.         Vec3  lookPosition;
  30.         Vec3  lookDirection;
  31.         float speed;
  32.         float distanceToPathEnd;
  33.  
  34.         PathEntityOut()
  35.                 : moveDirection(0)
  36.                 , lookPosition(0, 0, 0)
  37.                 , lookDirection(0, 0, 0)
  38.                 , speed(0)
  39.                 , distanceToPathEnd(0)
  40.         {
  41.         }
  42. };
  43.  
  44. struct PathFollowerParams
  45. {
  46.         float desiredSpeed;
  47.         float pathRadius;
  48.         float lookAheadDistance;
  49.         float decelerateDistance;
  50.         float maxStartDistanceAlongNonLoopingPath;
  51.         bool  loopAlongPath;
  52.         bool  startPathFromClosestLocation;
  53.  
  54.         PathFollowerParams()
  55.                 : desiredSpeed(15.0f)
  56.                 , pathRadius(1.0f)
  57.                 , lookAheadDistance(3.0f)
  58.                 , decelerateDistance(10.0f)
  59.                 , maxStartDistanceAlongNonLoopingPath(30.0f)
  60.                 , loopAlongPath(false)
  61.                 , startPathFromClosestLocation(false)
  62.         {
  63.         }
  64. };
  65.  
  66. class PathFollower
  67. {
  68. public:
  69.         PathFollower();
  70.         ~PathFollower();
  71.  
  72.         void          Init(const SShape& path, const PathFollowerParams& params, const PathEntityIn& pathEntity);
  73.         PathEntityOut Update(const PathEntityIn& pathEntity, const float elapsedSeconds);
  74.  
  75.         void          SetFinalPathLocation(const Vec3& position);
  76.         void          ResetFinalPathLocation();
  77.  
  78.         void          SetDesiredSpeed(const float desiredSpeed);
  79.  
  80.         void          Draw();
  81.  
  82.         const Path&   GetCurrentPath() const
  83.         {
  84.                 CRY_ASSERT(m_pCurrentPath);
  85.                 return *m_pCurrentPath;
  86.         }
  87.  
  88. private:
  89.         void         SetPath(const SShape& path, const bool loopAlongPath);
  90.  
  91.         Vec3         CalculatePathPosition(const PathLocation& pathLocation) const;
  92.         PathLocation CalculateNextPathLocation(const PathLocation& pathLocation, const float advance) const;
  93.  
  94.         void         SetUseReversePath(const bool useReversePath);
  95.         PathLocation GetNonReversedTargetLocation() const;
  96.  
  97. private:
  98.         Path               m_path;
  99.         Path               m_reversePath;
  100.  
  101.         Path*              m_pCurrentPath;
  102.  
  103.         PathLocation       m_targetLocation;
  104.         PathLocation       m_lookAtLocation;
  105.  
  106.         PathLocation       m_finalLocation;
  107.         bool               m_stopAtFinalLocation;
  108.  
  109.         Vec3               m_targetPosition;
  110.         Vec3               m_lookAtPosition;
  111.         Vec3               m_finalPosition;
  112.  
  113.         PathFollowerParams m_params; // TODO: Don't store, pass it as parameter to update / functions that need it.
  114. };
  115.  
  116. }
  117.  
  118. #endif
  119.  
downloadFlyHelpers_PathFollower.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