// 4. Intersect horizon, left and right to obtain the combined camera origin.
ERR_FAIL_COND_MSG(
!horizon.intersect_3(planes[0][CameraMatrix::PLANE_LEFT],planes[1][CameraMatrix::PLANE_RIGHT],&main_transform.origin),"Can't determine camera origin");
// handy to have the inverse of the transform we just build
// 6. Intersect far and left planes with top planes from both eyes, save the point with highest y as top_left.
Vector3top_left,other;
ERR_FAIL_COND_MSG(
!far.intersect_3(planes[0][CameraMatrix::PLANE_LEFT],planes[0][CameraMatrix::PLANE_TOP],&top_left),"Can't determine left camera far/left/top vector");
ERR_FAIL_COND_MSG(
!far.intersect_3(planes[1][CameraMatrix::PLANE_LEFT],planes[1][CameraMatrix::PLANE_TOP],&other),"Can't determine right camera far/left/top vector");
if(y.dot(top_left)<y.dot(other)){
top_left=other;
}
// 7. Intersect far and left planes with bottom planes from both eyes, save the point with lowest y as bottom_left.
Vector3bottom_left;
ERR_FAIL_COND_MSG(
!far.intersect_3(planes[0][CameraMatrix::PLANE_LEFT],planes[0][CameraMatrix::PLANE_BOTTOM],&bottom_left),"Can't determine left camera far/left/bottom vector");
ERR_FAIL_COND_MSG(
!far.intersect_3(planes[1][CameraMatrix::PLANE_LEFT],planes[1][CameraMatrix::PLANE_BOTTOM],&other),"Can't determine right camera far/left/bottom vector");
if(y.dot(other)<y.dot(bottom_left)){
bottom_left=other;
}
// 8. Intersect far and right planes with top planes from both eyes, save the point with highest y as top_right.
Vector3top_right;
ERR_FAIL_COND_MSG(
!far.intersect_3(planes[0][CameraMatrix::PLANE_RIGHT],planes[0][CameraMatrix::PLANE_TOP],&top_right),"Can't determine left camera far/right/top vector");
ERR_FAIL_COND_MSG(
!far.intersect_3(planes[1][CameraMatrix::PLANE_RIGHT],planes[1][CameraMatrix::PLANE_TOP],&other),"Can't determine right camera far/right/top vector");
if(y.dot(top_right)<y.dot(other)){
top_right=other;
}
// 9. Intersect far and right planes with bottom planes from both eyes, save the point with lowest y as bottom_right.
Vector3bottom_right;
ERR_FAIL_COND_MSG(
!far.intersect_3(planes[0][CameraMatrix::PLANE_RIGHT],planes[0][CameraMatrix::PLANE_BOTTOM],&bottom_right),"Can't determine left camera far/right/bottom vector");
ERR_FAIL_COND_MSG(
!far.intersect_3(planes[1][CameraMatrix::PLANE_RIGHT],planes[1][CameraMatrix::PLANE_BOTTOM],&other),"Can't determine right camera far/right/bottom vector");
if(y.dot(other)<y.dot(bottom_right)){
bottom_right=other;
}
// 10. Create top plane with these points: camera origin, top_left, top_right
// 15. get x and y from these to obtain left, top, right bottom for the frustum. Get the distance from near plane to camera origin to obtain near, and the distance from the far plane to the camer origin to obtain far.