geometry.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef GEOMETRY_H
  2. #define GEOMETRY_H
  3. #include "vector3D.h"
  4. #include "mesh.h"
  5. #include "matrix.h"
  6. //Struct containing vertex data for a AABB
  7. //around the model. Primarily for use in frustum culling
  8. //Regiong R = {(x, y, z) | min.x <=x <= max.x | same Y | same Z}
  9. struct AABox{
  10. Vector3f minPoints;
  11. Vector3f maxPoints;
  12. //Builds axis aligned bounding box of the given mesh
  13. void buildAABB(const Mesh &mesh);
  14. void update(const Matrix4 &modelMatrix);
  15. };
  16. struct Plane{
  17. Vector3f normal;
  18. float D;
  19. float distance(const Vector3f &points);
  20. void setNormalAndPoint(const Vector3f &normal, const Vector3f &point);
  21. };
  22. class Frustrum{
  23. private:
  24. enum {
  25. TOP = 0, BOTTOM, LEFT,
  26. RIGHT, NEARP, FARP
  27. };
  28. public:
  29. float fov, AR, near, far , nearH, nearW, farH, farW;
  30. Frustrum(float ratio): fov(90), near(0.1), far(100), AR(ratio){};
  31. Plane pl[6];
  32. void setCamInternals();
  33. void updatePlanes(Matrix4 &viewMat, const Vector3f &cameraPos) ;
  34. bool checkIfInside(AABox *bounds);
  35. };
  36. #endif