geometry.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef GEOMETRY_H
  2. #define GEOMETRY_H
  3. // ===============================
  4. // AUTHOR : Angel Ortiz (angelo12 AT vt DOT edu)
  5. // CREATE DATE : 2018-07-19
  6. // PURPOSE : This file contains all of the geometry classes. Mostly important for
  7. // view frustrum culling since it contains the geometry for axis aligned
  8. // bounding boxes, planes and frustrums.
  9. // ===============================
  10. //Headers
  11. #include "vector3D.h"
  12. #include "mesh.h"
  13. #include "matrix.h"
  14. //Struct containing vertex data for a AABB
  15. //around the model. Primarily for use in frustum culling
  16. //Regiong R = {(x, y, z) | min.x <=x <= max.x | same Y | same Z}
  17. struct AABox{
  18. Vector3f minPoints;
  19. Vector3f maxPoints;
  20. //Builds axis aligned bounding box of the given mesh
  21. void buildAABB(const Mesh &mesh);
  22. void update(const Matrix4 &modelMatrix);
  23. };
  24. //Only used in frustrum culling, a frustrum has 6 planes
  25. //Equation is Ax + By + Cz + D = 0 (or somthing)
  26. struct Plane{
  27. Vector3f normal;
  28. float D;
  29. float distance(const Vector3f &points);
  30. void setNormalAndPoint(const Vector3f &normal, const Vector3f &point);
  31. };
  32. //The shape of the camera view area
  33. class Frustrum{
  34. private:
  35. enum {
  36. TOP = 0, BOTTOM, LEFT,
  37. RIGHT, NEARP, FARP
  38. };
  39. public:
  40. float fov, AR, near, far , nearH, nearW;
  41. Frustrum(float ratio): fov(50), near(0.1), far(100), AR(ratio){};
  42. Plane pl[6];
  43. void setCamInternals();
  44. void updatePlanes(Matrix4 &viewMat, const Vector3f &cameraPos) ;
  45. bool checkIfInside(AABox *bounds);
  46. };
  47. #endif