Polygon.h 5.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /******************************************************************************/
  2. #if EE_PRIVATE
  3. struct Poly // Polygon
  4. {
  5. struct Vtx // polygon vertex
  6. {
  7. Int index, // point index
  8. edge ; // edge index
  9. Flt angle; // angle
  10. void set(Int index ) {T.index=index;}
  11. void set(Int index, Int edge) {T.index=index; T.edge=edge;}
  12. };
  13. Byte angle; // if angles should be calculated
  14. Int id ; // id number
  15. Vec *pos ; // pointer to vertex positions
  16. Meml<Vtx> vtx ; // list of vertexes
  17. // manage
  18. Poly& del ( ); // delete
  19. Poly& create(Vec *pos, Int id=0); // create
  20. // get / set
  21. Bool infinite() ; // if infinite
  22. Flt length2D()C; // get 2D length
  23. Flt length3D()C; // get 3D length
  24. void setAngle() ; // recalculate angles of vertexes
  25. // operations
  26. void addVtx(Int index ) {vtx.New().set(index );} // add vertex
  27. void addVtx(Int index, Int edge) {vtx.New().set(index, edge);} // add vertex and set edge
  28. void removeVtx(MemlNode *v ); // remove vertex
  29. void link (Poly &poly, MemlNode *i, MemlNode *pi); // link with vertexes from poly, 'i'=connected vertex from self, 'pi'= connected vertex from 'poly', 'poly' remains unmodified
  30. // draw
  31. void draw2D(C Color &color);
  32. void draw3D(C Color &color); // this relies on active object matrix which can be set using 'SetMatrix' function
  33. ~Poly() {del();}
  34. Poly();
  35. private:
  36. Byte _infinite;
  37. };
  38. #endif
  39. /******************************************************************************/
  40. void CreateConvex2D (MemPtr<Vec2 > poly, C Vec2 *point, Int points); // create convex 'poly' from points xy coordinates ('point'=array of points, 'points'=number of points)
  41. void CreateConvex2D (MemPtr<VecD2> poly, C VecD2 *point, Int points); // create convex 'poly' from points xy coordinates ('point'=array of points, 'points'=number of points)
  42. void CreateConvex2Dxz(MemPtr<Vec2 > poly, C Vec *point, Int points); // create convex 'poly' from points xz coordinates ('point'=array of points, 'points'=number of points)
  43. void CreateConvex2Dxz(MemPtr<VecD2> poly, C VecD *point, Int points); // create convex 'poly' from points xz coordinates ('point'=array of points, 'points'=number of points)
  44. void Triangulate( C MemPtr<Vec > &poly , MeshBase &mesh, Bool convex=false ); // triangulate 'poly' to 'mesh', 'mesh' will be deleted at start , 'convex'=if 'polys' are known to be convex (this will speed up the process)
  45. void Triangulate( C MemPtr<VtxFull> &poly , MeshBase &mesh, UInt flag_and, Bool convex=false ); // triangulate 'poly' to 'mesh', 'mesh' will be deleted at start, 'flag_and'=elements to include in 'mesh' creation (MESH_BASE_FLAG) , 'convex'=if 'polys' are known to be convex (this will speed up the process)
  46. void Triangulate(C MemPtr< Memc <Vec > > &polys, MeshBase &mesh , Flt weld_pos_eps=EPS, Bool convex=false, C Byte *poly_flags=null); // triangulate set of 'polys' to 'mesh', 'mesh' will be deleted at start , 'weld_pos_eps'=epsilon used for final vertex position welding, 'convex'=if 'polys' are known to be convex (this will speed up the process), 'poly_flags'=if not null then mesh faces will have their flags set according to given pointer (its length must be as long as number of 'polys')
  47. void Triangulate(C MemPtr< Memc <VtxFull> > &polys, MeshBase &mesh, UInt flag_and, Flt weld_pos_eps=EPS, Bool convex=false, C Byte *poly_flags=null); // triangulate set of 'polys' to 'mesh', 'mesh' will be deleted at start, 'flag_and'=elements to include in 'mesh' creation (MESH_BASE_FLAG), 'weld_pos_eps'=epsilon used for final vertex position welding, 'convex'=if 'polys' are known to be convex (this will speed up the process), 'poly_flags'=if not null then mesh faces will have their flags set according to given pointer (its length must be as long as number of 'polys')
  48. void ClipPoly (C MemPtr<Vec > &poly, C Plane &plane, MemPtr<Vec > output ); // clip 'poly' according to 'plane' and store result in 'output' , 'poly' and 'output' must point to different containers
  49. void ClipPoly (C MemPtr<VtxFull> &poly, C Plane &plane, MemPtr<VtxFull> output ); // clip 'poly' according to 'plane' and store result in 'output' , 'poly' and 'output' must point to different containers
  50. void SplitPoly(C MemPtr<Vec > &poly, C Plane &plane, MemPtr<Vec > output_positive, MemPtr<Vec > output_negative); // split 'poly' according to 'plane' and store results in 'output_*', 'poly' and 'output_*' must point to different containers
  51. void SplitPoly(C MemPtr<VtxFull> &poly, C Plane &plane, MemPtr<VtxFull> output_positive, MemPtr<VtxFull> output_negative); // split 'poly' according to 'plane' and store results in 'output_*', 'poly' and 'output_*' must point to different containers
  52. void DrawPoly2D(C MemPtr<Vec> &poly, C Color &edge_color=WHITE, C Color &vtx_color=TRANSPARENT); // draw 'poly'
  53. void DrawPoly (C MemPtr<Vec> &poly, C Color &edge_color=WHITE, C Color &vtx_color=TRANSPARENT); // draw 'poly', this relies on active object matrix which can be set using 'SetMatrix' function
  54. /******************************************************************************/