Loading...
Searching...
No Matches
SViewFrustum.h
Go to the documentation of this file.
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __S_VIEW_FRUSTUM_H_INCLUDED__
#define __S_VIEW_FRUSTUM_H_INCLUDED__
#include "plane3d.h"
#include "vector3d.h"
#include "line3d.h"
#include "aabbox3d.h"
#include "matrix4.h"
#include "IVideoDriver.h"
namespace irr
{
namespace scene
{
struct SViewFrustum
{
enum VFPLANES
{
VF_FAR_PLANE = 0,
VF_NEAR_PLANE,
VF_LEFT_PLANE,
VF_RIGHT_PLANE,
VF_BOTTOM_PLANE,
VF_TOP_PLANE,
VF_PLANE_COUNT
};
SViewFrustum() {}
SViewFrustum(const SViewFrustum& other);
SViewFrustum(const core::matrix4& mat);
inline void setFrom(const core::matrix4& mat);
void transform(const core::matrix4& mat);
core::vector3df getFarLeftUp() const;
core::vector3df getFarLeftDown() const;
core::vector3df getFarRightUp() const;
core::vector3df getFarRightDown() const;
core::vector3df getNearLeftUp() const;
core::vector3df getNearLeftDown() const;
core::vector3df getNearRightUp() const;
core::vector3df getNearRightDown() const;
const core::aabbox3d<f32> &getBoundingBox() const;
inline void recalculateBoundingBox();
core::matrix4& getTransform( video::E_TRANSFORMATION_STATE state);
const core::matrix4& getTransform( video::E_TRANSFORMATION_STATE state) const;
bool clipLine(core::line3d<f32>& line) const;
core::vector3df cameraPosition;
core::plane3d<f32> planes[VF_PLANE_COUNT];
core::aabbox3d<f32> boundingBox;
private:
enum E_TRANSFORMATION_STATE_FRUSTUM
{
ETS_VIEW = 0,
ETS_PROJECTION = 1,
ETS_COUNT_FRUSTUM
};
core::matrix4 Matrices[ETS_COUNT_FRUSTUM];
};
inline SViewFrustum::SViewFrustum(const SViewFrustum& other)
{
cameraPosition=other.cameraPosition;
boundingBox=other.boundingBox;
u32 i;
for (i=0; i<VF_PLANE_COUNT; ++i)
planes[i]=other.planes[i];
for (i=0; i<ETS_COUNT_FRUSTUM; ++i)
Matrices[i]=other.Matrices[i];
}
inline SViewFrustum::SViewFrustum(const core::matrix4& mat)
{
setFrom ( mat );
}
inline void SViewFrustum::transform(const core::matrix4& mat)
{
for (u32 i=0; i<VF_PLANE_COUNT; ++i)
mat.transformPlane(planes[i]);
mat.transformVect(cameraPosition);
recalculateBoundingBox();
}
inline core::vector3df SViewFrustum::getFarLeftUp() const
{
core::vector3df p;
planes[scene::SViewFrustum::VF_FAR_PLANE].getIntersectionWithPlanes(
planes[scene::SViewFrustum::VF_TOP_PLANE],
planes[scene::SViewFrustum::VF_LEFT_PLANE], p);
return p;
}
inline core::vector3df SViewFrustum::getFarLeftDown() const
{
core::vector3df p;
planes[scene::SViewFrustum::VF_FAR_PLANE].getIntersectionWithPlanes(
planes[scene::SViewFrustum::VF_BOTTOM_PLANE],
planes[scene::SViewFrustum::VF_LEFT_PLANE], p);
return p;
}
inline core::vector3df SViewFrustum::getFarRightUp() const
{
core::vector3df p;
planes[scene::SViewFrustum::VF_FAR_PLANE].getIntersectionWithPlanes(
planes[scene::SViewFrustum::VF_TOP_PLANE],
planes[scene::SViewFrustum::VF_RIGHT_PLANE], p);
return p;
}
inline core::vector3df SViewFrustum::getFarRightDown() const
{
core::vector3df p;
planes[scene::SViewFrustum::VF_FAR_PLANE].getIntersectionWithPlanes(
planes[scene::SViewFrustum::VF_BOTTOM_PLANE],
planes[scene::SViewFrustum::VF_RIGHT_PLANE], p);
return p;
}
inline core::vector3df SViewFrustum::getNearLeftUp() const
{
core::vector3df p;
planes[scene::SViewFrustum::VF_NEAR_PLANE].getIntersectionWithPlanes(
planes[scene::SViewFrustum::VF_TOP_PLANE],
planes[scene::SViewFrustum::VF_LEFT_PLANE], p);
return p;
}
inline core::vector3df SViewFrustum::getNearLeftDown() const
{
core::vector3df p;
planes[scene::SViewFrustum::VF_NEAR_PLANE].getIntersectionWithPlanes(
planes[scene::SViewFrustum::VF_BOTTOM_PLANE],
planes[scene::SViewFrustum::VF_LEFT_PLANE], p);
return p;
}
inline core::vector3df SViewFrustum::getNearRightUp() const
{
core::vector3df p;
planes[scene::SViewFrustum::VF_NEAR_PLANE].getIntersectionWithPlanes(
planes[scene::SViewFrustum::VF_TOP_PLANE],
planes[scene::SViewFrustum::VF_RIGHT_PLANE], p);
return p;
}
inline core::vector3df SViewFrustum::getNearRightDown() const
{
core::vector3df p;
planes[scene::SViewFrustum::VF_NEAR_PLANE].getIntersectionWithPlanes(
planes[scene::SViewFrustum::VF_BOTTOM_PLANE],
planes[scene::SViewFrustum::VF_RIGHT_PLANE], p);
return p;
}
inline const core::aabbox3d<f32> &SViewFrustum::getBoundingBox() const
{
return boundingBox;
}
inline void SViewFrustum::recalculateBoundingBox()
{
boundingBox.reset ( cameraPosition );
boundingBox.addInternalPoint(getFarLeftUp());
boundingBox.addInternalPoint(getFarRightUp());
boundingBox.addInternalPoint(getFarLeftDown());
boundingBox.addInternalPoint(getFarRightDown());
}
inline void SViewFrustum::setFrom(const core::matrix4& mat)
{
// left clipping plane
planes[VF_LEFT_PLANE].Normal.X = mat[3 ] + mat[0];
planes[VF_LEFT_PLANE].Normal.Y = mat[7 ] + mat[4];
planes[VF_LEFT_PLANE].Normal.Z = mat[11] + mat[8];
planes[VF_LEFT_PLANE].D = mat[15] + mat[12];
// right clipping plane
planes[VF_RIGHT_PLANE].Normal.X = mat[3 ] - mat[0];
planes[VF_RIGHT_PLANE].Normal.Y = mat[7 ] - mat[4];
planes[VF_RIGHT_PLANE].Normal.Z = mat[11] - mat[8];
planes[VF_RIGHT_PLANE].D = mat[15] - mat[12];
// top clipping plane
planes[VF_TOP_PLANE].Normal.X = mat[3 ] - mat[1];
planes[VF_TOP_PLANE].Normal.Y = mat[7 ] - mat[5];
planes[VF_TOP_PLANE].Normal.Z = mat[11] - mat[9];
planes[VF_TOP_PLANE].D = mat[15] - mat[13];
// bottom clipping plane
planes[VF_BOTTOM_PLANE].Normal.X = mat[3 ] + mat[1];
planes[VF_BOTTOM_PLANE].Normal.Y = mat[7 ] + mat[5];
planes[VF_BOTTOM_PLANE].Normal.Z = mat[11] + mat[9];
planes[VF_BOTTOM_PLANE].D = mat[15] + mat[13];
// far clipping plane
planes[VF_FAR_PLANE].Normal.X = mat[3 ] - mat[2];
planes[VF_FAR_PLANE].Normal.Y = mat[7 ] - mat[6];
planes[VF_FAR_PLANE].Normal.Z = mat[11] - mat[10];
planes[VF_FAR_PLANE].D = mat[15] - mat[14];
// near clipping plane
planes[VF_NEAR_PLANE].Normal.X = mat[2];
planes[VF_NEAR_PLANE].Normal.Y = mat[6];
planes[VF_NEAR_PLANE].Normal.Z = mat[10];
planes[VF_NEAR_PLANE].D = mat[14];
// normalize normals
u32 i;
for ( i=0; i != VF_PLANE_COUNT; ++i)
{
const f32 len = -core::reciprocal_squareroot(
planes[i].Normal.getLengthSQ());
planes[i].Normal *= len;
planes[i].D *= len;
}
// make bounding box
recalculateBoundingBox();
}
inline core::matrix4& SViewFrustum::getTransform(video::E_TRANSFORMATION_STATE state )
{
u32 index = 0;
switch ( state )
{
case video::ETS_PROJECTION:
index = SViewFrustum::ETS_PROJECTION; break;
case video::ETS_VIEW:
index = SViewFrustum::ETS_VIEW; break;
default:
break;
}
return Matrices [ index ];
}
inline const core::matrix4& SViewFrustum::getTransform(video::E_TRANSFORMATION_STATE state ) const
{
u32 index = 0;
switch ( state )
{
case video::ETS_PROJECTION:
index = SViewFrustum::ETS_PROJECTION; break;
case video::ETS_VIEW:
index = SViewFrustum::ETS_VIEW; break;
default:
break;
}
return Matrices [ index ];
}
inline bool SViewFrustum::clipLine(core::line3d<f32>& line) const
{
bool wasClipped = false;
for (u32 i=0; i < VF_PLANE_COUNT; ++i)
{
if (planes[i].classifyPointRelation(line.start) == core::ISREL3D_FRONT)
{
line.start = line.start.getInterpolated(line.end,
1.f-planes[i].getKnownIntersectionWithLine(line.start, line.end));
wasClipped = true;
}
if (planes[i].classifyPointRelation(line.end) == core::ISREL3D_FRONT)
{
line.end = line.start.getInterpolated(line.end,
1.f-planes[i].getKnownIntersectionWithLine(line.start, line.end));
wasClipped = true;
}
}
return wasClipped;
}
} // end namespace scene
} // end namespace irr
#endif
IVideoDriver.h
aabbox3d.h
irr::core::CMatrix4::transformVect
void transformVect(vector3df &vect) const
Transforms the vector by this matrix.
Definition matrix4.h:1137
irr::core::CMatrix4::transformPlane
void transformPlane(core::plane3d< f32 > &plane) const
Transforms a plane by this matrix.
Definition matrix4.h:1179
irr::core::aabbox3d
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.h:22
irr::core::line3d
3D line between two points with intersection methods.
Definition line3d.h:19
irr::core::line3d::start
vector3d< T > start
Start point of line.
Definition line3d.h:130
irr::core::line3d::end
vector3d< T > end
End point of line.
Definition line3d.h:132
irr::core::plane3d
Template plane class with some intersection testing methods.
Definition plane3d.h:34
line3d.h
matrix4.h
irr::core::vector3df
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
irr::core::matrix4
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
Definition matrix4.h:2235
irr::core::ISREL3D_FRONT
@ ISREL3D_FRONT
Definition plane3d.h:19
irr::core::reciprocal_squareroot
REALINLINE f64 reciprocal_squareroot(const f64 x)
Definition irrMath.h:497
irr::scene
All scene management can be found in this namespace: Mesh loading, special scene nodes like octrees a...
Definition CDynamicMeshBuffer.h:16
irr::video::E_TRANSFORMATION_STATE
E_TRANSFORMATION_STATE
enumeration for geometry transformation states
Definition IVideoDriver.h:53
irr::video::ETS_VIEW
@ ETS_VIEW
View transformation.
Definition IVideoDriver.h:55
irr::video::ETS_PROJECTION
@ ETS_PROJECTION
Projection transformation.
Definition IVideoDriver.h:59
irr
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
irr::f32
float f32
32 bit floating point variable.
Definition irrTypes.h:104
irr::u32
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
plane3d.h
irr::scene::SViewFrustum
Defines the view frustum. That's the space visible by the camera.
Definition SViewFrustum.h:26
irr::scene::SViewFrustum::getBoundingBox
const core::aabbox3d< f32 > & getBoundingBox() const
returns a bounding box enclosing the whole view frustum
Definition SViewFrustum.h:238
irr::scene::SViewFrustum::setFrom
void setFrom(const core::matrix4 &mat)
This constructor creates a view frustum based on a projection and/or view matrix.
Definition SViewFrustum.h:255
irr::scene::SViewFrustum::getFarRightUp
core::vector3df getFarRightUp() const
returns the point which is on the far right top corner inside the the view frustum.
Definition SViewFrustum.h:178
irr::scene::SViewFrustum::recalculateBoundingBox
void recalculateBoundingBox()
recalculates the bounding box member based on the planes
Definition SViewFrustum.h:243
irr::scene::SViewFrustum::getNearRightUp
core::vector3df getNearRightUp() const
returns the point which is on the near right top corner inside the the view frustum.
Definition SViewFrustum.h:218
irr::scene::SViewFrustum::getNearRightDown
core::vector3df getNearRightDown() const
returns the point which is on the near right bottom corner inside the the view frustum.
Definition SViewFrustum.h:228
irr::scene::SViewFrustum::SViewFrustum
SViewFrustum()
Default Constructor.
Definition SViewFrustum.h:48
irr::scene::SViewFrustum::cameraPosition
core::vector3df cameraPosition
the position of the camera
Definition SViewFrustum.h:104
irr::scene::SViewFrustum::getFarLeftDown
core::vector3df getFarLeftDown() const
returns the point which is on the far left bottom corner inside the the view frustum.
Definition SViewFrustum.h:168
irr::scene::SViewFrustum::clipLine
bool clipLine(core::line3d< f32 > &line) const
clips a line to the view frustum.
Definition SViewFrustum.h:344
irr::scene::SViewFrustum::getFarLeftUp
core::vector3df getFarLeftUp() const
returns the point which is on the far left upper corner inside the the view frustum.
Definition SViewFrustum.h:158
irr::scene::SViewFrustum::getFarRightDown
core::vector3df getFarRightDown() const
returns the point which is on the far right bottom corner inside the the view frustum.
Definition SViewFrustum.h:188
irr::scene::SViewFrustum::getTransform
core::matrix4 & getTransform(video::E_TRANSFORMATION_STATE state)
get the given state's matrix based on frustum E_TRANSFORMATION_STATE
Definition SViewFrustum.h:310
irr::scene::SViewFrustum::boundingBox
core::aabbox3d< f32 > boundingBox
bounding box around the view frustum
Definition SViewFrustum.h:110
irr::scene::SViewFrustum::getNearLeftUp
core::vector3df getNearLeftUp() const
returns the point which is on the near left upper corner inside the the view frustum.
Definition SViewFrustum.h:198
irr::scene::SViewFrustum::VFPLANES
VFPLANES
Definition SViewFrustum.h:28
irr::scene::SViewFrustum::VF_FAR_PLANE
@ VF_FAR_PLANE
Far plane of the frustum. That is the plane farest away from the eye.
Definition SViewFrustum.h:30
irr::scene::SViewFrustum::VF_LEFT_PLANE
@ VF_LEFT_PLANE
Left plane of the frustum.
Definition SViewFrustum.h:34
irr::scene::SViewFrustum::VF_PLANE_COUNT
@ VF_PLANE_COUNT
Amount of planes enclosing the view frustum. Should be 6.
Definition SViewFrustum.h:43
irr::scene::SViewFrustum::VF_BOTTOM_PLANE
@ VF_BOTTOM_PLANE
Bottom plane of the frustum.
Definition SViewFrustum.h:38
irr::scene::SViewFrustum::VF_RIGHT_PLANE
@ VF_RIGHT_PLANE
Right plane of the frustum.
Definition SViewFrustum.h:36
irr::scene::SViewFrustum::VF_NEAR_PLANE
@ VF_NEAR_PLANE
Near plane of the frustum. That is the plane nearest to the eye.
Definition SViewFrustum.h:32
irr::scene::SViewFrustum::VF_TOP_PLANE
@ VF_TOP_PLANE
Top plane of the frustum.
Definition SViewFrustum.h:40
irr::scene::SViewFrustum::getNearLeftDown
core::vector3df getNearLeftDown() const
returns the point which is on the near left bottom corner inside the the view frustum.
Definition SViewFrustum.h:208
irr::scene::SViewFrustum::transform
void transform(const core::matrix4 &mat)
transforms the frustum by the matrix
Definition SViewFrustum.h:148
irr::scene::SViewFrustum::planes
core::plane3d< f32 > planes[VF_PLANE_COUNT]
all planes enclosing the view frustum.
Definition SViewFrustum.h:107
vector3d.h
- Irrlicht Engine Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on for Irrlicht 3D Engine by Doxygen 1.15.0