Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "cinder/AxisAlignedBox.h"
00027 #include "cinder/Camera.h"
00028 #include "cinder/Plane.h"
00029 #include "cinder/Sphere.h"
00030
00031 #pragma once
00032
00033 #if defined( CINDER_MSW )
00034 #pragma push_macro( "NEAR" )
00035 #undef NEAR
00036 #pragma push_macro( "FAR" )
00037 #undef FAR
00038 #endif
00039
00040 namespace cinder {
00041
00042 template<typename T>
00043 class Frustum
00044 {
00045 public:
00046 enum { NEAR, FAR, LEFT, RIGHT, TOP, BOTTOM };
00047
00048 public:
00049 Frustum() {}
00050 Frustum( const Camera &cam );
00051
00053 void set( const Camera &cam );
00055 void set( const Camera &cam, const Vec3<T> &ntl, const Vec3<T> &ntr, const Vec3<T> &nbl, const Vec3<T> &nbr );
00056
00058 bool contains( const Vec3<T> &loc ) const;
00060 bool contains( const Sphere &sphere ) const { return contains(sphere.getCenter(), sphere.getRadius()); };
00062 bool contains( const Vec3<T> ¢er, T radius ) const;
00064 bool contains( const AxisAlignedBox3f &box ) const;
00066 bool contains( const Vec3<T> ¢er, const Vec3<T> &size ) const {
00067 AxisAlignedBox3f box(center-0.5f*size, center+0.5f*size);
00068 return contains(box);
00069 };
00070
00072 bool intersects( const Vec3<T> &loc ) const { return contains(loc); };
00074 bool intersects( const Sphere &sphere ) const { return intersects(sphere.getCenter(), sphere.getRadius()); };
00076 bool intersects( const Vec3<T> ¢er, T radius ) const;
00078 bool intersects( const AxisAlignedBox3f &box ) const;
00080 bool intersects( const Vec3<T> ¢er, const Vec3<T> &size ) const {
00081 AxisAlignedBox3f box(center-0.5f*size, center+0.5f*size);
00082 return intersects(box);
00083 };
00084
00085 protected:
00086 Plane<T> mFrustumPlanes[6];
00087 };
00088
00089 typedef Frustum<float> Frustumf;
00090 typedef Frustum<double> Frustumd;
00091
00092 #if defined( CINDER_MSW )
00093 #pragma pop_macro( "FAR" )
00094 #pragma pop_macro( "NEAR" )
00095 #endif
00096
00097 }