Last active
June 18, 2020 16:04
-
-
Save pingpoli/f7dcca484f7403deafa0659d5090f4cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 render() | |
{ | |
// update camera based on mouse position, WASD, etc. | |
// calculate the view frustum | |
viewFrustum.calculate( 60.0f , (float)window->getWidth()/(float)window->getHeight() , 0.1f , 100.0f ); | |
// convert the view frustum to world space | |
viewFrustum.convertToWorldSpace( camera->getInverseViewMatrix() ); | |
const vec3& bottomLeft = viewFrustum.getNearBottomLeft(); | |
const vec3& bottomRight = viewFrustum.getNearBottomRight(); | |
// near clipping plane, left bottom vertex | |
float elevation = /* get the elevation of your terrain at the bottom left view frustum position, e.g. getTerrainHeight( bottomLeft.x , bottomLeft.z ); */; | |
if ( bottomLeft.y <= elevation ) | |
{ | |
// move the camera up | |
camera->setPosition( vec3( camera->getPosition().x , elevation + A_LITTLE_BIT_EXTRA , camera->getPosition().z ) ); | |
} | |
// near clipping plane, right bottom vertex | |
float elevation = /* get the elevation of your terrain at the bottom right view frustum position, e.g. getTerrainHeight( bottomRight.x , bottomRight.z ); */; | |
if ( bottomRight.y <= elevation ) | |
{ | |
// move the camera up | |
camera->setPosition( vec3( camera->getPosition().x , elevation + A_LITTLE_BIT_EXTRA , camera->getPosition().z ) ); | |
} | |
// do the rest of the rendering | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment