Added Frustum::Contains(AxisAlignedBox)
Fixed Frustum::Contains, Intersect and Plane::Distance not being const Former-commit-id: e219a10fac78f50743f19ebe523345bcac0b0fb7
This commit is contained in:
parent
6bfe9c8890
commit
28ea9fc9a0
|
|
@ -8,6 +8,7 @@
|
|||
#define NAZARA_FRUSTUM_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/AxisAlignedBox.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Plane.hpp>
|
||||
|
|
@ -25,10 +26,11 @@ class NzFrustum
|
|||
|
||||
NzFrustum& Build(T angle, T ratio, T zNear, T zFar, const NzVector3<T>& eye, const NzVector3<T>& target, const NzVector3<T>& up = NzVector3<T>::Up());
|
||||
|
||||
bool Contains(const NzCube<T>& cube);
|
||||
bool Contains(const NzSphere<T>& sphere);
|
||||
bool Contains(const NzVector3<T>& point);
|
||||
bool Contains(const NzVector3<T>* points, unsigned int pointCount);
|
||||
bool Contains(const NzAxisAlignedBox<T>& box) const;
|
||||
bool Contains(const NzCube<T>& cube) const;
|
||||
bool Contains(const NzSphere<T>& sphere) const;
|
||||
bool Contains(const NzVector3<T>& point) const;
|
||||
bool Contains(const NzVector3<T>* points, unsigned int pointCount) const;
|
||||
|
||||
NzFrustum& Extract(const NzMatrix4<T>& clipMatrix);
|
||||
NzFrustum& Extract(const NzMatrix4<T>& view, const NzMatrix4<T>& projection);
|
||||
|
|
@ -36,9 +38,10 @@ class NzFrustum
|
|||
const NzVector3<T>& GetCorner(nzCorner corner) const;
|
||||
const NzPlane<T>& GetPlane(nzFrustumPlane plane) const;
|
||||
|
||||
nzIntersectionSide Intersect(const NzAxisAlignedBox<T>& box) const;
|
||||
nzIntersectionSide Intersect(const NzCube<T>& cube) const;
|
||||
nzIntersectionSide Intersect(const NzSphere<T>& sphere) const;
|
||||
nzIntersectionSide Intersect(const NzVector3<T>* points, unsigned int pointCount);
|
||||
nzIntersectionSide Intersect(const NzVector3<T>* points, unsigned int pointCount) const;
|
||||
|
||||
NzFrustum& Set(const NzFrustum& frustum);
|
||||
template<typename U> NzFrustum& Set(const NzFrustum<U>& frustum);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,26 @@ NzFrustum<T>& NzFrustum<T>::Build(T angle, T ratio, T zNear, T zFar, const NzVec
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzFrustum<T>::Contains(const NzCube<T>& cube)
|
||||
bool NzFrustum<T>::Contains(const NzAxisAlignedBox<T>& box) const
|
||||
{
|
||||
switch (box.extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return Contains(box.cube);
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return true;
|
||||
|
||||
case nzExtend_Null:
|
||||
return false;
|
||||
}
|
||||
|
||||
NazaraError("Invalid extend type (0x" + NzString::Number(box.extend, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzFrustum<T>::Contains(const NzCube<T>& cube) const
|
||||
{
|
||||
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/
|
||||
for(unsigned int i = 0; i <= nzFrustumPlane_Max; i++)
|
||||
|
|
@ -79,7 +98,7 @@ bool NzFrustum<T>::Contains(const NzCube<T>& cube)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzFrustum<T>::Contains(const NzSphere<T>& sphere)
|
||||
bool NzFrustum<T>::Contains(const NzSphere<T>& sphere) const
|
||||
{
|
||||
for(unsigned int i = 0; i <= nzFrustumPlane_Max; i++)
|
||||
{
|
||||
|
|
@ -91,7 +110,7 @@ bool NzFrustum<T>::Contains(const NzSphere<T>& sphere)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzFrustum<T>::Contains(const NzVector3<T>& point)
|
||||
bool NzFrustum<T>::Contains(const NzVector3<T>& point) const
|
||||
{
|
||||
for(unsigned int i = 0; i <= nzFrustumPlane_Max; ++i)
|
||||
{
|
||||
|
|
@ -103,7 +122,7 @@ bool NzFrustum<T>::Contains(const NzVector3<T>& point)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzFrustum<T>::Contains(const NzVector3<T>* points, unsigned int pointCount)
|
||||
bool NzFrustum<T>::Contains(const NzVector3<T>* points, unsigned int pointCount) const
|
||||
{
|
||||
for (unsigned int i = 0; i <= nzFrustumPlane_Max; ++i)
|
||||
{
|
||||
|
|
@ -327,6 +346,25 @@ const NzPlane<T>& NzFrustum<T>::GetPlane(nzFrustumPlane plane) const
|
|||
return m_planes[plane];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
nzIntersectionSide NzFrustum<T>::Intersect(const NzAxisAlignedBox<T>& box) const
|
||||
{
|
||||
switch (box.extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
return Intersect(box.cube);
|
||||
|
||||
case nzExtend_Infinite:
|
||||
return nzIntersectionSide_Intersecting;
|
||||
|
||||
case nzExtend_Null:
|
||||
return nzIntersectionSide_Outside;
|
||||
}
|
||||
|
||||
NazaraError("Invalid extend type (0x" + NzString::Number(box.extend, 16) + ')');
|
||||
return nzIntersectionSide_Outside;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
nzIntersectionSide NzFrustum<T>::Intersect(const NzCube<T>& cube) const
|
||||
{
|
||||
|
|
@ -363,7 +401,7 @@ nzIntersectionSide NzFrustum<T>::Intersect(const NzSphere<T>& sphere) const
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
nzIntersectionSide NzFrustum<T>::Intersect(const NzVector3<T>* points, unsigned int pointCount)
|
||||
nzIntersectionSide NzFrustum<T>::Intersect(const NzVector3<T>* points, unsigned int pointCount) const
|
||||
{
|
||||
unsigned int c = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ class NzPlane
|
|||
NzPlane(const NzPlane& plane) = default;
|
||||
~NzPlane() = default;
|
||||
|
||||
T Distance(const NzVector3<T>& point);
|
||||
T Distance(T x, T y, T z);
|
||||
T Distance(const NzVector3<T>& point) const;
|
||||
T Distance(T x, T y, T z) const;
|
||||
|
||||
NzPlane& Set(T normalX, T normalY, T normalZ, T Distance);
|
||||
NzPlane& Set(const T plane[4]);
|
||||
|
|
|
|||
|
|
@ -47,13 +47,13 @@ NzPlane<T>::NzPlane(const NzPlane<U>& plane)
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
T NzPlane<T>::Distance(const NzVector3<T>& point)
|
||||
T NzPlane<T>::Distance(const NzVector3<T>& point) const
|
||||
{
|
||||
return normal.DotProduct(point) + distance;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzPlane<T>::Distance(T x, T y, T z)
|
||||
T NzPlane<T>::Distance(T x, T y, T z) const
|
||||
{
|
||||
return Distance(NzVector3<T>(x, y, z));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue