BVB Source Codes

CRYENGINE Show Shape.h Source code

Return Download CRYENGINE: download Shape.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /********************************************************************
  4.    -------------------------------------------------------------------------
  5.    File name:   Shape.h
  6.    $Id$
  7.    Description: Polygon shapes used for different purposes in the AI system and various shape containers.
  8.  
  9.    The bin sort point-in-polygon check is based on:
  10.    Graphics Gems IV: Point in Polygon Strategies by Eric Haines
  11.    http://tog.acm.org/GraphicsGems/gemsiv/ptpoly_haines/
  12.  
  13.    -------------------------------------------------------------------------
  14.    History:
  15.    - 2007                               : Created by Mikko Mononen
  16.    - 2 Mar 2009 : Evgeny Adamenkov: Removed IRenderer
  17.  
  18.  *********************************************************************/
  19.  
  20. #ifndef _SHAPE_H_
  21. #define _SHAPE_H_
  22.  
  23. #if _MSC_VER > 1000
  24.         #pragma once
  25. #endif
  26.  
  27. typedef std::vector<Vec3> ShapePointContainer;
  28.  
  29. class CAIShape
  30. {
  31. public:
  32.         CAIShape();
  33.         ~CAIShape();
  34.  
  35.         CAIShape*                         DuplicateData(); // Duplicates data only, not acceleration structure.
  36.  
  37.         inline void                       SetName(const string& name) { m_name = name; }
  38.         inline const string&              GetName() const             { return m_name; }
  39.  
  40.         void                              SetPoints(const std::vector<Vec3>& points);
  41.         void                              BuildBins();
  42.         void                              BuildAABB();
  43.  
  44.         bool                              IsPointInside(const Vec3& pt) const;
  45.         bool                              IsPointOnEdge(const Vec3& pt, float tol, Vec3* outNormal = 0) const;
  46.         bool                              IntersectLineSeg(const Vec3& start, const Vec3& end, float& tmin, Vec3* outClosestPoint, Vec3* outNormal = 0, bool bForceNormalOutwards = false) const;
  47.         bool                              IntersectLineSeg(const Vec3& start, const Vec3& end, float radius) const;
  48.  
  49.         bool                              OverlapAABB(const AABB& aabb) const;
  50.  
  51.         inline ShapePointContainer&       GetPoints()       { return m_points; }
  52.         inline const ShapePointContainer& GetPoints() const { return m_points; }
  53.         inline const AABB&                GetAABB() const   { return m_aabb; }
  54.  
  55.         void                              DebugDraw();
  56.  
  57.         size_t                            MemStats() const;
  58.  
  59. private:
  60.  
  61.         struct Edge
  62.         {
  63.                 inline Edge(unsigned short id, float minx, float maxx, bool fullCross) : id(id), fullCross(fullCross), minx(minx), maxx(maxx) {}
  64.                 inline bool operator<(const Edge& rhs) const { return minx < rhs.minx; }
  65.                 float          minx, maxx;
  66.                 unsigned short id;
  67.                 bool           fullCross;
  68.         };
  69.  
  70.         struct Bin
  71.         {
  72.                 inline void AddEdge(float vx0, float vx1, unsigned short id, bool fullCross)
  73.                 {
  74.                         if (vx0 > vx1)
  75.                                 std::swap(vx0, vx1);
  76.                         // Update bin range
  77.                         if (minx > vx0)
  78.                                 minx = vx0;
  79.                         if (maxx < vx1)
  80.                                 maxx = vx1;
  81.                         // Insert edge
  82.                         edges.push_back(Edge(id, vx0, vx1, fullCross));
  83.                 }
  84.  
  85.                 float             minx, maxx;
  86.                 std::vector<Edge> edges;
  87.         };
  88.  
  89.         // Holds the bin sort acceleration structure for the polygon.
  90.         struct BinSort
  91.         {
  92.                 std::vector<Bin> bins;
  93.                 float            ydelta, invYdelta;
  94.         };
  95.  
  96.         bool IsPointInsideSlow(const Vec3& pt) const;
  97.  
  98.         bool IsPointOnEdgeSlow(const Vec3& pt, float tol, Vec3* outNormal = 0) const;
  99.  
  100.         bool IntersectLineSegSlow(const Vec3& start, const Vec3& end, float& tmin,
  101.                                   Vec3* outClosestPoint = 0, Vec3* outNormal = 0, bool bForceNormalOutwards = false) const;
  102.  
  103.         bool IntersectLineSegBin(const Bin& bin, float xrmin, float xrmax,
  104.                                  const Vec3& start, const Vec3& end,
  105.                                  float& tmin, const Vec3*& isa, const Vec3*& isb) const;
  106.  
  107.         float GetDrawZ(float x, float y);
  108.  
  109.         BinSort*            m_binSort;
  110.         ShapePointContainer m_points;
  111.         AABB                m_aabb;
  112.         string              m_name;
  113. };
  114.  
  115. /*
  116.    class CAISpecialArea : public CAIShape
  117.    {
  118.    public:
  119.  
  120.    enum EType
  121.    {
  122.     TYPE_WAYPOINT_HUMAN,
  123.     TYPE_VOLUME,
  124.     TYPE_FLIGHT,
  125.     TYPE_WATER,
  126.     TYPE_WAYPOINT_3DSURFACE,
  127.     TYPE_FREE_2D,
  128.     TYPE_TRIANGULATION
  129.    };
  130.  
  131.    CAISpecialArea() :
  132.     CAIShape(),
  133.     m_buildingID(-1), m_type(TYPE_WAYPOINT_HUMAN),
  134.     m_calculate3DNav(true), m_3DNavVolumeRadius(10.0f), m_waypointConnections(WPCON_DESIGNER_NONE),
  135.     m_vehiclesInHumanNav(false), m_altered(false), m_lightLevel(AILL_NONE),
  136.     m_minZ(FLT_MAX), m_maxZ(-FLT_MAX), m_height(0)
  137.    {
  138.    }
  139.  
  140.    ~CAISpecialArea() { CAIShape::~CAIShape(); }
  141.  
  142.    inline bool IsPointInside(const Vec3& pt, bool checkHeight) const
  143.    {
  144.     if (checkHeight && (pt.z < m_minZ || pt.z > m_maxZ)) return false;
  145.     return CAIShape::IsPointInside(pt);
  146.    }
  147.  
  148.    float m_minZ,m_maxZ;
  149.    float m_height;
  150.    float m_nodeAutoConnectDistance;
  151.    int m_waypointType;
  152.    int m_vehiclesInHumanNav;
  153.    int  m_buildingID;
  154.    EType m_type;
  155.    bool  m_calculate3DNav;
  156.    float m_3DNavVolumeRadius;
  157.    EAILightLevel m_lightLevel;
  158.    EWaypointConnections m_waypointConnections;
  159.    bool m_altered; // making links unpassible
  160.    };
  161.  */
  162.  
  163. #endif
  164.  
downloadShape.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