Created
April 10, 2014 17:42
-
-
Save greggman/10405738 to your computer and use it in GitHub Desktop.
Set a frustum to a sub rect of a larger view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SetFrustumToSubRectOfLargerView( | |
float fullWidth, // width of large 'virtual' monitor that other views will be sub rect of | |
float fullHeight, // height of large 'virtual' monitor that other views will be sub rect of | |
float subRectX, // left edge of sub rect for this view | |
float subRectY, // top edge of sub rect for this view | |
float subRectWidth, // width of sub rect for this view | |
float subRectHeight, // height of sub rect fo this view | |
float fovInRadians, // field of view in radians for fullwidth x fullheight view. | |
float zNear, // z near clipping plane | |
float zFar) // z far clipping plane | |
{ | |
float aspect = fullWidth / fullHeight; | |
float top = tanf(fovInRadians * 0.5f) * zNear; | |
float bottom = -top; | |
float left = aspect * bottom; | |
float right = aspect * top; | |
float width = fabs(right - left); | |
float height = fabs(top - bottom); | |
gluFrustum( | |
left + subRectX * width / fullWidth, | |
left + (subRectX + subRectWidth) * width / fullWidth, | |
top - (subRectY + subRectHeight) * height / fullHeight, | |
top - subRectY * height / fullHeight, | |
zNear, | |
zFar | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment