BVB Source Codes

CRYENGINE Show CTriangulator.h Source code

Return Download CRYENGINE: download CTriangulator.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef _TRIANGULATOR_H_
  4. #define _TRIANGULATOR_H_
  5.  
  6. #if _MSC_VER > 1000
  7.         #pragma once
  8. #endif
  9.  
  10. #include <vector>
  11. #include <list>
  12.  
  13. struct Vtx
  14. {
  15.         real             x, y, z;
  16.         std::vector<int> m_lstTris; // triangles that contain this point
  17.         bool             bCollidable;
  18.         bool             bHideable;
  19.  
  20.         Vtx(real x = 0.0f, real y = 0.0f, real z = 0.0f) : x(x), y(y), z(z) { bCollidable = true; bHideable = false; }
  21.         Vtx(const Vec3r& v) : x(v.x), y(v.y), z(v.z) { bCollidable = true; bHideable = false; }
  22.  
  23.         bool operator==(const Vtx& other)
  24.         {
  25.                 if ((fabs(x - other.x) < 0.001) && (fabs(y - other.y) < 0.001))
  26.                         return true;
  27.                 return false;
  28.         }
  29. };
  30.  
  31. struct Tri
  32. {
  33.         int      v[3];
  34.         Vtx      center;
  35.         real     radiusSq;
  36.  
  37.         unsigned graphNodeIndex;
  38.  
  39.         Tri(int v0 = 0, int v1 = 0, int v2 = 0)
  40.         {
  41.                 v[0] = v0;
  42.                 v[1] = v1;
  43.                 v[2] = v2;
  44.                 radiusSq = 0.0f;
  45.                 center.x = center.y = center.z = 0.0f;
  46.                 graphNodeIndex = 0;
  47.         }
  48. };
  49.  
  50. struct SPOINT
  51. {
  52.         int x, y;
  53. };
  54.  
  55. struct MYPOINT : public SPOINT
  56. {
  57.         bool operator==(const MYPOINT& other) const
  58.         {
  59.                 return ((this->x == other.x) && (this->y == other.y));
  60.         }
  61. };
  62.  
  63. typedef std::list<Tri*>  TARRAY;
  64. typedef std::vector<Vtx> VARRAY;
  65.  
  66. class CTriangulator
  67. {
  68.         // line segment
  69.         struct SSegment
  70.         {
  71.                 SSegment(const Vec3r& p1, const Vec3r& p2) : m_p1(p1), m_p2(p2){}
  72.                 Vec3r m_p1;
  73.                 Vec3r m_p2;
  74.         };
  75.         typedef std::vector<SSegment> TCutsVector;
  76.  
  77.         VARRAY m_vProcessed;
  78.         TARRAY m_vTriangles;
  79.  
  80.         typedef std::vector<MYPOINT> tUniquePts;
  81.         tUniquePts  m_uniquePts;
  82.  
  83.         TCutsVector m_cuts;
  84.         size_t      m_curCutIdx;
  85.  
  86. public:
  87.         void CalcCircle(const Vtx& v1, const Vtx& v2, const Vtx& v3, Tri* pTri);
  88.  
  89.         CTriangulator();
  90.         ~CTriangulator();
  91.  
  92.         VARRAY m_vVertices;
  93.         Vtx    m_vtxBBoxMin;
  94.         Vtx    m_vtxBBoxMax;
  95.  
  96.         int    AddVertex(real x, real y, real z, bool bCollidable, bool bHideable);
  97.         void   AddSegment(const Vec3r& p1, const Vec3r& p2);
  98.         bool   GetSegment(Vec3r& p1, Vec3r& p2);
  99.         bool   Triangulate();
  100.         TARRAY GetTriangles();
  101.         VARRAY GetVertices();
  102.         bool   IsAntiClockwise(Tri* who);
  103.         void   PushUnique(int a, int b);
  104.  
  105.         bool   DoesVertexExist2D(real x, real y, real tol) const;
  106.         bool   PrepForTriangulation(void);
  107.         bool   TriangulateNew(void);
  108. private:
  109.         bool   IsPerpendicular(const Vtx& v1, const Vtx& v2, const Vtx& v3);
  110.         bool   Calculate(Tri* pTri);
  111. };
  112.  
  113. #endif // _TRIANGULATOR_H_
  114.  
downloadCTriangulator.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