BVB Source Codes

CRYENGINE Show LineSeg.h Source code

Return Download CRYENGINE: download LineSeg.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef LINE_SEGMENT_2D_H
  4. #define LINE_SEGMENT_2D_H
  5.  
  6. #include "Utils.h"
  7.  
  8. #include <vector>
  9.  
  10. /**
  11.  * @brief A simple oriented 2D line segment implementation.
  12.  */
  13. template<typename VectorT>
  14. class LineSeg
  15. {
  16.         VectorT m_start;
  17.         VectorT m_end;
  18. public:
  19.         LineSeg(const VectorT& start, const VectorT& end);
  20.         const VectorT& Start() const;
  21.         const VectorT& End() const;
  22.         /// Inverts this line segment's direction.
  23.         void           Invert();
  24.         VectorT        Dir() const;
  25.         /// Takes parameter and returns point corresponding to that parameter.
  26.         VectorT        Pt(float t) const;
  27.         float          GetParam(const VectorT& pt) const;
  28.         /// Returns (unnormalized) normal vector to this lineseg.
  29.         VectorT        Normal() const;
  30. };
  31.  
  32. template<typename VectorT>
  33. inline LineSeg<VectorT>::LineSeg(const VectorT& start, const VectorT& end) :
  34.         m_start(start), m_end(end)
  35. {
  36. }
  37.  
  38. template<typename VectorT>
  39. inline const VectorT& LineSeg<VectorT >::Start() const
  40. {
  41.         return m_start;
  42. }
  43.  
  44. template<typename VectorT>
  45. inline const VectorT& LineSeg<VectorT >::End() const
  46. {
  47.         return m_end;
  48. }
  49.  
  50. template<typename VectorT>
  51. inline void LineSeg<VectorT >::Invert()
  52. {
  53.         std::swap(m_start, m_end);
  54. }
  55.  
  56. template<typename VectorT>
  57. inline VectorT LineSeg<VectorT >::Dir() const
  58. {
  59.         return m_end - m_start;
  60. }
  61.  
  62. template<typename VectorT>
  63. inline VectorT LineSeg<VectorT >::Pt(float t) const
  64. {
  65.         return m_start + Dir() * t;
  66. }
  67.  
  68. template<typename VectorT>
  69. inline float LineSeg<VectorT >::GetParam(const VectorT& pt) const
  70. {
  71.         const VectorT toPt = pt - m_start;
  72.         const VectorT thisDir = Dir();
  73.         const int sign = toPt.Dot(thisDir) > 0.0f ? 1 : -1;
  74.         return sign * toPt.GetLength() / thisDir.GetLength();
  75. }
  76.  
  77. template<typename VectorT>
  78. inline VectorT LineSeg<VectorT >::Normal() const
  79. {
  80.         return Dir().Perp();
  81. }
  82.  
  83. typedef LineSeg<Vector2d>      LineSeg2d;
  84. typedef std::vector<LineSeg2d> LineSegVec;
  85.  
  86. #endif
  87.  
downloadLineSeg.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