5#ifndef S_VIEW_FRUSTUM_HPP_INCLUDED
6#define S_VIEW_FRUSTUM_HPP_INCLUDED
8#include <nirtcpp/core/engine/plane3d.hpp>
9#include <nirtcpp/core/engine/vector3d.hpp>
10#include <nirtcpp/core/engine/line3d.hpp>
11#include <nirtcpp/core/engine/aabbox3d.hpp>
12#include <nirtcpp/core/engine/matrix4.hpp>
13#include <nirtcpp/core/engine/IVideoDriver.hpp>
126 enum E_TRANSFORMATION_STATE_FRUSTUM
134 inline void recalculateBoundingSphere();
139 float BoundingRadius;
140 float FarNearDistance;
257 recalculateBoundingSphere();
262 return BoundingRadius;
267 return BoundingCenter;
272 FarNearDistance = distance;
330 const f32 len = -core::reciprocal_squareroot(
331 planes[i].Normal.getLengthSQ());
349 index = SViewFrustum::ETS_PROJECTION;
break;
351 index = SViewFrustum::ETS_VIEW;
break;
355 return Matrices [ index ];
367 index = SViewFrustum::ETS_PROJECTION;
break;
369 index = SViewFrustum::ETS_VIEW;
break;
373 return Matrices [ index ];
379 bool wasClipped =
false;
382 if (
planes[i].classifyPointRelation(line.start) == core::ISREL3D_FRONT)
388 if (
planes[i].classifyPointRelation(line.end) == core::ISREL3D_FRONT)
398 inline void SViewFrustum::recalculateBoundingSphere()
404 const float farlen = FarNearDistance;
405 const float fartocenter = (farlen + (shortlen - longlen) * (shortlen + longlen)/(4*farlen)) / 2;
406 const float neartocenter = farlen - fartocenter;
422 float diam[8] = { 0.f };
424 for (i = 0; i < 8; ++i)
425 diam[i] = dir[i].getLengthSQ();
429 for (i = 0; i < 8; ++i)
431 if (diam[i] > longest)
435 BoundingRadius = sqrtf(longest);
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition matrix4.hpp:49
void transformPlane(core::plane3d< f32 > &plane) const
Transforms a plane by this matrix.
Definition matrix4.hpp:1275
void transformVect(vector3df &vect) const
Transforms the vector by this matrix.
Definition matrix4.hpp:1224
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition aabbox3d.hpp:74
aabbox3d< T > getInterpolated(const aabbox3d< T > &other, f32 d) const
Calculates a new interpolated bounding box.
Definition aabbox3d.hpp:208
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition aabbox3d.hpp:50
bool getIntersectionWithPlanes(const plane3d< T > &o1, const plane3d< T > &o2, vector3d< T > &outPoint) const
Get the intersection point with two other planes if there is one.
Definition plane3d.hpp:195
T D
Distance from origin.
Definition plane3d.hpp:231
vector3d< T > Normal
Normal vector of the plane.
Definition plane3d.hpp:228
f32 getKnownIntersectionWithLine(const vector3d< T > &linePoint1, const vector3d< T > &linePoint2) const
Get percentage of line between two points where an intersection with this plane happens.
Definition plane3d.hpp:107
T Y
Y coordinate of the vector.
Definition vector3d.hpp:453
T X
X coordinate of the vector.
Definition vector3d.hpp:450
T Z
Z coordinate of the vector.
Definition vector3d.hpp:456
Defines the view frustum. That's the space visible by the camera.
Definition SViewFrustum.hpp:26
float getBoundingRadius() const
get the bounding sphere's radius (of an optimized sphere, not the AABB's)
Definition SViewFrustum.hpp:260
core::vector3df getBoundingCenter() const
get the bounding sphere's radius (of an optimized sphere, not the AABB's)
Definition SViewFrustum.hpp:265
void setFrom(const core::matrix4 &mat, bool zClipFromZero)
This constructor creates a view frustum based on a projection and/or view matrix.
Definition SViewFrustum.hpp:277
core::vector3df getNearRightUp() const
returns the point which is on the near right top corner inside the the view frustum.
Definition SViewFrustum.hpp:220
core::matrix4 & getTransform(video::E_TRANSFORMATION_STATE state)
get the given state's matrix based on frustum E_TRANSFORMATION_STATE
Definition SViewFrustum.hpp:343
void transform(const core::matrix4 &mat)
transforms the frustum by the matrix
Definition SViewFrustum.hpp:150
core::vector3df getNearRightDown() const
returns the point which is on the near right bottom corner inside the the view frustum.
Definition SViewFrustum.hpp:230
core::vector3df getNearLeftDown() const
returns the point which is on the near left bottom corner inside the the view frustum.
Definition SViewFrustum.hpp:210
bool clipLine(core::line3d< f32 > &line) const
clips a line to the view frustum.
Definition SViewFrustum.hpp:377
core::vector3df getNearLeftUp() const
returns the point which is on the near left upper corner inside the the view frustum.
Definition SViewFrustum.hpp:200
core::vector3df cameraPosition
the position of the camera
Definition SViewFrustum.hpp:116
void recalculateBoundingBox()
recalculates the bounding box and sphere based on the planes
Definition SViewFrustum.hpp:245
core::plane3d< f32 > planes[VF_PLANE_COUNT]
all planes enclosing the view frustum.
Definition SViewFrustum.hpp:119
core::vector3df getFarRightDown() const
returns the point which is on the far right bottom corner inside the the view frustum.
Definition SViewFrustum.hpp:190
core::vector3df getFarLeftUp() const
returns the point which is on the far left upper corner inside the the view frustum.
Definition SViewFrustum.hpp:160
core::vector3df getFarLeftDown() const
returns the point which is on the far left bottom corner inside the the view frustum.
Definition SViewFrustum.hpp:170
const core::aabbox3d< f32 > & getBoundingBox() const
returns a bounding box enclosing the whole view frustum
Definition SViewFrustum.hpp:240
core::vector3df getFarRightUp() const
returns the point which is on the far right top corner inside the the view frustum.
Definition SViewFrustum.hpp:180
void setFarNearDistance(float distance)
the cam should tell the frustum the distance between far and near
Definition SViewFrustum.hpp:270
SViewFrustum()
Default Constructor.
Definition SViewFrustum.hpp:49
core::aabbox3d< f32 > boundingBox
bounding box around the view frustum
Definition SViewFrustum.hpp:122
VFPLANES
Definition SViewFrustum.hpp:29
@ VF_FAR_PLANE
Far plane of the frustum. That is the plane furthest away from the eye.
Definition SViewFrustum.hpp:31
@ VF_TOP_PLANE
Top plane of the frustum.
Definition SViewFrustum.hpp:41
@ VF_NEAR_PLANE
Near plane of the frustum. That is the plane nearest to the eye.
Definition SViewFrustum.hpp:33
@ VF_RIGHT_PLANE
Right plane of the frustum.
Definition SViewFrustum.hpp:37
@ VF_LEFT_PLANE
Left plane of the frustum.
Definition SViewFrustum.hpp:35
@ VF_BOTTOM_PLANE
Bottom plane of the frustum.
Definition SViewFrustum.hpp:39
@ VF_PLANE_COUNT
Amount of planes enclosing the view frustum. Should be 6.
Definition SViewFrustum.hpp:44
E_TRANSFORMATION_STATE
enumeration for geometry transformation states
Definition IVideoDriver.hpp:54
@ ETS_VIEW
View transformation.
Definition IVideoDriver.hpp:56
@ ETS_PROJECTION
Projection transformation.
Definition IVideoDriver.hpp:60
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110