Frustum.pkg 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. $#include "Frustum.h"
  2. /// Frustum planes.
  3. enum FrustumPlane
  4. {
  5. PLANE_NEAR = 0,
  6. PLANE_LEFT,
  7. PLANE_RIGHT,
  8. PLANE_UP,
  9. PLANE_DOWN,
  10. PLANE_FAR,
  11. };
  12. static const unsigned NUM_FRUSTUM_PLANES;
  13. static const unsigned NUM_FRUSTUM_VERTICES;
  14. /// Convex constructed of 6 planes.
  15. class Frustum
  16. {
  17. public:
  18. /// Construct undefined.
  19. Frustum();
  20. /// Copy-construct from another frustum.
  21. Frustum(const Frustum& frustum);
  22. /// Define with projection parameters and a transform matrix.
  23. void Define(float fov, float aspectRatio, float zoom, float nearZ, float farZ, const Matrix3x4& transform = Matrix3x4::IDENTITY);
  24. /// Define with near and far dimension vectors and a transform matrix.
  25. void Define(const Vector3& near, const Vector3& far, const Matrix3x4& transform = Matrix3x4::IDENTITY);
  26. /// Define with a bounding box and a transform matrix.
  27. void Define(const BoundingBox& box, const Matrix3x4& transform = Matrix3x4::IDENTITY);
  28. /// Define with orthographic projection parameters and a transform matrix.
  29. void DefineOrtho(float orthoSize, float aspectRatio, float zoom, float nearZ, float farZ, const Matrix3x4& transform = Matrix3x4::IDENTITY);
  30. /// Transform by a 3x3 matrix.
  31. void Transform(const Matrix3& transform);
  32. /// Transform by a 3x4 matrix.
  33. void Transform(const Matrix3x4& transform);
  34. /// Test if a point is inside or outside.
  35. Intersection IsInside(const Vector3& point) const;
  36. /// Test if a sphere is inside, outside or intersects.
  37. Intersection IsInside(const Sphere& sphere) const;
  38. /// Test if a sphere if (partially) inside or outside.
  39. Intersection IsInsideFast(const Sphere& sphere) const;
  40. /// Test if a bounding box is inside, outside or intersects.
  41. Intersection IsInside(const BoundingBox& box) const;
  42. /// Test if a bounding box is (partially) inside or outside.
  43. Intersection IsInsideFast(const BoundingBox& box) const;
  44. /// Return distance of a point to the frustum, or 0 if inside.
  45. float Distance(const Vector3& point) const;
  46. /// Return transformed by a 3x3 matrix.
  47. Frustum Transformed(const Matrix3& transform) const;
  48. /// Return transformed by a 3x4 matrix.
  49. Frustum Transformed(const Matrix3x4& transform) const;
  50. /// Return projected by a 4x4 projection matrix.
  51. Rect Projected(const Matrix4& transform) const;
  52. /// Update the planes. Called internally.
  53. void UpdatePlanes();
  54. };