/** * View an area of camera framebuffer for zoom, rotate, etc * TBD should rotate/scale about image center, not upper left (0,0) * (could add auto pan/zoom of camera as needed...) * @author: Phil Gage */ class Viewport { /** Camera to view */ AbstractCamera camera; // parent camera FrameBuffer framebuffer; // view image boolean fileOutput = true; // true for TGA file output boolean rectify = true; // true for Cyl distort rectification String path = ""; // path for TGA files int width, height; // view size double xScale, yScale; // scale double cosAngle, sinAngle; // rotate double xOffset, yOffset; // translate Color tempColor = new Color(); Viewport (AbstractCamera camera, int width, int height) { this.camera = camera; this.width = width; this.height = height; framebuffer = new FrameBuffer(width, height); xScale = camera.width / width; yScale = camera.height / height; xOffset = 0.0; yOffset = 0.0; cosAngle = 1.0; sinAngle = 0.0; } /** Rotate to angle in degrees */ void rotate (double angle) { cosAngle = Math.cos(angle*Constants.DTOR); sinAngle = Math.sin(angle*Constants.DTOR); } /** Set scale factor */ void scale (double x, double y) { xScale = x; yScale = y; } /** Set translate offset */ void translate (double x, double y) { xOffset = x; yOffset = y; } /** Convert from View coordinates to Camera X coordinate */ int transformX (double x, double y) { x = x * cosAngle - y * sinAngle; // rotate x *= xScale; // scale x += xOffset; // translate /* if (rectify) { double xc = x - camera.width/2.0; double yc = y - camera.height/2.0; double zc = 100.0; //? double az = Math.atan2(xc,zc); double el = Math.atan2(yc,Math.sqrt(xc*xc+yc*yc)); x = az*camera.width/camera.fov; y = el*camera.height/camera.vfov; } */ return (int)x; } /** Convert from View coordinates to Camera Y coordinate */ int transformY (double x, double y) { y = x * sinAngle + y * cosAngle; // rotate y *= yScale; // scale y += yOffset; // translate /* if (rectify) { double xc = x - camera.width/2.0; double yc = y - camera.height/2.0; double zc = 100.0; //? double az = Math.atan2(xc,zc); double el = Math.atan2(yc,Math.sqrt(xc*xc+yc*yc)); x = az*camera.width/camera.fov; y = el*camera.height/camera.vfov; } */ return (int)y; } /** Render view image from camera using current transform */ /* void render (int frame) { int tx, ty; for (int y=0; y