]>
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 **************************************************************************/
12 #include <Moof/Aabb.hh>
13 #include <Moof/Frustum.hh>
14 #include <Moof/Sphere.hh>
20 void Frustum::init(const Matrix4
& modelview
, const Matrix4
& projection
)
24 cml::extract_frustum_planes(modelview
, projection
, planes
,
27 mPlanes
[0] = Plane(planes
[0][0], planes
[0][1],
28 planes
[0][2], planes
[0][3]);
29 mPlanes
[1] = Plane(planes
[1][0], planes
[1][1],
30 planes
[1][2], planes
[1][3]);
31 mPlanes
[2] = Plane(planes
[2][0], planes
[2][1],
32 planes
[2][2], planes
[2][3]);
33 mPlanes
[3] = Plane(planes
[3][0], planes
[3][1],
34 planes
[3][2], planes
[3][3]);
35 mPlanes
[4] = Plane(planes
[4][0], planes
[4][1],
36 planes
[4][2], planes
[4][3]);
37 mPlanes
[5] = Plane(planes
[5][0], planes
[5][1],
38 planes
[5][2], planes
[5][3]);
41 void Frustum::init(const Matrix4
& modelview
, Scalar fovy
, Scalar aspect
,
42 Scalar abutting
, Scalar distant
)
46 cml::matrix_perspective_yfov_RH(projection
, fovy
, aspect
, abutting
,
47 distant
, cml::z_clip_neg_one
);
49 init(modelview
, projection
);
52 Frustum::Collision
Frustum::contains(const Aabb
<3>& aabb
) const
57 aabb
.getCorners(corners
);
59 for (int i
= 0; i
< 6; ++i
)
63 for (int j
= 0; j
< 8; ++j
)
65 if (mPlanes
[i
].intersects(corners
[j
]) == Plane::NEGATIVE
)
71 if (nInside
== 0) return OUTSIDE
;
72 else if (nInside
== 8) ++nTotalInside
;
75 if (nTotalInside
== 6) return INSIDE
;
76 else return INTERSECT
;
80 Frustum::Collision
Frustum::contains(const Sphere
<3>& sphere
) const
82 for (int i
= 0; i
< 6; ++i
)
84 Plane::Halfspace halfspace
= mPlanes
[i
].intersects(sphere
);
86 if (halfspace
== Plane::NEGATIVE
) return OUTSIDE
;
87 else if (halfspace
== Plane::INTERSECT
) return INTERSECT
;
This page took 0.038819 seconds and 4 git commands to generate.