/** * @param box * @return true if the box intersect with this viewfrustum. */ public boolean intersects( float[][] box ) { int classification = intersectsFrustum( box ); if ( classification == OUTSIDE ) { return false; } return true; }
private double calcMove() { double moveStep = vf.getEyePos().z / 50.0; if ( moveStep < 5 ) { moveStep = 5; } return moveStep; } }
/** * Rotate the viewfrustum around the z-axis (according to the view direction). yaw * * @param delta */ public void rotateZ( double delta ) { rotate( right, backward, delta ); rotate( up, backward, delta ); setCameraParams( eye, lookingAt, up ); }
/** * 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 ); }
/** * @param viewParams * to get the objects for. * @return the objects which intersect with the given view parameters and or it's children, or the empty list. */ public Set<T> getObjects( ViewParams viewParams ) { Set<T> result = new HashSet<T>(); Point3d e = viewParams.getViewFrustum().getEyePos(); float[] eye = new float[] { (float) e.x, (float) e.y, (float) e.z }; getObjects( viewParams, eye, result ); return result; }
/** * Create a view Frustum by using the given roll, pitch, yaw and distance to the point of interest (looking at), to * calculate the eye and the up vector. * * @param pitch * @param yaw * @param roll * @param distance * @param lookingAt * @param fovy * the field-of-view in y direction * @param aspect * @param zNear * @param zFar */ public ViewFrustum( double pitch, double yaw, double roll, double distance, Point3d lookingAt, double fovy, double aspect, double zNear, double zFar ) { Point3d calculatedEye = calcObserPosition( lookingAt, pitch, yaw, distance ); Vector3d calculatedUp = calcUp( roll, calculatedEye, lookingAt ); setPerspectiveParams( fovy, aspect, zNear, zFar ); setCameraParams( calculatedEye, lookingAt, calculatedUp ); }
private int intersectsFrustum( double[][] box ) { int result = INSIDE; // for each plane do ... for ( int i = 0; i < 6; i++ ) { // is the positive vertex outside? Point3d pVertex = pl[i].getPositiveVertex( box ); Point3d nVertex = pl[i].getNegativeVertex( box ); if ( pl[i].distance( pVertex ) < 0 ) { return OUTSIDE; } else if ( pl[i].distance( nVertex ) < 0 ) { result = INTERSECT; } } return result; }
public FlightControls( GLCanvas master, ViewParams viewParams ) { this.master = master; this.vf = viewParams.getViewFrustum(); }
/** * 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; }
private boolean isInViewVolume( Arc arc ) { float[][] scaledBBox = arc.getBBox(); scaledBBox[0][2] *= zScale; scaledBBox[1][2] *= zScale; return viewRegion.intersects( scaledBBox ); }
/** * * @param eye * @param lookingAt * @param viewerUp * @param fovy * @param zNear * @param zFar */ public ViewParams( Point3d eye, Point3d lookingAt, Vector3d viewerUp, double fovy, double zNear, double zFar ) { this.vf = new ViewFrustum( eye, lookingAt, viewerUp, fovy, 1.0, zNear, zFar ); }
/** * Create a viewFrustum from the given parameters. * * @param eye * @param lookingAt * @param up * @param fovy * the field-of-view in y direction * @param aspect * @param zNear * @param zFar */ public ViewFrustum( Point3d eye, Point3d lookingAt, Vector3d up, double fovy, double aspect, double zNear, double zFar ) { setPerspectiveParams( fovy, aspect, zNear, zFar ); setCameraParams( eye, lookingAt, up ); }
private int intersectsFrustum( float[][] box ) { int result = INSIDE; // for each plane do ... for ( int i = 0; i < 6; i++ ) { // is the positive vertex outside? Point3d pVertex = pl[i].getPositiveVertex( box ); Point3d nVertex = pl[i].getNegativeVertex( box ); if ( pl[i].distance( pVertex ) < 0 ) { return OUTSIDE; } else if ( pl[i].distance( nVertex ) < 0 ) { result = INTERSECT; } } return result; }
/** * Rotate the viewfrustum around the y-axis (according to the view direction). roll * * @param delta */ public void rotateY( double delta ) { rotate( right, up, delta ); rotate( backward, up, delta ); lookingAt = new Point3d( eye ); lookingAt.sub( backward ); setCameraParams( eye, lookingAt, up ); }
/** * Determines if this arc interferes with the given {@link Geometry}. * * @param roi * geometry that is tested for interference * @param zScale * scaling factor applied to z values of the mesh geometry (and bounding boxes) * @return true, if the arc interferes with the geometry, false otherwise */ public boolean interferes( ViewFrustum roi, float zScale ) { float[][] nodeBBox = getBBox(); nodeBBox[0][2] *= zScale; nodeBBox[1][2] *= zScale; return roi.intersects( nodeBBox ); }
/** * @param box * @return true if the box intersect with this viewfrustum. */ public boolean intersects( double[][] box ) { int classification = intersectsFrustum( box ); if ( classification == OUTSIDE ) { return false; } return true; }
private int intersectsFrustum( float[] box ) { int result = INSIDE; // for each plane do ... float[] t = new float[3]; for ( int i = 0; i < 6; i++ ) { // is the positive vertex outside? pl[i].getPositiveVertex( box, t ); if ( pl[i].distance( t ) < 0 ) { return OUTSIDE; } // is the negative vertex outside? pl[i].getNegativeVertex( box, t ); if ( pl[i].distance( t ) < 0 ) { result = INTERSECT; } } return result; }
/** * Rotate the viewfrustum around the x-axis (according to the view direction). pitch * * @param delta */ public void rotateX( double delta ) { rotate( up, right, delta ); rotate( backward, right, delta ); lookingAt = new Point3d( eye ); lookingAt.sub( backward ); setCameraParams( eye, lookingAt, up ); }
/** * @param box * @return true if the box intersect with this viewfrustum. */ public boolean intersects( float[] box ) { int classification = intersectsFrustum( box ); if ( classification == OUTSIDE ) { return false; } return true; }