/** * Returns a guaranteed upper bound for the size that a world-space unit (e.g. a line with length 1) has in pixels * after perspective projection, i.e. in pixels on the screen. * * @param dist * distance of the object (from the point-of-view) * @return maximum number of pixels that an object of size 1 will cover */ public double estimatePixelSizeForSpaceUnit( double dist ) { double h = 2.0 * dist * (float) Math.tan( Math.toRadians( vf.getFOVY() * 0.5f ) ); return projectionHeight / h; }
/** * Set the new projection plane dimensions * * @param width * @param height */ public void setProjectionPlaneDimensions( int width, int height ) { projectionWidth = width; projectionHeight = height; double aspect = (double) width / height; vf.setPerspectiveParams( vf.getFOVY(), aspect, vf.getZNear(), vf.getZFar() ); vf.setCameraParams( vf.getEyePos(), vf.getLookingAt(), vf.getUp() ); }
/** * @param gl */ private void reshape( GL gl ) { float aspect = (float) width / (float) height; LOG.trace( "reshape( GLAutoDrawable, " + 0 + ", " + 0 + ", " + width + ", " + height + " ) called, aspect: " + aspect ); gl.glMatrixMode( GL.GL_PROJECTION ); gl.glLoadIdentity(); gl.glViewport( 0, 0, width, height ); glu.gluPerspective( viewParams.getViewFrustum().getFOVY(), aspect, viewParams.getViewFrustum().getZNear(), viewParams.getViewFrustum().getZFar() ); gl.glMatrixMode( GL.GL_MODELVIEW ); }
@Override public void reshape( GLAutoDrawable drawable, int x, int y, int width, int height ) { float aspect = (float) width / (float) height; LOG.info( "reshape( GLAutoDrawable, " + x + ", " + y + ", " + width + ", " + height + " ) called, aspect: " + aspect ); params.setProjectionPlaneDimensions( width, height ); GL gl = drawable.getGL(); gl.glViewport( x, y, width, height ); gl.glMatrixMode( GL.GL_PROJECTION ); gl.glLoadIdentity(); glu.gluPerspective( params.getViewFrustum().getFOVY(), aspect, params.getViewFrustum().getZNear(), params.getViewFrustum().getZFar() ); // glu.gluPerspective( params.getViewFrustum().getFOVY(), aspect, 0.01, 1000 ); gl.glMatrixMode( GL.GL_MODELVIEW ); }