geometry.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. };
  15. struct Plane{
  16. Vector3f normal;
  17. float D;
  18. float distance(const Vector3f &points);
  19. void setNormalAndPoint(const Vector3f &normal, const Vector3f &point);
  20. };
  21. class Frustrum{
  22. private:
  23. enum {
  24. TOP = 0, BOTTOM, LEFT,
  25. RIGHT, NEARP, FARP
  26. };
  27. public:
  28. float fov, AR, near, far , nearH, nearW, farH, farW;
  29. Frustrum(float ratio): fov(90), near(0.1), far(10000), AR(ratio){};
  30. Plane pl[6];
  31. void setCamInternals();
  32. void updatePlanes(Matrix4 &viewMat, const Vector3f &cameraPos) ;
  33. bool checkIfInside(AABox *bounds);
  34. };
  35. #endif