My Project
GDIRegion.h
1 #pragma once
2 #include <vector>
3 #include <list>
4 using namespace std;
5 namespace ParaEngine
6 {
7  struct GDISimpleEdge {
8  public:
9  GDISimpleEdge(const Vector3 &p1,const Vector3 &p2);
10  friend class CGDIRegion;
11  protected:
12  GDISimpleEdge();
13  Vector3 point1,point2;
14  float slope;//=tgA=(point2.y-point1.y)/(point2.x-point1.x)
15  float intersect;//=point1.y-slope*point1.x
16  float GetY(float x)const{return intersect+slope*x;}
17  int vertical;//if ==0 the edge is not vertical, if >0 the edge is upwards vertical, if <0 the edge is downwards vertical
18  };
19  struct GDIClipNode {
20  Vector3 point;
21  //-1 for inside-outside , 0 for none, 1 for outside-inside point
22  int nodetype;
23  //link to other place
24  list<GDIClipNode>::const_iterator link;
25  };
29  class CGDIRegion
30  {
31  public:
35  CGDIRegion();
39  CGDIRegion(const RECT &rect);
40  bool operator ==(const CGDIRegion &region);
41  bool operator ==(const RECT &rect);
42  operator RECT();
46  void Translate(float dx,float dy,float dz=0);
47  void Translate(const Vector3 &v);
48 
52  bool IsEmpty()const;
56  bool IsInfinite()const{return m_points.size()==0;}
57  void MakeEmpty();
58  void MakeInifinite();
59  CGDIRegion *Clone();
66  bool LineIntersect(const Vector3 &point1,const Vector3 &point2, Vector3 &outpoint)const;
67  bool LineIntersect(const GDISimpleEdge &edge,vector<Vector3> &outpoint,vector<int> &outedge)const;
72  bool InsideTest(const Vector3 &point)const;
73 
79  int PolygonClip(const CGDIRegion &region,vector<CGDIRegion> &outregions);
80 
84  int RectClip(const CGDIRegion &region,CGDIRegion &outregion);
89  static bool EdgeIntersect(const GDISimpleEdge &edge1,const GDISimpleEdge &edge2,Vector3 &point);
90 
91  Vector3 GetPoint(int index)const;
92  int PointCount()const{return (int)m_points.size();}
93  GDISimpleEdge GetEdge(int index)const;
94  protected:
104  bool IsPoint1Closer(const Vector3 &point,const Vector3 &point1, const Vector3 &point2,int relation=0);
105  bool CalculateClipX(const GDISimpleEdge &edge1,const GDISimpleEdge &edge2,float &pointx)const;
106  void GenerateEdge();
107  void Preprocessing();
108  vector<Vector3> m_points;
109  vector<GDISimpleEdge> m_edges;
110  list<GDIClipNode> m_nodes;
111  int m_shape;
112  };
113 }
Definition: GDIRegion.h:19
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ManagedDef.h:18
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
bool IsInfinite() const
Check if the region is infinite.
Definition: GDIRegion.h:56
Definition: GDIRegion.h:7
We always shape the region points and edges in clockwise.
Definition: GDIRegion.h:29