mElite
1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
|
Allows frustum culling and other frustum calculations. More...
#include <Frustum.h>
Public Member Functions | |
Frustum (FrustumInformation frustum) | |
~Frustum (void) | |
void | update (CameraObject *camera) |
Updates the frustum. | |
float | getFrustumWidth (float dist) |
Calculates the frustum width at a given distance. | |
float | getFrustumHeight (float dist) |
Calculates the frustum height at a given distance. | |
CullingLocation | isPointInFrustum (const Vector3 &p) |
Checks if a point is inside the frustum. | |
CullingLocation | isSphereInFrustum (const Vector3 &p, float radius) |
Tests if a sphere intersects the frustum. | |
bool | isInUpperHalf (const Vector3 &p) |
Checks if a point is in the upper half of the view frustum. | |
bool | isInRightHalf (const Vector3 &p) |
Checks if a point is in the right half of the view frustum. | |
void | setFrustumInformation (FrustumInformation frustum) |
Sets the current frustum. | |
Allows frustum culling and other frustum calculations.
This class provides some operations with the view frustum. The needed information is stored in the FrustumInformation structure. These are size and position of near and far planes and the field of view and aspect ratio. With these values the class can calculate the current positions of the frustum and the equations for the bording planes from the actual eye point. If this is updated everytime the camera moves, the class provides prooving if an actual object (with spheric shape) is inside the frustum, or not.
Frustum::Frustum | ( | FrustumInformation | frustum | ) |
Definition at line 8 of file Frustum.cpp.
Frustum::~Frustum | ( | void | ) |
Definition at line 12 of file Frustum.cpp.
float Frustum::getFrustumHeight | ( | float | dist | ) |
Calculates the frustum height at a given distance.
If the distance is longer than the furstums far distance or shorter than the near distance zero is returned. Otherwise the width is calculated using the formula
dist | The distance for what the height is calculated |
Definition at line 157 of file Frustum.cpp.
float Frustum::getFrustumWidth | ( | float | dist | ) |
Calculates the frustum width at a given distance.
If the distance is longer than the furstums far distance or shorter than the near distance zero is returned. Otherwise the width is calculated using the formula
dist | The distance for what the width is calculated |
Definition at line 140 of file Frustum.cpp.
bool Frustum::isInRightHalf | ( | const Vector3 & | p | ) |
Checks if a point is in the right half of the view frustum.
The functions returns false if the point is in the left half of the frustum or outside the frustum. The result can't be used to create an opposite function 'isInLeftHalf'.
p | The point that is to be tested |
Definition at line 121 of file Frustum.cpp.
bool Frustum::isInUpperHalf | ( | const Vector3 & | p | ) |
Checks if a point is in the upper half of the view frustum.
The functions returns false if the point is in the lower half of the frustum or outside the frustum. The result can't be used to create an opposite function 'isInUpperHalf'.
p | The point that is to be tested |
Definition at line 103 of file Frustum.cpp.
CullingLocation Frustum::isPointInFrustum | ( | const Vector3 & | p | ) |
Checks if a point is inside the frustum.
Tests if a single point is inside the frustum or outside. Therefor the signed distance is used. The point is tested with each plane and if the distance is greater than zero it lies on the right side. If the point lies on the right side of every plane it's inside the frustum. If it is on the wrong side of only one plane, that means, the distance is zero or negative, the point is not in the frustum and the calculation can be stopped.
Definition at line 67 of file Frustum.cpp.
CullingLocation Frustum::isSphereInFrustum | ( | const Vector3 & | p, |
float | radius | ||
) |
Tests if a sphere intersects the frustum.
Tests if a sphere is inside the frustrum. It also has to be tested if the sphere intersects with the frustum. For each plane is tested, if the distance between it and the center of the sphere is greater than the radius of the sphere. If it's definitly outside, the calculation can be stopped.
Definition at line 82 of file Frustum.cpp.
void Frustum::setFrustumInformation | ( | FrustumInformation | frustum | ) |
Sets the current frustum.
Defines the size of the frustum that is used for the calculations. If the frustum is changed i.e. because the window is reshaped the frustum needs to be updated.
frustum | The current frustum |
Definition at line 21 of file Frustum.cpp.
void Frustum::update | ( | CameraObject * | camera | ) |
Updates the frustum.
Calculates the eight edges of a frustum and the six bounding planes. These can be used tho verify whether an object is inside the frustum or not (or maybe intersects it).
camera | The camera object to which the frustum belongs. |
Definition at line 31 of file Frustum.cpp.