]>
Dogcows Code - chaz/yoink/blob - src/moof/frustum.cc
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
20 void frustum::init(const matrix4
& modelview
, const matrix4
& projection
)
24 extract_frustum_planes(modelview
, projection
, planes
, z_clip_neg_one
);
26 planes_
[0] = plane(planes
[0][0], planes
[0][1],
27 planes
[0][2], planes
[0][3]);
28 planes_
[1] = plane(planes
[1][0], planes
[1][1],
29 planes
[1][2], planes
[1][3]);
30 planes_
[2] = plane(planes
[2][0], planes
[2][1],
31 planes
[2][2], planes
[2][3]);
32 planes_
[3] = plane(planes
[3][0], planes
[3][1],
33 planes
[3][2], planes
[3][3]);
34 planes_
[4] = plane(planes
[4][0], planes
[4][1],
35 planes
[4][2], planes
[4][3]);
36 planes_
[5] = plane(planes
[5][0], planes
[5][1],
37 planes
[5][2], planes
[5][3]);
40 void frustum::init(const matrix4
& modelview
, scalar fovy
, scalar aspect
,
41 scalar abutting
, scalar distant
)
45 matrix_perspective_yfov_RH(projection
, fovy
, aspect
, abutting
,
46 distant
, z_clip_neg_one
);
48 init(modelview
, projection
);
51 frustum::collision
frustum::contains(const aabb
<3>& aabb
) const
56 aabb
.get_corners(corners
);
58 for (int i
= 0; i
< 6; ++i
)
62 for (int j
= 0; j
< 8; ++j
)
64 if (planes_
[i
].intersects(corners
[j
]) == plane::negative
)
70 if (nInside
== 0) return outside
;
71 else if (nInside
== 8) ++nTotalInside
;
74 if (nTotalInside
== 6) return inside
;
75 else return intersecting
;
79 frustum::collision
frustum::contains(const sphere
<3>& sphere
) const
81 for (int i
= 0; i
< 6; ++i
)
83 plane::halfspace halfspace
= planes_
[i
].intersects(sphere
);
85 if (halfspace
== plane::negative
) return outside
;
86 else if (halfspace
== plane::intersecting
) return intersecting
;
This page took 0.04799 seconds and 4 git commands to generate.