BVB Source Codes

CRYENGINE Show FlyHelpers_Path.cpp Source code

Return Download CRYENGINE: download FlyHelpers_Path.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 "FlyHelpers_Path.h"
  5.  
  6. namespace FlyHelpers
  7. {
  8.  
  9. Path::Path()
  10. {
  11. }
  12.  
  13. Path::~Path()
  14. {
  15. }
  16.  
  17. void Path::Clear()
  18. {
  19.         m_points.clear();
  20.         m_segmentDistances.clear();
  21.         m_pathLengthsToPoint.clear();
  22. }
  23.  
  24. void Path::AddPoint(const Vec3& point)
  25. {
  26.         if (m_points.empty())
  27.         {
  28.                 m_points.push_back(point);
  29.                 m_pathLengthsToPoint.push_back(0);
  30.         }
  31.         else
  32.         {
  33.                 const Vec3& previousPoint = m_points.back();
  34.                 Vec3 segment = point - previousPoint;
  35.                 const float segmentLength = segment.GetLength();
  36.                 if (0.01f < segmentLength)
  37.                 {
  38.                         m_points.push_back(point);
  39.                         m_segmentDistances.push_back(segmentLength);
  40.  
  41.                         const float pathLengthToPreviousPoint = m_pathLengthsToPoint.back();
  42.                         const float pathLengthToPoint = pathLengthToPreviousPoint + segmentLength;
  43.                         m_pathLengthsToPoint.push_back(pathLengthToPoint);
  44.                 }
  45.         }
  46. }
  47.  
  48. const Vec3& Path::GetPoint(const size_t pointIndex) const
  49. {
  50.         assert(pointIndex < m_points.size());
  51.         return m_points[pointIndex];
  52. }
  53.  
  54. Lineseg Path::GetSegment(const size_t segmentIndex) const
  55. {
  56.         assert(segmentIndex + 1 < m_points.size());
  57.         const Vec3& start = m_points[segmentIndex];
  58.         const Vec3& end = m_points[segmentIndex + 1];
  59.         return Lineseg(start, end);
  60. }
  61.  
  62. float Path::GetSegmentLength(const size_t segmentIndex) const
  63. {
  64.         assert(segmentIndex < m_segmentDistances.size());
  65.         return m_segmentDistances[segmentIndex];
  66. }
  67.  
  68. size_t Path::GetPointCount() const
  69. {
  70.         return m_points.size();
  71. }
  72.  
  73. size_t Path::GetSegmentCount() const
  74. {
  75.         return m_segmentDistances.size();
  76. }
  77.  
  78. void Path::MakeLooping()
  79. {
  80.         if (m_points.empty())
  81.         {
  82.                 return;
  83.         }
  84.  
  85.         const Vec3 firstPoint = m_points.front();
  86.         AddPoint(firstPoint);
  87. }
  88.  
  89. float Path::GetPathDistanceToPoint(const size_t pointIndex) const
  90. {
  91.         assert(pointIndex < m_pathLengthsToPoint.size());
  92.         return m_pathLengthsToPoint[pointIndex];
  93. }
  94.  
  95. float Path::GetTotalPathDistance() const
  96. {
  97.         assert(!m_pathLengthsToPoint.empty());
  98.         return m_pathLengthsToPoint.back();
  99. }
  100.  
  101. }
  102.  
downloadFlyHelpers_Path.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