Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Frustum.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011, The Cinder Project, All rights reserved.
3  This code is intended for use with the Cinder C++ library: http://libcinder.org
4 
5  Portions of this code (C) Paul Houx
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
9  the following conditions are met:
10 
11  * Redistributions of source code must retain the above copyright notice, this list of conditions and
12  the following disclaimer.
13  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
14  the following disclaimer in the documentation and/or other materials provided with the distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
17  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
19  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23  POSSIBILITY OF SUCH DAMAGE.
24 */
25 
26 #include "cinder/AxisAlignedBox.h"
27 #include "cinder/Camera.h"
28 #include "cinder/Plane.h"
29 #include "cinder/Sphere.h"
30 
31 #pragma once
32 
33 #if defined( CINDER_MSW )
34  #pragma push_macro( "NEAR" )
35  #undef NEAR
36  #pragma push_macro( "FAR" )
37  #undef FAR
38 #endif
39 
40 namespace cinder {
41 
42 template<typename T>
43 class Frustum
44 {
45  public:
46  enum { NEAR, FAR, LEFT, RIGHT, TOP, BOTTOM };
47 
48  public:
49  Frustum() {}
50  Frustum( const Camera &cam );
51 
53  void set( const Camera &cam );
55  void set( const Camera &cam, const Vec3<T> &ntl, const Vec3<T> &ntr, const Vec3<T> &nbl, const Vec3<T> &nbr );
56 
58  bool contains( const Vec3<T> &loc ) const;
60  bool contains( const Sphere &sphere ) const { return contains(sphere.getCenter(), sphere.getRadius()); };
62  bool contains( const Vec3<T> &center, T radius ) const;
64  bool contains( const AxisAlignedBox3f &box ) const;
66  bool contains( const Vec3<T> &center, const Vec3<T> &size ) const {
67  AxisAlignedBox3f box(center-0.5f*size, center+0.5f*size);
68  return contains(box);
69  };
70 
72  bool intersects( const Vec3<T> &loc ) const { return contains(loc); };
74  bool intersects( const Sphere &sphere ) const { return intersects(sphere.getCenter(), sphere.getRadius()); };
76  bool intersects( const Vec3<T> &center, T radius ) const;
78  bool intersects( const AxisAlignedBox3f &box ) const;
80  bool intersects( const Vec3<T> &center, const Vec3<T> &size ) const {
81  AxisAlignedBox3f box(center-0.5f*size, center+0.5f*size);
82  return intersects(box);
83  };
84 
85  protected:
87 };
88 
91 
92 #if defined( CINDER_MSW )
93  #pragma pop_macro( "FAR" )
94  #pragma pop_macro( "NEAR" )
95 #endif
96 
97 } // namespace cinder
float getRadius() const
Definition: Sphere.h:37
Definition: Frustum.h:46
bool contains(const Sphere &sphere) const
Returns TRUE if the sphere is fully contained within frustum. See also 'intersects'.
Definition: Frustum.h:60
bool contains(const Vec3< T > &loc) const
Returns TRUE if point is within frustum.
Definition: Frustum.cpp:79
Definition: Frustum.h:43
bool intersects(const Vec3< T > &loc) const
Returns TRUE if point is within frustum.
Definition: Frustum.h:72
Definition: Camera.h:36
bool contains(const Vec3< T > &center, const Vec3< T > &size) const
Returns TRUE if the box is fully contained within frustum. See also 'intersects'. ...
Definition: Frustum.h:66
Plane< T > mFrustumPlanes[6]
Definition: Frustum.h:83
Definition: Vector.h:65
bool intersects(const Sphere &sphere) const
Returns TRUE if the sphere is partially contained within frustum. See also 'contains'.
Definition: Frustum.h:74
Definition: Plane.h:34
Frustum< float > Frustumf
Definition: Frustum.h:89
Definition: Sphere.h:32
Definition: Frustum.h:46
Definition: Frustum.h:46
bool intersects(const Vec3< T > &center, const Vec3< T > &size) const
Returns TRUE if the box is partially contained within frustum. See also 'contains'.
Definition: Frustum.h:80
const Vec3f & getCenter() const
Definition: Sphere.h:40
Frustum()
Definition: Frustum.h:49
Definition: Frustum.h:46
Frustum< double > Frustumd
Definition: Frustum.h:90
Definition: Frustum.h:46
void set(const Camera &cam)
Creates a frustum based on the camera's parameters.
Definition: Frustum.cpp:43
Definition: AxisAlignedBox.h:31
GLclampf f
Definition: GLee.h:15307
GLsizeiptr size
Definition: GLee.h:2089
Definition: Frustum.h:46