Saga3D API Documentation
1.0-RC4
|
Go to the documentation of this file.
5 #ifndef __SVIEW_FRUSTUM_H_INCLUDED__
6 #define __SVIEW_FRUSTUM_H_INCLUDED__
15 #include <glm/vec3.hpp>
16 #include <glm/gtc/type_ptr.hpp>
57 inline void setFrom(
const glm::mat4& mat);
128 enum class E_TRANSFORM_STATE_FRUSTUM
135 inline void recalculateBoundingSphere();
138 std::array<glm::mat4, TRANSFORM_FRUSTUM_COUNT> Matrices;
140 float BoundingRadius;
141 float FarNearDistance;
142 glm::vec3 BoundingCenter;
158 Matrices[i]=other.Matrices[i];
160 BoundingRadius = other.BoundingRadius;
161 FarNearDistance = other.FarNearDistance;
162 BoundingCenter = other.BoundingCenter;
274 recalculateBoundingSphere();
279 return BoundingRadius;
284 return BoundingCenter;
289 FarNearDistance = distance;
297 auto mat = glm::value_ptr(matrix);
365 bool wasClipped =
false;
386 inline void SViewFrustum::recalculateBoundingSphere()
392 const float farlen = FarNearDistance;
393 const float fartocenter = (farlen + (shortlen - longlen) * (shortlen + longlen)/(4*farlen)) / 2;
394 const float neartocenter = farlen - fartocenter;
410 float diam[8] = { 0.f };
412 for (i = 0; i < 8; ++i)
413 diam[i] = glm::length2(dir[i]);
417 for (i = 0; i < 8; ++i)
419 if (diam[i] > longest)
423 BoundingRadius = sqrtf(longest);
glm::mat4 & getTransform(video::E_TRANSFORM_STATE state)
get the given state's matrix based on frustum E_TRANSFORM_STATE
Template plane class with some intersection testing methods.
constexpr auto enumToPOD(E e) noexcept
@ NEAR
Near plane of the frustum. That is the plane nearest to the eye.
core::plane3d< float > & plane(E_PLANES type)
void transform(const glm::mat4 &mat)
transforms the frustum by the matrix
glm::vec3 getBoundingCenter() const
get the bounding sphere's radius (of an optimized sphere, not the AABB's)
void recalculateBoundingBox()
recalculates the bounding box and sphere based on the planes
glm::vec3 getFarLeftUp() const
returns the point which is on the far left upper corner inside the the view frustum.
@ BOTTOM
Bottom plane of the frustum.
std::array< core::plane3d< float >, VIEW_FRUSTUM_PLANE_COUNT > planes
all planes enclosing the view frustum.
void setFarNearDistance(float distance)
the cam should tell the frustum the distance between far and near
core::plane3d< float > plane(E_PLANES type) const
REALINLINE double reciprocal_squareroot(const double x)
@ FAR
Far plane of the frustum. That is the plane furthest away from the eye.
@ LEFT
Left plane of the frustum.
glm::vec3 getNearLeftUp() const
returns the point which is on the near left upper corner inside the the view frustum.
3D line between two points with intersection methods.
constexpr auto TRANSFORM_FRUSTUM_COUNT
const core::aabbox3d< float > & getBoundingBox() const
returns a bounding box enclosing the whole view frustum
constexpr auto VIEW_FRUSTUM_PLANE_COUNT
glm::vec3 getNearRightUp() const
returns the point which is on the near right top corner inside the the view frustum.
glm::vec3 cameraPosition
the position of the camera
bool clipLine(core::line3d< float > &line) const
clips a line to the view frustum.
E_TRANSFORM_STATE
enumeration for geometry transformation states
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
glm::vec3 end
End point of line.
glm::vec3 start
Start point of line.
glm::vec3 getFarRightDown() const
returns the point which is on the far right bottom corner inside the the view frustum.
glm::vec3 getNearRightDown() const
returns the point which is on the near right bottom corner inside the the view frustum.
glm::vec3 getFarRightUp() const
returns the point which is on the far right top corner inside the the view frustum.
glm::vec3 getFarLeftDown() const
returns the point which is on the far left bottom corner inside the the view frustum.
SViewFrustum()
Default Constructor.
core::aabbox3d< float > boundingBox
bounding box around the view frustum
float getBoundingRadius() const
get the bounding sphere's radius (of an optimized sphere, not the AABB's)
Defines the view frustum. That's the space visible by the camera.
void addInternalPoint(const glm::vec3 &p)
Adds a point to the bounding box.
glm::vec3 getNearLeftDown() const
returns the point which is on the near left bottom corner inside the the view frustum.
@ RIGHT
Right plane of the frustum.
void setFrom(const glm::mat4 &mat)
This constructor creates a view frustum based on a projection and/or view matrix.
@ TOP
Top plane of the frustum.