Frustum.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /******************************************************************************
  2. Use 'Frustum' to detect shapes visibility according to the camera's viewing frustum.
  3. Sample Usage:
  4. Ball ball;
  5. if(Frustum(ball)).. // if ball is visible in current frustum
  6. /******************************************************************************/
  7. struct FrustumClass // Frustum
  8. {
  9. // if shape intersects with frustum
  10. Bool operator()(C Vec &point)C;
  11. Bool operator()(C VecD &point)C;
  12. Bool operator()(C Ball &ball)C;
  13. Bool operator()(C BallM &ball)C;
  14. Bool operator()(C Capsule &capsule)C;
  15. Bool operator()(C CapsuleM &capsule)C;
  16. Bool operator()(C Extent &ext )C;
  17. Bool operator()(C Extent &ext, C Matrix &matrix )C; // 'ext' transformed by 'matrix'
  18. Bool operator()(C Extent &ext, C MatrixM &matrix )C; // 'ext' transformed by 'matrix'
  19. Bool operator()(C Extent &ext, Bool &fully_inside)C; // 'fully_inside'=after this function returns this will be set to if the 'ext' is fully inside the frustum
  20. Bool operator()(C Box &box )C;
  21. Bool operator()(C Box &box, C Matrix &matrix )C; // 'box' transformed by 'matrix'
  22. Bool operator()(C Box &box, C MatrixM &matrix )C; // 'box' transformed by 'matrix'
  23. Bool operator()(C Box &box, Bool &fully_inside)C; // 'fully_inside'=after this function returns this will be set to if the 'box' is fully inside the frustum
  24. Bool operator()(C OBox &obox)C;
  25. Bool operator()(C Shape &shape )C;
  26. Bool operator()(C Shape *shape, Int shapes)C;
  27. Bool operator()(C Mesh &mesh )C {return T(mesh.ext );} // 'mesh.ext'
  28. Bool operator()(C Mesh &mesh, C Matrix &matrix)C {return T(mesh.ext, matrix);} // 'mesh.ext' transformed by 'matrix'
  29. Bool operator()(C Mesh &mesh, C MatrixM &matrix)C {return T(mesh.ext, matrix);} // 'mesh.ext' transformed by 'matrix'
  30. #if EE_PRIVATE
  31. Bool operator()(C FrustumClass &frustum )C;
  32. void set (Flt range, C Vec2 &fov, C MatrixM &camera); // set from active viewport
  33. void set ( ); // set from active viewport and camera
  34. void from(C BoxD &box ); // set from box
  35. void from(C PyramidM &pyramid ); // set from pyramid
  36. void draw(C Color &color=WHITE)C; // this relies on active object matrix which can be set using 'SetMatrix' function
  37. #endif
  38. void getIntersectingAreas(MemPtr<VecI2> area_pos, Flt area_size, Bool distance_check, Bool sort_by_distance, Bool extend, C RectI *clamp=null)C; // get 'area_pos' coordinates of areas intersecting with this Frustum, 'area_size'=size of a single area, 'distance_check'=list only areas within frustum range, 'sort_by_distance'=if sort areas by distance from camera, 'extend'=if extend frustum by half of 'area_size', 'clamp'=optionally process areas only within this inclusive rectangle, this assumes that areas are located on flat XZ plane, so only XZ coordinates of all 3D vectors are processed and Y is ignored
  39. #if !EE_PRIVATE
  40. private:
  41. #endif
  42. VecD point[ 8]; Int points;
  43. VecI2 edge [12]; Int edges ;
  44. Bool persp, use_extra_plane;
  45. Flt range, eye, view_quad_max_dist;
  46. Vec2 fov_tan, fov_cos_inv;
  47. Vec size, plane_n_abs[DIR_NUM], extra_plane_n_abs;
  48. PlaneM plane[DIR_NUM], extra_plane;
  49. MatrixM matrix;
  50. }extern
  51. Frustum; // Active Frustum
  52. #if EE_PRIVATE
  53. extern FrustumClass FrustumMain, FrustumGrass;
  54. #endif
  55. /******************************************************************************/