Mesh Cuts.h 13 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /******************************************************************************
  2. In following functions 'hit_face' can indicate a triangle or a quad index
  3. If it's a quad then 'hit_face' has XOR'ed SIGN_BIT into its value
  4. Determining triangle or quad looks like this:
  5. if(hit_face&SIGN_BIT)quad_index=hit_face^SIGN_BIT; // it's a quad
  6. else tri_index=hit_face ; // it's a triangle
  7. /******************************************************************************/
  8. // if moving 3D point cuts through a static mesh, if mesh is transformed pass its matrix to 'mesh_matrix', 'hit_frac'=0..1, 'hit_pos'=hit position, 'hit_face'=index of hit face, if you're sure that quad's are fully valid (their triangles are coplanar) set 'test_quads_as_2_tris'=false for performance boost
  9. Bool Sweep(C Vec &point, C Vec &move, C MeshBase &mshb, C Matrix *mesh_matrix=null, Flt *hit_frac=null, Vec *hit_pos=null, Int *hit_face=null , Bool test_quads_as_2_tris=true, Bool two_sided=false ); // 'two_sided'=if mesh faces are two-sided
  10. Bool Sweep(C Vec &point, C Vec &move, C MeshRender &mshr, C Matrix *mesh_matrix=null, Flt *hit_frac=null, Vec *hit_pos=null, Int *hit_face=null , Bool two_sided=false ); // 'two_sided'=if mesh faces are two-sided
  11. Bool Sweep(C Vec &point, C Vec &move, C MeshPart &part, C Matrix *mesh_matrix=null, Flt *hit_frac=null, Vec *hit_pos=null, Int *hit_face=null , Bool test_quads_as_2_tris=true, Int two_sided=-1, Bool only_visible=true); // , 'two_sided'=if mesh faces are two-sided (use -1 to set according to material cull), 'only_visible'=if process only visible mesh parts
  12. Bool Sweep(C Vec &point, C Vec &move, C MeshLod &mesh, C Matrix *mesh_matrix=null, Flt *hit_frac=null, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null , Bool test_quads_as_2_tris=true, Int two_sided=-1, Bool only_visible=true); // 'hit_part'=index of hit MeshPart , 'two_sided'=if mesh faces are two-sided (use -1 to set according to material cull), 'only_visible'=if process only visible mesh parts
  13. Bool Sweep(C Vec &point, C Vec &move, C Mesh &mesh, C Matrix *mesh_matrix=null, Flt *hit_frac=null, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null , Bool test_quads_as_2_tris=true, Int two_sided=-1, Bool only_visible=true); // 'hit_part'=index of hit MeshPart , 'two_sided'=if mesh faces are two-sided (use -1 to set according to material cull), 'only_visible'=if process only visible mesh parts
  14. Bool Sweep(C VecD &point, C VecD &move, C Mesh &mesh, C MatrixM *mesh_matrix=null, Flt *hit_frac=null, VecD *hit_pos=null, Int *hit_face=null, Int *hit_part=null , Bool test_quads_as_2_tris=true, Int two_sided=-1, Bool only_visible=true); // 'hit_part'=index of hit MeshPart , 'two_sided'=if mesh faces are two-sided (use -1 to set according to material cull), 'only_visible'=if process only visible mesh parts
  15. Bool Sweep(C Vec &point, C Vec &move, C MeshGroup &mshg, C Matrix *mesh_matrix=null, Flt *hit_frac=null, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null, Int *hit_mesh=null, Bool test_quads_as_2_tris=true, Int two_sided=-1, Bool only_visible=true); // 'hit_part'=index of hit MeshPart, 'hit_mesh'=index of hit Mesh, 'two_sided'=if mesh faces are two-sided (use -1 to set according to material cull), 'only_visible'=if process only visible mesh parts
  16. /******************************************************************************/
  17. // raycast left from(*, point.y, point.x), return if hit, 'hit_pos'=hit position, 'hit_face'=index of hit face, if you're sure that quad's are fully valid (their triangles are coplanar) set 'test_quads_as_2_tris'=false for performance boost
  18. Bool PosPointMeshXL(C Vec2 &point, C MeshBase &mshb, Vec *hit_pos=null, Int *hit_face=null, C Box *box=null, Bool test_quads_as_2_tris=true); // 'box'=pass 'mshb' bounding box if you know it to improve performance
  19. Bool PosPointMeshXL(C Vec2 &point, C Mesh &mesh, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null , Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart
  20. Bool PosPointMeshXL(C Vec2 &point, C MeshGroup &mshg, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null, Int *hit_mesh=null, Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart, 'hit_mesh'=index of hit Mesh
  21. // raycast right from(*, point.y, point.x), return if hit, 'hit_pos'=hit position, 'hit_face'=index of hit face, if you're sure that quad's are fully valid (their triangles are coplanar) set 'test_quads_as_2_tris'=false for performance boost
  22. Bool PosPointMeshXR(C Vec2 &point, C MeshBase &mshb, Vec *hit_pos=null, Int *hit_face=null, C Box *box=null, Bool test_quads_as_2_tris=true); // 'box'=pass 'mshb' bounding box if you know it to improve performance
  23. Bool PosPointMeshXR(C Vec2 &point, C Mesh &mesh, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null , Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart
  24. Bool PosPointMeshXR(C Vec2 &point, C MeshGroup &mshg, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null, Int *hit_mesh=null, Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart, 'hit_mesh'=index of hit Mesh
  25. // raycast downward from(point.x, *, point.y), return if hit, 'hit_pos'=hit position, 'hit_face'=index of hit face, if you're sure that quad's are fully valid (their triangles are coplanar) set 'test_quads_as_2_tris'=false for performance boost
  26. Bool PosPointMeshY(C Vec2 &point, C MeshBase &mshb, Vec *hit_pos=null, Int *hit_face=null, C Box *box=null, Bool test_quads_as_2_tris=true); // 'box'=pass 'mshb' bounding box if you know it to improve performance
  27. Bool PosPointMeshY(C Vec2 &point, C Mesh &mesh, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null , Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart
  28. Bool PosPointMeshY(C Vec2 &point, C MeshGroup &mshg, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null, Int *hit_mesh=null, Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart, 'hit_mesh'=index of hit Mesh
  29. // raycast forward from(point.x, point.y, *), return if hit, 'hit_pos'=hit position, 'hit_face'=index of hit face, if you're sure that quad's are fully valid (their triangles are coplanar) set 'test_quads_as_2_tris'=false for performance boost
  30. Bool PosPointMeshZF(C Vec2 &point, C MeshBase &mshb, Vec *hit_pos=null, Int *hit_face=null, C Box *box=null, Bool test_quads_as_2_tris=true); // 'box'=pass 'mshb' bounding box if you know it to improve performance
  31. Bool PosPointMeshZF(C Vec2 &point, C Mesh &mesh, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null , Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart
  32. Bool PosPointMeshZF(C Vec2 &point, C MeshGroup &mshg, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null, Int *hit_mesh=null, Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart, 'hit_mesh'=index of hit Mesh
  33. // raycast backwards from(point.x, point.y, *), return if hit, 'hit_pos'=hit position, 'hit_face'=index of hit face, if you're sure that quad's are fully valid (their triangles are coplanar) set 'test_quads_as_2_tris'=false for performance boost
  34. Bool PosPointMeshZB(C Vec2 &point, C MeshBase &mshb, Vec *hit_pos=null, Int *hit_face=null, C Box *box=null, Bool test_quads_as_2_tris=true); // 'box'=pass 'mshb' bounding box if you know it to improve performance
  35. Bool PosPointMeshZB(C Vec2 &point, C Mesh &mesh, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null , Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart
  36. Bool PosPointMeshZB(C Vec2 &point, C MeshGroup &mshg, Vec *hit_pos=null, Int *hit_face=null, Int *hit_part=null, Int *hit_mesh=null, Bool test_quads_as_2_tris=true); // 'hit_part'=index of hit MeshPart, 'hit_mesh'=index of hit Mesh
  37. /******************************************************************************/
  38. // get mesh rest matrix as if it has fallen on the ground and lying there, 'initial_matrix'=initial matrix of the mesh (use null for no custom matrix), 'mass_center'=mesh center of mass (use null for auto-detect), 'min_dist'=minimum distance between vertexes to consider them as contact points, 'rest_box'=if specified then it will be set to the precise box of the mesh after being transformed by the rest matrix, 'max_steps'=maximum number of steps to perform the calculation (<0 = unlimited), 'only_visible'=if process only visible mesh parts, 'only_phys'=if process only mesh parts without 'MSHP_NO_PHYS_BODY'
  39. Matrix GetRestMatrix(C MeshBase &mesh , C Matrix *initial_matrix=null, C Vec *mass_center=null, Flt min_dist=0.01f, Box *rest_box=null, Int max_steps=-1);
  40. Matrix GetRestMatrix(C MeshLod &mesh , C Matrix *initial_matrix=null, C Vec *mass_center=null, Flt min_dist=0.01f, Box *rest_box=null, Int max_steps=-1, Bool only_visible=true, Bool only_phys=true);
  41. Matrix GetRestMatrix(C Mesh &mesh , C Matrix *initial_matrix=null, C Vec *mass_center=null, Flt min_dist=0.01f, Box *rest_box=null, Int max_steps=-1, Bool only_visible=true, Bool only_phys=true);
  42. Matrix GetRestMatrix(C MemPtr<C MeshPart*> &meshes, C Matrix *initial_matrix=null, C Vec *mass_center=null, Flt min_dist=0.01f, Box *rest_box=null, Int max_steps=-1, Bool only_visible=true, Bool only_phys=true);
  43. Matrix GetRestMatrix(C MemPtr<C MeshLod *> &meshes, C Matrix *initial_matrix=null, C Vec *mass_center=null, Flt min_dist=0.01f, Box *rest_box=null, Int max_steps=-1, Bool only_visible=true, Bool only_phys=true);
  44. /******************************************************************************/
  45. #if EE_PRIVATE
  46. /******************************************************************************/
  47. enum TEST_FLAG // Test Flags
  48. {
  49. TEST_NO_PHYS =0x1, // skip testing if ETQ_NO_PHYS set
  50. //TEST_DOUBLE_SIDE=0x2, // skip testing if double sided
  51. };
  52. /******************************************************************************/
  53. struct CutsCache
  54. {
  55. Box box ;
  56. Boxes boxes ;
  57. Memc<UInt> *box_face;
  58. ~CutsCache();
  59. explicit CutsCache(C MeshBase &mshb);
  60. NO_COPY_CONSTRUCTOR(CutsCache);
  61. };
  62. /******************************************************************************/
  63. DIST_TYPE DistPointMesh(C Vec2 &point, C MeshBase &mshb, UInt flag, Flt *dist=null, Int *index=null, UInt test_flag=0); // 'flag' specifies what to test(can be combination of VTX_POS,EDGE_IND,TRI_IND,QUAD_IND), 'dist'=pointer to distance, 'index'=pointer to nearest element(vtx/edge/tri/quad), 'test_flag'=TEST_FLAG
  64. DIST_TYPE DistPointMesh(C Vec &point, C MeshBase &mshb, UInt flag, Flt *dist=null, Int *index=null ); // 'flag' specifies what to test(can be combination of VTX_POS,EDGE_IND,TRI_IND,QUAD_IND), 'dist'=pointer to distance, 'index'=pointer to nearest element(vtx/edge/tri/quad)
  65. Bool CutsPointMesh(C Vec2 &point, C MeshBase &mshb, Flt *dist=null, UInt test_flag=0); // if point 2D is inside mshb, 'dist'=distance to mesh, 'test_flag'=TEST_FLAG
  66. Bool CutsPointMesh(C Vec &point, C MeshBase &mshb, Flt *dist=null, CutsCache *cache=null); // if point 3D is inside mshb, 'dist'=distance to mesh, 'cache '=helper object created on the base of 'mshb' for function improved performance
  67. Bool CutsPointMesh(C Vec2 &point, C MeshLod &mesh, Flt *dist=null, UInt test_flag=0); // if point 2D is inside mesh, 'dist'=distance to mesh, 'test_flag'=TEST_FLAG
  68. Bool CutsPointMesh(C Vec &point, C MeshLod &mesh, Flt *dist=null ); // if point 3D is inside mesh, 'dist'=distance to mesh
  69. Bool CutsPointMesh(C Vec2 &point, C Mesh &mesh, Flt *dist=null, UInt test_flag=0); // if point 2D is inside mesh, 'dist'=distance to mesh, 'test_flag'=TEST_FLAG
  70. Bool CutsPointMesh(C Vec &point, C Mesh &mesh, Flt *dist=null ); // if point 3D is inside mesh, 'dist'=distance to mesh
  71. Bool CutsPointMesh(C Vec2 &point, C MeshGroup &mshg, UInt test_flag=0); // if point 2D is inside mshg
  72. Bool CutsPointMesh(C Vec &point, C MeshGroup &mshg ); // if point 3D is inside mshg
  73. /******************************************************************************/
  74. // if moving 2D point cuts through a static mesh, 'hit_frac'=0..1, 'hit_pos'=hit position, 'hit_edge'=index of hit edge
  75. Bool Sweep(C Vec2 &point, C Vec2 &move, C MeshBase &mshb, Flt *hit_frac=null, Vec2 *hit_pos=null, Int *hit_edge=null);
  76. Bool Sweep(C Vec2 &point, C Vec2 &move, C MeshBase &mshb, C Rects &rects, Index &rect_edge, Flt *hit_frac=null, Vec2 *hit_pos=null, Int *hit_edge=null);
  77. /******************************************************************************/
  78. #endif
  79. /******************************************************************************/