// view.h // // by John D. de Boer typedef struct { rect port; // screen coordinates of view rectangle point org; // screen coordinate of the centre of the view real mag, // the magnification from real to screen coordinates in a projection mag1, // lower bound on mag, valid if "maglim" is true mag2, // upper bound on mag, valid if "maglim" is true stretch, // stretch factor for z axis azim, // azimuth of direction being looked toward elev, // elevation of direction being looked toward width, // width of view rectangle in pixels rads, // number or radians between left and right edges of view pix; // the number of pixels per radian in a perspective matrix rot; // rotation from world coordinates to screen coordinates vector look; // vantage point in perspective, or centre of a projection bool persp, // whether the view is a simple plane projection, or a perspective wide, // if view is wide-angled (with distortion to be treated consistently) str, // if the z axis is to be exagerated by a factor "stretch" terr, // whether the scroll bars work backwards: "terrestrial document mode" maglim; // whether there are bounds to the magnification string fov; // decimal string of "rads" value ControlRef zout, // control for zooming out zmin, // control for zooming in shlf, // control for shifting vantage to left shup, // control for shifting vantage up shbk, // control for shifting vantage backward shfw, // control for shifting vantage forward shdn, // control for shifting vantage down shrt; // control for shifting vantage to right } projection; // "azim" and "elev" are the conventional spherical angles (phi and complement of theta) // of the direction toward which the observer is looking, subtended at the "look" point. // Azimuth is measured around the z axis, starting at the x-z plane, increasing // initially toward positive y. Elevation is the angle above the x-y plane. // The screen coordinates (h,v,d) are horizontal (increasing right), vertical (increasing // down), and depth (increasing into screen). Both coordinate systems are right-handed. // The z direction through the look point is always rendered vertically on the screen, // in the upward sense, i.e. there is no "roll" angle allowed. // Allocation projection *newprojection(real X, real Y, real Z, real Mag, rect R); void oldprojection(projection *P); // Setting projection properties void resizeproj(projection *P, rect R); void projmode(projection *P, bool Persp); void setprojangles(projection *P, ControlRef Azim, ControlRef Elev); void setscrollangles(projection *P, ControlRef Azim, ControlRef Elev); void setazimelev(projection *P, real Azim, real Elev); void setviewangles(projection *P, real Theta, real Phi); void setdirection(projection *P, const vector *To); void setlook(projection *P, const vector *V); void setlookpoint(projection *P, real X, real Y, real Z); void shiftlook(projection *P, const vector *V); void shiftlookpoint(projection *P, real DX, real DY, real DZ); void shiftproj(projection *P, float DH, float DV, float DD); void verticalstretch(projection *P, real Factor); void setmaglimits(projection *P, real Lower, real Upper); void setmagnification(projection *P, real Mag); void zoommagnification(projection *P, real Zoom); // Projection query bool projatnadir(const projection *P); // Saving projections to files ulong lengthofprojection(const projection *P); void writeprojection(const projection *P); void readprojection(projection *P); // Rendering typedef struct { bool good; // whether the point is on the QuickDraw coordinate plane point pt; // Quartz screen coordinates long miss; // approximate number of pixels by which the point is outside the viewport real depth, // screen depth of point, increasing away from observer mag; // magnification, in pixels per unit distance } image; // Plane projection & perspective views bool projectpoint(const projection *P, const vector *V, image *D); bool projectdirection(const projection *P, const vector *V, image *D); bool reverseprojection(const projection *P, point Q, vector *V); bool reversevector(const projection *P, vector *Q, vector *V); void solveperspdrag(projection *Proj, const vector *Where, point P); // These routines project a point onto an opaque unit sphere. bool projontosphere(const projection *Proj, const vector *V, image *D); bool reverseprojontosphere(const projection *Proj, point P, vector *V); void solvespheredrag(projection *Proj, const vector *Where, point P); // Projecting points into views bool clicktovector(const mouseclick *M, vector *V); bool imagerotation(const projection *P, const image *D, matrix *R); void vectmove(window *W, const projection *P, const vector *V); void vectmoveto(window *W, const projection *P, const vector *V); void vectline(window *W, const projection *P, const vector *V); void vectlineto(window *W, const projection *P, const vector *V); void projmove(window *W, const projection *P, real X, real Y, real Z); void projmoveto(window *W, const projection *P, real X, real Y, real Z); void projline(window *W, const projection *P, real X, real Y, real Z); void projlineto(window *W, const projection *P, real X, real Y, real Z); void movetolineto(window *W, const image *P, bool *PenDown); //void addpentorect(CGRect *R, image *D, float Width); void imagepoly(window *W, const image *Im, int N);