]> Dogcows Code - chaz/yoink/blob - src/moof/frustum.cc
remove some unused stlplus modules
[chaz/yoink] / src / moof / frustum.cc
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #include "aabb.hh"
11 #include "frustum.hh"
12 #include "sphere.hh"
13
14
15 namespace moof {
16
17
18 void frustum::init(const matrix4& modelview, const matrix4& projection)
19 {
20 scalar planes[6][4];
21 extract_frustum_planes(modelview, projection, planes, z_clip_neg_one);
22
23 planes_[0] = plane(planes[0][0], planes[0][1], planes[0][2], planes[0][3]);
24 planes_[1] = plane(planes[1][0], planes[1][1], planes[1][2], planes[1][3]);
25 planes_[2] = plane(planes[2][0], planes[2][1], planes[2][2], planes[2][3]);
26 planes_[3] = plane(planes[3][0], planes[3][1], planes[3][2], planes[3][3]);
27 planes_[4] = plane(planes[4][0], planes[4][1], planes[4][2], planes[4][3]);
28 planes_[5] = plane(planes[5][0], planes[5][1], planes[5][2], planes[5][3]);
29 }
30
31 void frustum::init(const matrix4& modelview, scalar fovy, scalar aspect,
32 scalar abutting, scalar distant)
33 {
34 matrix4 projection;
35 matrix_perspective_yfov_RH(projection,
36 fovy, aspect, abutting, distant, z_clip_neg_one);
37 init(modelview, projection);
38 }
39
40 frustum::collision frustum::contains(const aabb<3>& aabb) const
41 {
42 int total = 0;
43 vector3 corners[8];
44 aabb.get_corners(corners);
45
46 for (int i = 0; i < 6; ++i)
47 {
48 int num = 8;
49 for (int j = 0; j < 8; ++j)
50 {
51 if (planes_[i].intersects(corners[j]) == plane::negative)
52 --num;
53 }
54 if (num == 0) return outside;
55 else if (num == 8) ++total;
56 }
57
58 if (total == 6) return inside;
59 return intersecting;
60 }
61
62 frustum::collision frustum::contains(const sphere3& sphere) const
63 {
64 for (int i = 0; i < 6; ++i)
65 {
66 plane::halfspace halfspace = planes_[i].intersects(sphere);
67 if (halfspace == plane::negative) return outside;
68 else if (halfspace == plane::intersecting) return intersecting;
69 }
70 return inside;
71 }
72
73
74 } // namespace moof
75
This page took 0.033928 seconds and 4 git commands to generate.