All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Frustum.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "VectorMathDecl.h"
6 #include "Plane.h"
7 #include "Geometry.h"
8 #include <vector>
9 
10 namespace Eegeo
11 {
12  namespace Geometry
13  {
14  void BuildFrustumPlanesFromViewProjection(std::vector<Geometry::Plane> &frustumPlanes, const Eegeo::m44& viewProjection);
15 
16  class Frustum
17  {
18  public:
19 
20  static const int PLANE_LEFT = 0;
21  static const int PLANE_RIGHT = 1;
22  static const int PLANE_BOTTOM = 2;
23  static const int PLANE_TOP = 3;
24  static const int PLANE_NEAR = 4;
25  static const int PLANE_FAR = 5;
26  static const int PLANES_COUNT = 6;
27  Geometry::Plane planes[PLANES_COUNT];
28 
29  void Update(const std::vector<Geometry::Plane>& frustumPlanes)
30  {
31  for (int i = 0; i < 6; ++ i)
32  {
33  planes[i] = frustumPlanes[i].Norm();
34  }
35  }
36 
37  const Geometry::Plane& operator[] (const int index) const
38  {
39  return planes[index];
40  }
41 
42  void CalculateVertexPositions(std::vector<Eegeo::v3>& verts) const;
43 
44  bool Intersects(const SingleSphere& sphere) const;
45 
46  float CalculateFov() const;
47 
48  static Frustum Transform(const Frustum& frustum, const m44& nonScalingTransform);
49 
50  private:
51  void IntersectPlanes(const Plane& p1, const Plane& p2, const Plane& p3, Eegeo::v3& intersectionPoint)const;
52  };
53  }
54 }