BVB Source Codes

CRYENGINE Show ShapeContainer.h Source code

Return Download CRYENGINE: download ShapeContainer.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:   ShapeContainer.h
  6.    $Id$
  7.    Description: Shape containers.
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 2007                               : Created by Mikko Mononen
  12.  
  13.  *********************************************************************/
  14.  
  15. #ifndef _SHAPECONTAINER_H_
  16. #define _SHAPECONTAINER_H_
  17.  
  18. #if _MSC_VER > 1000
  19.         #pragma once
  20. #endif
  21.  
  22. #include "Shape.h"
  23.  
  24. template<typename ShapeClass>
  25. struct SQuadTreeAIShapeElement
  26. {
  27.         /// no-arg constructor is just to allow std::vector::resize(0)
  28.         SQuadTreeAIShapeElement(ShapeClass* pShape = 0) : m_pShape(pShape), m_counter(-1) {}
  29.  
  30.         inline bool        DoesAABBIntersectAABB(const AABB& aabb) const   { return Overlap::AABB_AABB2D(aabb, m_pShape->GetAABB()); }
  31.         inline bool        DoesAABBIntersectPoint(const Vec3& point) const { return Overlap::Point_AABB2D(point, m_pShape->GetAABB()); }
  32.         inline bool        DoesIntersectAABB(const AABB& aabb) const       { return m_pShape->OverlapAABB(aabb); }
  33.         inline const AABB& GetAABB() const                                 { return m_pShape->GetAABB(); }
  34.  
  35.         ShapeClass*        m_pShape;
  36.         mutable int        m_counter;
  37. };
  38.  
  39. // Simple helper class to deal with shapes.
  40. class CAIShapeContainer
  41. {
  42. public:
  43.  
  44.         typedef std::map<string, CAIShape*>                           NameToShapeMap;
  45.         typedef std::vector<CAIShape*>                                ShapeVector;
  46.         typedef std::vector<const SQuadTreeAIShapeElement<CAIShape>*> QuadTreeAIShapeVector;
  47.  
  48.         // Constructor
  49.         CAIShapeContainer();
  50.         // Destructor
  51.         ~CAIShapeContainer();
  52.         // Clear all shapes and supporting structures.
  53.         void                      Clear();
  54.         // Replace the container with content from specified container.
  55.         void                      Copy(const CAIShapeContainer& cont);
  56.         // Insert the contents of the specified container.
  57.         void                      Insert(const CAIShapeContainer& cont);
  58.         // Insert new shape, the container will delete the shape when the container cleared.
  59.         void                      InsertShape(CAIShape* pShape);
  60.         // Deletes shape from container and removes any references to it.
  61.         void                      DeleteShape(const string& name);
  62.         // Deletes shape from container and removes any references to it.
  63.         void                      DeleteShape(CAIShape* pShape);
  64.         // Detaches specified shape from the container.
  65.         void                      DetachShape(CAIShape* pShape);
  66.         // Finds shape by name.
  67.         CAIShape*                 FindShape(const string& name);
  68.         // Builds quadtree structure to speed up spatial queries.
  69.         void                      BuildQuadTree(int maxElementsPerCell, float minCellSize);
  70.         // Builds bin sorting structures for the shapes to speed up spatial queries.
  71.         void                      BuildBins();
  72.         // Clears the quadtree
  73.         void                      ClearQuadTree();
  74.         // Returns the shape vector.
  75.         inline const ShapeVector& GetShapes() const { return m_shapes; }
  76.         // Returns the shape vector.
  77.         inline ShapeVector&       GetShapes()       { return m_shapes; }
  78.         // Returns all shapes that overlap the specified AABB.
  79.         void                      GetShapesOverlappingAABB(ShapeVector& elements, const AABB& aabb);
  80.         // Returns true if specified point is inside any of the shapes in the container.
  81.         bool                      IsPointInside(const Vec3& pt, const CAIShape** outShape = 0) const;
  82.         // Counts and returns number of shapes that contain the specified point.
  83.         unsigned                  IsPointInsideCount(const Vec3& pt, const CAIShape** outShape = 0) const;
  84.         // Returns true if the specified point lies on any edges within specified tolerance of any of the shapes in the container.
  85.         bool                      IsPointOnEdge(const Vec3& pt, float tol, const CAIShape** outShape = 0) const;
  86.         // Returns true if the linesegment intersects with any of the shapes in hte containers.
  87.         // Finds nearest hit.
  88.         bool IntersectLineSeg(const Vec3& start, const Vec3& end, Vec3& outClosestPoint,
  89.                               Vec3* outNormal = 0, bool bForceNormalOutwards = false, const string* nameToSkip = 0) const;
  90.  
  91.         bool IntersectLineSeg(const Vec3& start, const Vec3& end, float radius) const;
  92.  
  93.         // Returns memory used by the container including the shapes.
  94.         size_t MemStats() const;
  95.  
  96. private:
  97.  
  98.         typedef CAIQuadTree<SQuadTreeAIShapeElement<CAIShape>> ShapeQuadTree;
  99.  
  100.         ShapeQuadTree*               m_quadTree;
  101.         NameToShapeMap               m_nameToShape;
  102.         ShapeVector                  m_shapes;
  103.  
  104.         static QuadTreeAIShapeVector s_elements;
  105.         static int                   s_instances;
  106.  
  107.         // Prevent copying which will break the instance count
  108.         CAIShapeContainer(const CAIShapeContainer&);
  109.         CAIShapeContainer& operator=(const CAIShapeContainer&);
  110. };
  111.  
  112. /*
  113.    // Simple helper class to deal with shapes.
  114.    class CAISpecialAreaContainer
  115.    {
  116.    public:
  117.  
  118.    typedef std::map<string, CAISpecialArea*> NameToShapeMap;
  119.    typedef std::vector<CAISpecialArea*> ShapeVector;
  120.    typedef std::vector<const SQuadTreeAIShapeElement<CAISpecialArea>*> QuadTreeAISpecialAreaVector;
  121.  
  122.    // Constructor
  123.    CAISpecialAreaContainer();
  124.    // Destructor
  125.    ~CAISpecialAreaContainer();
  126.    // Clear all shapes and supporting structures.
  127.    void Clear();
  128.    // Insert new shape, the container will delete the shape when the container cleared.
  129.    void InsertShape(CAISpecialArea* pShape);
  130.    // Deletes shape from container and removes any references to it.
  131.    void DeleteShape(const string& name);
  132.    // Deletes shape from container and removes any references to it.
  133.    void DeleteShape(CAISpecialArea* pShape);
  134.    // Finds shape by name.
  135.    CAISpecialArea* FindShape(const string& name);
  136.    // Quick lookup of shape by ID.
  137.    inline CAISpecialArea* CAISpecialAreaContainer::GetShapeById(int id)
  138.    {
  139.     AIAssert(id < 0 || id >= m_idToShape.size());
  140.     return m_idToShape[id];
  141.    }
  142.    // Builds quad tree structure to speed up spatial queries.
  143.    void BuildQuadTree(int maxElementsPerCell, float minCellSize);
  144.    // Builds bin sorting structures for the shapes to speed up spatial queries.
  145.    void BuildBins();
  146.    // Returns the shape vector.
  147.    inline const ShapeVector& GetShapes() const { return m_shapes; }
  148.    // Returns the shape vector.
  149.    inline ShapeVector& GetShapes() { return m_shapes; }
  150.    // Returns all shapes that overlap the specified AABB.
  151.    //   bool GetShapesOverlappingAABB(QuadTreeAIShapeVector& elements, const AABB& aabb);
  152.    // Returns true if specified point is inside any of the shapes in the container.
  153.    bool IsPointInside(const Vec3& pt, bool checkHeight, const CAISpecialArea** outShape = 0) const;
  154.  
  155.    // Returns memory used by the container including the shapes.
  156.    size_t MemStats() const;
  157.  
  158.    private:
  159.  
  160.    typedef CAIQuadTree<SQuadTreeAIShapeElement<CAISpecialArea> > ShapeQuadTree;
  161.  
  162.    ShapeQuadTree* m_quadTree;
  163.    NameToShapeMap m_nameToShape;
  164.    ShapeVector m_idToShape;
  165.    ShapeVector m_shapes;
  166.    };
  167.  */
  168.  
  169. #endif
  170.  
downloadShapeContainer.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