1 // frustum.h
2 //
3 // Copyright (C) 2000-2008, Chris Laurel <claurel@shatters.net>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 
10 #ifndef _CELMATH_FRUSTUM_H_
11 #define _CELMATH_FRUSTUM_H_
12 
13 #include <celmath/plane.h>
14 #include <celmath/capsule.h>
15 
16 
17 class Frustum
18 {
19  public:
20     Frustum(float fov, float aspectRatio, float nearDist);
21     Frustum(float fov, float aspectRatio, float nearDist, float farDist);
22 
23     void transform(const Mat3f&);
24     void transform(const Mat4f&);
25 
26     inline Planef getPlane(int) const;
27 
28     enum {
29         Bottom    = 0,
30         Top       = 1,
31         Left      = 2,
32         Right     = 3,
33         Near      = 4,
34         Far       = 5,
35     };
36 
37     enum Aspect {
38         Outside   = 0,
39         Inside    = 1,
40         Intersect = 2,
41     };
42 
43     Aspect test(const Point3f&) const;
44     Aspect testSphere(const Point3f& center, float radius) const;
45     Aspect testSphere(const Point3d& center, double radius) const;
46     Aspect testCapsule(const Capsulef&) const;
47 
48  private:
49     void init(float, float, float, float);
50 
51     Planef planes[6];
52     bool infinite;
53 };
54 
getPlane(int which)55 Planef Frustum::getPlane(int which) const
56 {
57     return planes[which];
58 }
59 
60 #endif // _CELMATH_FRUSTUM_H_
61