How To Resize Viewable Area To Show All Objects/coordinates?
Solution 1:
You want to change the view frustum. This is how I've done it in my android Renderer class:
intviewportWidth= -1;
intviewportHeight= -1;
intzoom=0.5f;
floatnearPlane=3.0f;
floatfarPlane=7.0f;
floatFOV=60.0f@OverridepublicvoidonSurfaceChanged(GL10 gl, int width, int height) {
viewportWidth = width;
viewportHeight = height;
gl.glViewport(0, 0, width, height);
setProjectionMatrix(gl);
}
@OverridepublicvoidonSurfaceCreated(GL10 gl, EGLConfig config) {
setProjectionMatrix(gl);
}
protectedvoidsetProjectionMatrix(GL10 gl){
if(viewportWidth <0 || viewportHeight <0){
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, FOV*zoom, 1.0f, nearPlane, farPlane);
} else {
floatratio= (float) viewportWidth / viewportHeight;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-ratio*zoom, ratio*zoom, -1*zoom, 1*zoom, nearPlane, farPlane);
}
}
As you can see, I mostly use glFrustumf, don't really use GLU.gluPerspective, and I don't use glOrthof at all, but that's not a problem. Depending on which method you use, you will get different results. Imagine you have a set of train tracks starting in front of you and going away from you. Using Orthographic projection, the tracks will still be the same distance apart when they hit the horizon as they do in front of you. With perspective projection, they appear to convege at some distant 'vanishing point'.
If you use my code as above, try also changing the near and far planes variables and also the zoom variable to see the effects it has on your program
Post a Comment for "How To Resize Viewable Area To Show All Objects/coordinates?"