]>
Dogcows Code - chaz/yoink/blob - src/moof/frustum.cc
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
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.
8 *****************************************************************************/
18 void frustum::init(const matrix4
& modelview
, const matrix4
& projection
)
21 extract_frustum_planes(modelview
, projection
, planes
, z_clip_neg_one
);
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]);
31 void frustum::init(const matrix4
& modelview
, scalar fovy
, scalar aspect
,
32 scalar abutting
, scalar distant
)
35 matrix_perspective_yfov_RH(projection
,
36 fovy
, aspect
, abutting
, distant
, z_clip_neg_one
);
37 init(modelview
, projection
);
40 frustum::collision
frustum::contains(const aabb
<3>& aabb
) const
44 aabb
.get_corners(corners
);
46 for (int i
= 0; i
< 6; ++i
)
49 for (int j
= 0; j
< 8; ++j
)
51 if (planes_
[i
].intersects(corners
[j
]) == plane::negative
)
54 if (num
== 0) return outside
;
55 else if (num
== 8) ++total
;
58 if (total
== 6) return inside
;
62 frustum::collision
frustum::contains(const sphere3
& sphere
) const
64 for (int i
= 0; i
< 6; ++i
)
66 plane::halfspace halfspace
= planes_
[i
].intersects(sphere
);
67 if (halfspace
== plane::negative
) return outside
;
68 else if (halfspace
== plane::intersecting
) return intersecting
;
This page took 0.041154 seconds and 4 git commands to generate.