1 #ifndef INCLUDE_AL_FRUSTUM_HPP
2 #define INCLUDE_AL_FRUSTUM_HPP
45 #include "al/math/al_Plane.hpp"
46 #include "al/math/al_Vec.hpp"
67 enum { TOP = 0, BOTTOM, LEFT, RIGHT, NEARP, FARP };
68 enum { OUTSIDE = 0, INTERSECT, INSIDE };
73 const Vec<3, T>& corner(
int i)
const {
return (&ntl)[i]; }
75 const Vec<3, T>& corner(
int i0,
int i1,
int i2)
const {
76 return corner(i2 << 2 | i1 << 1 | i0);
83 lerp(frac[1], lerp(frac[0], corner(0, 0, 0), corner(1, 0, 0)),
84 lerp(frac[0], corner(0, 1, 0), corner(1, 1, 0))),
85 lerp(frac[1], lerp(frac[0], corner(0, 0, 1), corner(1, 0, 1)),
86 lerp(frac[0], corner(0, 1, 1), corner(1, 1, 1))));
114 return (ntl + ntr + nbl + nbr + ftl + ftr + fbl +
fbr) * 0.125;
124 template <
class Tf,
class Tv>
125 static Tv lerp(Tf f,
const Tv& x,
const Tv& y) {
126 return (y - x) * f + x;
136 for (
int i = 1; i < 8; ++i) {
158 for (
int i = 0; i < 6; ++i) {
159 if (pl[i].inNegativeSpace(p))
return OUTSIDE;
167 for (
int i = 0; i < 6; ++i) {
171 else if (distance < r)
180 for (
int i = 0; i < 6; ++i) {
195 if (plNrm[0] > 0) vp[0] += dim[0];
196 if (plNrm[1] > 0) vp[1] += dim[1];
197 if (plNrm[2] > 0) vp[2] += dim[2];
198 if (pl[i].inNegativeSpace(vp))
return OUTSIDE;
202 if (plNrm[0] < 0) vn[0] += dim[0];
203 if (plNrm[1] < 0) vn[1] += dim[1];
204 if (plNrm[2] < 0) vn[2] += dim[2];
205 if (pl[i].inNegativeSpace(vn)) result = INTERSECT;
int testBox(const Vec< 3, T > &xyz, const Vec< 3, T > &dim) const
Test whether axis-aligned box is in frustum.
int testPoint(const Vec< 3, T > &p) const
Test whether point is in frustum.
int testSphere(const Vec< 3, T > ¢er, float radius) const
Test whether sphere is in frustum.
Vec< 3, T > getPoint(const Vec< 3, U > &frac) const
Get point in frustum corresponding to fraction along edges.
Vec< 3, T > getPoint(const U &fracx, const U &fracy, const U &fracz) const
Get point in frustum corresponding to fraction along edges.
void boundingBox(Vec< 3, V > &xyz, Vec< 3, V > &dim) const
Get axis-aligned bounding box.
Vec< 3, T > center() const
Returns center of frustum.
void computePlanes()
Compute planes based on frustum corners (planes face to inside)
T distance(const Vec3 &p) const
Returns distance from plane to point (measured relative to plane normal)
const Vec3 & normal() const
Get normal perpendicular to plane (a, b, and c components)
Plane & from3Points(const Vec3 &v1, const Vec3 &v2, const Vec3 &v3)
Set from three points lying on the plane.
T min(const T &v1, const T &v2, const T &v3)
T max(const T &v1, const T &v2, const T &v3)
Frustum< double > Frustumd
Double precision frustrum.