11void mFrustum_c::set(f32 top, f32 bottom, f32 left, f32 right, f32 near, f32 far,
const mMtx_c &cameraMtx,
bool orthographic) {
16 PSMTXInverse(cameraMtx, invCameraMtx);
17 PSMTXCopy(cameraMtx, mCamMtx);
22 pts[POINT_NEAR_TL].set(left, top, -near);
23 pts[POINT_NEAR_TR].set(right, top, -near);
24 pts[POINT_NEAR_BR].set(right, bottom, -near);
25 pts[POINT_NEAR_BL].set(left, bottom, -near);
27 pts[POINT_FAR_TL].z = -far;
28 pts[POINT_FAR_TR].z = -far;
29 pts[POINT_FAR_BR].z = -far;
30 pts[POINT_FAR_BL].z = -far;
33 pts[POINT_FAR_TL].x = left;
34 pts[POINT_FAR_TL].y = top;
35 pts[POINT_FAR_TR].x = right;
36 pts[POINT_FAR_TR].y = top;
37 pts[POINT_FAR_BR].x = right;
38 pts[POINT_FAR_BR].y = bottom;
39 pts[POINT_FAR_BL].x = left;
40 pts[POINT_FAR_BL].y = bottom;
42 mPlaneL.Set(&pts[POINT_NEAR_BL], &pts[POINT_FAR_BL], &pts[POINT_NEAR_TL]);
43 mPlaneR.Set(&pts[POINT_NEAR_TR], &pts[POINT_FAR_TR], &pts[POINT_NEAR_BR]);
44 mPlaneT.Set(&pts[POINT_NEAR_TL], &pts[POINT_FAR_TL], &pts[POINT_NEAR_TR]);
45 mPlaneB.Set(&pts[POINT_NEAR_BR], &pts[POINT_FAR_BR], &pts[POINT_NEAR_BL]);
47 for (
int i = 0; i < POINT_MAX; i++) {
48 PSMTXMultVec(invCameraMtx, pts[i], pts[i]);
51 mPlanes[PLANE_L].Set(&pts[POINT_NEAR_BL], &pts[POINT_FAR_BL], &pts[POINT_NEAR_TL]);
52 mPlanes[PLANE_R].Set(&pts[POINT_NEAR_TR], &pts[POINT_FAR_TR], &pts[POINT_NEAR_BR]);
53 mPlanes[PLANE_T].Set(&pts[POINT_NEAR_TL], &pts[POINT_FAR_TL], &pts[POINT_NEAR_TR]);
54 mPlanes[PLANE_B].Set(&pts[POINT_NEAR_BR], &pts[POINT_FAR_BR], &pts[POINT_NEAR_BL]);
56 f32 depthRatio = far / near;
58 eyePos.set(0.0f, 0.0f, 0.0f);
60 pts[POINT_FAR_TL].x = depthRatio * left;
61 pts[POINT_FAR_TL].y = depthRatio * top;
62 pts[POINT_FAR_TR].x = depthRatio * right;
63 pts[POINT_FAR_TR].y = depthRatio * top;
64 pts[POINT_FAR_BR].x = depthRatio * right;
65 pts[POINT_FAR_BR].y = depthRatio * bottom;
66 pts[POINT_FAR_BL].x = depthRatio * left;
67 pts[POINT_FAR_BL].y = depthRatio * bottom;
72 mPlaneL.Set(&eyePos, &pts[POINT_NEAR_BL], &pts[POINT_NEAR_TL]);
73 mPlaneR.Set(&eyePos, &pts[POINT_NEAR_TR], &pts[POINT_NEAR_BR]);
74 mPlaneT.Set(&eyePos, &pts[POINT_NEAR_TL], &pts[POINT_NEAR_TR]);
75 mPlaneB.Set(&eyePos, &pts[POINT_NEAR_BR], &pts[POINT_NEAR_BL]);
77 for (
int i = 0; i < POINT_MAX; i++) {
78 PSMTXMultVec(invCameraMtx, pts[i], pts[i]);
80 PSMTXMultVec(invCameraMtx, eyePos, eyePos);
82 mPlanes[PLANE_L].Set(&eyePos, &pts[POINT_NEAR_BL], &pts[POINT_NEAR_TL]);
83 mPlanes[PLANE_R].Set(&eyePos, &pts[POINT_NEAR_TR], &pts[POINT_NEAR_BR]);
84 mPlanes[PLANE_T].Set(&eyePos, &pts[POINT_NEAR_TL], &pts[POINT_NEAR_TR]);
85 mPlanes[PLANE_B].Set(&eyePos, &pts[POINT_NEAR_BR], &pts[POINT_NEAR_BL]);
88 mBox.Set(pts, POINT_MAX);
89 mPlanes[PLANE_N].Set(&pts[POINT_NEAR_TL], &pts[POINT_NEAR_TR], &pts[POINT_NEAR_BR]);
90 mPlanes[PLANE_F].Set(&pts[POINT_FAR_TL], &pts[POINT_FAR_BL], &pts[POINT_FAR_BR]);
96 sphereCenterPos.z = mCamMtx._20 * sphere->mCenter.x +
97 mCamMtx._21 * sphere->mCenter.y +
98 mCamMtx._22 * sphere->mCenter.z + mCamMtx._23;
100 if (sphereCenterPos.z - sphere->mRadius > mNearZ) {
103 if (sphereCenterPos.z + sphere->mRadius < mFarZ) {
107 sphereCenterPos.x = mCamMtx._00 * sphere->mCenter.x +
108 mCamMtx._01 * sphere->mCenter.y +
109 mCamMtx._02 * sphere->mCenter.z + mCamMtx._03;
111 if (sphereCenterPos.x * mPlaneL.n.x + sphereCenterPos.z * mPlaneL.n.z > sphere->mRadius) {
114 if (sphereCenterPos.x * mPlaneR.n.x + sphereCenterPos.z * mPlaneR.n.z > sphere->mRadius) {
118 sphereCenterPos.y = mCamMtx._10 * sphere->mCenter.x +
119 mCamMtx._11 * sphere->mCenter.y +
120 mCamMtx._12 * sphere->mCenter.z + mCamMtx._13;
122 if (sphereCenterPos.y * mPlaneT.n.y + sphereCenterPos.z * mPlaneT.n.z > sphere->mRadius) {
125 if (sphereCenterPos.y * mPlaneB.n.y + sphereCenterPos.z * mPlaneB.n.z > sphere->mRadius) {