GlobeEngine
ViewFrustum.h
Go to the documentation of this file.
1 
9 #ifndef GlobeEngine_ViewFrustum_h
10 #define GlobeEngine_ViewFrustum_h
11 
12 #include "OpenGL_Includes.h"
13 #include "DrawableComponent.h"
14 #include <vmmlib/vmmlib.hpp>
15 
16 namespace ge {
17 
19  {
20  double fieldOfView;
21  double aspectRatio;
22  double nearPlane;
23  double farPlane;
24 
26  this->fieldOfView = 0.0;
27  this->aspectRatio = 0.0;
28  this->nearPlane = 0.0;
29  this->farPlane = 0.0;
30  }
31 
33  double _fieldOfView,
34  double _aspectRatio,
35  double _nearPlane,
36  double _farPlane) :
37  fieldOfView(_fieldOfView), aspectRatio(_aspectRatio),
38  nearPlane(_nearPlane), farPlane(_farPlane) {}
39 
40  // copy constructor
41  ViewFrustumProperties(const std::shared_ptr<ViewFrustumProperties> copy){
42  fieldOfView = copy->fieldOfView;
43  aspectRatio = copy->aspectRatio;
44  nearPlane = copy->nearPlane;
45  farPlane = copy->farPlane;
46  }
47  };
48 
50  {
51  vmml::Vector3d normal;
52  vmml::Vector3d aPoint;
54  };
55 
57  {
58  public:
59  ViewFrustum() {clear(); };
61  void clear();
62  void destroy();
63  void create(){};
64  void create(vmml::Vector3d eyePosition,
65  vmml::Vector3d view,
66  vmml::Vector3d up,
67  vmml::Vector3d right,
68  ViewFrustumProperties _frustumProp);
69  void createVAO();
70  void update();
71  void draw(std::shared_ptr<ge::Camera> _cam);
72  void move(vmml::Vector3d eyePosition,
73  vmml::Vector3d view,
74  vmml::Vector3d up,
75  vmml::Vector3d right);
76  void extractPlaneNormals();
77  const vmml::Vector3d* getFrustumPoints() const;
78 
79  void calculateAABB();
80  bool isInFrustum(vmml::Vector3d _position, double radius) const;
81  bool isStrictlyInFrustum(vmml::Vector3d _position, double radius) const;
82  bool isAABB2DRoughlyInFrustumAABB2D(vmml::Vector4d _rect) const;
83  bool isRoughlyInFrustumAABB3D(vmml::Vector3d _position) const;
84  bool isAABB2DFarAwayFromFrustumAABB2D(vmml::Vector4d _rect, double _farFactor=1.0) const;
85  bool isInFrustumSphere(vmml::Vector3d _position) const;
86  bool isInFrustumSphere(BoundingSphere* _boundingSphere) const;
87  void createBounds(vmml::Vector3d mid, double radius);
88 
89  bool isViewed();
90 
93 
94  double getNearPlaneDist() const;
95  double getFarPlaneDist() const;
96  double getFieldOfView() const;
97  double getAspectRatio() const;
98  double getZBufferDepth() const;
99 
100  void setAspectRatio(double _aspectRatio);
101 
102  private:
103 
104  bool isPointInsidePlane(ViewFrustumPlane _plane, vmml::Vector3d point, double _radius) const;
105 
106  double pointToPlaneDistance(ViewFrustumPlane _plane, vmml::Vector3d point) const;
107 
113  vmml::Vector3d points[8];
114 
122  ViewFrustumPlane planes[6];
123  vmml::Vector3d nearplaneCenter;
124  vmml::Vector3d farplaneCenter;
125 
126  // AABB
127  vmml::Vector3d aabbMin;
128  vmml::Vector3d aabbMax;
129 
130  ViewFrustumProperties properties;
131  double zBufferDepth;
132 
133  };
134 }
135 #endif
double nearPlane
Definition: ViewFrustum.h:22
bool isRoughlyInFrustumAABB3D(vmml::Vector3d _position) const
Definition: ViewFrustum.cpp:217
Definition: DrawableComponent.h:25
double getZBufferDepth() const
Definition: ViewFrustum.cpp:338
bool isStrictlyInFrustum(vmml::Vector3d _position, double radius) const
ViewFrustum()
Definition: ViewFrustum.h:59
void setAspectRatio(double _aspectRatio)
Definition: ViewFrustum.cpp:329
ViewFrustumProperties()
Definition: ViewFrustum.h:25
vmml::Vector3d aPoint
Definition: ViewFrustum.h:52
void move(vmml::Vector3d eyePosition, vmml::Vector3d view, vmml::Vector3d up, vmml::Vector3d right)
Definition: ViewFrustum.cpp:37
Definition: ViewFrustum.h:56
void setViewFrustumProperties(ViewFrustumProperties _in)
double farPlane
Definition: ViewFrustum.h:23
double normalDotAPoint
Definition: ViewFrustum.h:53
double aspectRatio
Definition: ViewFrustum.h:21
const vmml::Vector3d * getFrustumPoints() const
Definition: ViewFrustum.cpp:305
vmml::Vector3d normal
Definition: ViewFrustum.h:51
void createVAO()
Definition: ViewFrustum.cpp:138
bool isInFrustum(vmml::Vector3d _position, double radius) const
Definition: ViewFrustum.cpp:272
double fieldOfView
Definition: ViewFrustum.h:20
void destroy()
Definition: ViewFrustum.cpp:22
void createBounds(vmml::Vector3d mid, double radius)
Definition: ViewFrustum.cpp:79
double getFieldOfView() const
Definition: ViewFrustum.cpp:324
void extractPlaneNormals()
Definition: ViewFrustum.cpp:89
void clear()
Definition: ViewFrustum.cpp:14
bool isInFrustumSphere(vmml::Vector3d _position) const
Definition: ViewFrustum.cpp:256
bool isAABB2DFarAwayFromFrustumAABB2D(vmml::Vector4d _rect, double _farFactor=1.0) const
Definition: ViewFrustum.cpp:245
void draw(std::shared_ptr< ge::Camera > _cam)
Definition: ViewFrustum.cpp:188
void create()
Definition: ViewFrustum.h:63
void calculateAABB()
Definition: ViewFrustum.cpp:122
~ViewFrustum()
Definition: ViewFrustum.h:60
const ViewFrustumProperties * getViewFrustumProperties()
Definition: ViewFrustum.cpp:310
Definition: ViewFrustum.h:18
Definition: AvalancheTrainingSimulationEngine.h:28
Definition: ViewFrustum.h:49
double getNearPlaneDist() const
Definition: ViewFrustum.cpp:314
double getFarPlaneDist() const
Definition: ViewFrustum.cpp:319
bool isAABB2DRoughlyInFrustumAABB2D(vmml::Vector4d _rect) const
Definition: ViewFrustum.cpp:228
ViewFrustumProperties(const std::shared_ptr< ViewFrustumProperties > copy)
Definition: ViewFrustum.h:41
double getAspectRatio() const
Definition: ViewFrustum.cpp:333
ViewFrustumProperties(double _fieldOfView, double _aspectRatio, double _nearPlane, double _farPlane)
Definition: ViewFrustum.h:32
void update()
Definition: ViewFrustum.cpp:211
Definition: BoundingSphere.h:19