-+-+-+-+-+-+-+-+ START OF PART 279 -+-+-+-+-+-+-+-+ X (projht / windptr->viewvolume.y); X`7D /* maxadjustlimits */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void adjustlimits(C(Ppoint3 *) viewvolume) XPreANSI(Ppoint3 *viewvolume) X`7B X Pfloat projht, projwt, winwt, winht, aspectratio, winaspectratio; X Pfloat diff, height; X X /* adjust view volume to have same aspect ratio as window */ X X /* calculate aspect ratio of view area */ X if ((viewvolume->y == 0.0) `7C`7C (viewvolume->x == 0.0)) X aspectratio = 1.0; X else X aspectratio = viewvolume->y / viewvolume->x; X X /* adjust projection viewport to have same aspect ratio as view volume */ X windptr->viewbox = windptr->viewlims; X winht = windptr->viewbox.ymax - windptr->viewbox.ymin; X winwt = windptr->viewbox.xmax - windptr->viewbox.xmin; X if ((winht == 0.0) `7C`7C (winwt == 0.0)) X winaspectratio = 1.0; X else X winaspectratio = winht / winwt; `20 X if (aspectratio > winaspectratio) X `7B X /* decrease x */ X diff = (winwt - ((1.0 / aspectratio) * winht)); X windptr->viewbox.xmax -= diff / 2.0; X windptr->viewbox.xmin += diff / 2.0; X `7D X else X if (aspectratio < winaspectratio) X `7B X /* decrease y */ X diff = (winht - (aspectratio * winwt)); X windptr->viewbox.ymin += diff / 2.0; X windptr->viewbox.ymax -= diff / 2.0; X `7D `20 X X /* X ** calculate zmax so that projection viewport has same X ** aspect ratio as view volume. X */ X height = windptr->viewbox.ymax - windptr->viewbox.ymin; X `20 X if ((height == 0.0) `7C`7C (viewvolume->y == 0.0)) X windptr->viewbox.zmax = 1.0; X else X windptr->viewbox.zmax = MIN(height, viewvolume->y) /`20 X MAX(height, viewvolume->y); X`7D /* adjustlimits */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void evalviewvolume(C(Plimit3 *) wclimits, C(ptkboolean) docube) XPreANSI(Plimit3 *wclimits) XPreANSI(ptkboolean docube) X`7B X Ppoint3 boundvolume, minbox, maxbox, centrebox, ptinterest, scale; X Pmatrix3 mat; X Ppoint3 pmin, pmax; X Pfloat diameter; X X minbox = ptk_point3(wclimits->xmin, wclimits->ymin, wclimits->zmin); X maxbox = ptk_point3(wclimits->xmax, wclimits->ymax, wclimits->zmax); X X /* find centre of limits */ X centrebox = ptk_subv3(&maxbox, &minbox); X ptinterest = ptk_scalev3(¢rebox, 0.5); X ptinterest = ptk_addv3(&ptinterest, &minbox); X windptr->ptinterest = windptr->position = ptinterest; X centrebox = ptk_scalev3(¢rebox, -0.5); X ptk_shift3(¢rebox, PREPLACE, mat); X X if (docube) X `7B X /* increase box by 10 percent in all directions */ X scale = ptk_point3(1.1, 1.1, 1.1); X ptk_scale3(&scale, PPOSTCONCATENATE, mat); X `7D X X centrebox = ptk_scalev3(¢rebox, -1.0); X ptk_shift3(¢rebox, PPOSTCONCATENATE, mat); `20 X minbox = ptk_transform3(mat, &minbox); X maxbox = ptk_transform3(mat, &maxbox); X X /* bound volume is width, height and depth of limits */ X boundvolume = ptk_subv3(&maxbox, &minbox); X X if (docube) X `7B X diameter = sqrt((boundvolume.x * boundvolume.x) + X (boundvolume.y * boundvolume.y) + X (boundvolume.z * boundvolume.z)); X windptr->viewvolume = ptk_point3(diameter, diameter, diameter); X `7D X else X windptr->viewvolume = boundvolume; X adjustlimits(&windptr->viewvolume); X windptr->position.z += windptr->viewvolume.z; X`7D /* evalviewvolume */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic evalviewport(C(Plimit3 *) outview) XPreANSI(Plimit3 *outview) X`7B X Pfloat unitcube; X Ppoint origin; X X unitcube = MIN(windptr->windowsize.x, windptr->windowsize.y); X outview->xmin *= unitcube; X outview->xmax *= unitcube; X outview->ymin *= unitcube; X outview->ymax *= unitcube; X outview->zmin *= unitcube; X outview->zmax *= unitcube; X origin = windptr->windowposition; X origin.x -= unitcube / 2.0; X origin.y -= unitcube / 2.0; X outview->xmin += origin.x; X outview->xmax += origin.x; X outview->ymin += origin.y; X outview->ymax += origin.y; X`7D /* evalviewport */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void buildframe() X/* build frame about the origin according to window size X** and frame size. X*/ X`7B X Ppoint3 pts`5B6`5D, centre; X Ppoint centresize, bannercentre, bannerbox, framesize; X Pfloat charheight; X Ptxalign txalign; X Ppointlst3 sets; X X centre = ptk_point3(0.0, windptr->bannerheight / 2.0, 0.0); X centresize = windptr->windowsize; X centresize.y += windptr->bannerheight; X framesize = windptr->framesize; X X pts`5B0`5D = ptk_point3(centre.x - (centresize.x / 2.0) - framesize.x,`20 X centre.y - (centresize.y / 2.0) - framesize.y, X centre.z); X pts`5B1`5D = ptk_point3(pts`5B0`5D.x, pts`5B0`5D.y + centresize.y + (2.0 * V framesize.y), X centre.z); X pts`5B2`5D = ptk_point3(pts`5B0`5D.x + centresize.x + (2.0 * framesize.x), V pts`5B1`5D.y, X centre.z); X pts`5B3`5D = ptk_point3(pts`5B2`5D.x - framesize.x,`20 X pts`5B2`5D.y - framesize.y, centre.z); X pts`5B4`5D = ptk_point3(pts`5B1`5D.x + framesize.x, pts`5B3`5D.y,`20 X centre.z); X pts`5B5`5D = ptk_point3(pts`5B4`5D.x, pts`5B0`5D.y + framesize.y,`20 X centre.z); X /* frame */ X psetpickid(PTKEWINDOWFRAME); X psetintstyle(PSOLID); X psetintcolourind(windptr->frametlcolour); X pts`5B2`5D = ptk_point3(pts`5B0`5D.x + centresize.x + (2.0 * framesize.x), V`20 X pts`5B1`5D.y, centre.z); X pfillarea3(6, pts); X psetintcolourind(windptr->framebrcolour); X pts`5B1`5D.x += centresize.x + (2.0 * framesize.x); X pts`5B1`5D.y -= centresize.y + (2.0 * framesize.y); X pts`5B4`5D.x = pts`5B3`5D.x; X pts`5B4`5D.y = pts`5B5`5D.y; X pfillarea3(6, pts); X X /* view */ X psetpickid(PTKEWINDOWVIEW); X pts`5B2`5D = ptk_point3(pts`5B3`5D.x, pts`5B5`5D.y, centre.z); X pts`5B4`5D = ptk_point3(pts`5B0`5D.x + framesize.x, pts`5B3`5D.y,`20 X centre.z); X psetintstyle(PSOLID); X psetintcolourind(windptr->backgdcolour); X psetedgeflag(PEDGE_ON); X psetedgecolourind(windptr->edgecolour); X sets.number = 4; X sets.points = &pts`5B2`5D; X ptk_fillareaset3(1, &sets); X X /* banner */ X psetpickid(PTKEWINDOWBANNER); X pts`5B0`5D = ptk_point3(-windptr->windowsize.x / 2.0,`20 X windptr->windowsize.y /2.0, 0.0); X pts`5B1`5D = ptk_point3(pts`5B0`5D.x, pts`5B0`5D.y + windptr->bannerheight V, 0.0); X pts`5B2`5D = ptk_point3(pts`5B0`5D.x + windptr->windowsize.x, pts`5B1`5D.y V, 0.0); X pts`5B3`5D = ptk_point3(pts`5B2`5D.x, pts`5B0`5D.y, 0.0); X sets.number = 4; X sets.points = pts; X psetintcolourind(windptr->bannercolour); X ptk_fillareaset3(1, &sets); X bannerbox = ptk_point(windptr->windowsize.x, windptr->bannerheight); X ptk_computecharheight(windptr->wsid, windptr->titlestring, &bannerbox, X windptr->titlefont, &charheight); X psetcharheight(charheight); X txalign.hor = PAH_CENTRE; X txalign.ver = PAV_BOTTOM; X psettextalign(&txalign); X psettextfont(windptr->titlefont); X psettextcolourind(windptr->titlecolour); X bannercentre = ptk_point(centre.x, windptr->windowsize.y / 2.0); X ptext(&bannercentre, windptr->titlestring);`20 X`7D /* buildframe */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic ptkboolean find_string(C(Pint) structure, C(Pchar *) str) XPreANSI(Pint structure) XPreANSI(Pchar *str) X/* X** \parambegin X** \param`7B`7D`7Bstructure`7D`7Bwindow structure id`7D`7BIN`7D X** \param`7B`7D`7Bpickid`7D`7Bitem containing string`7D`7BIN`7D X** \param`7B`7D`7Bstrwindow`7D`7Bstring and window data`7D`7BIN`7D X** \paramend X** \blurb`7BSearch for string in window items. X** Returns TRUE if string found, otherwise FALSE.`7D X*/ X`7B X Pint error; X Psrchstatus stat; X ptkselcontent elcont; X Pchar *databuf; X Pint eltptr; X ptkboolean stop_search, string_found; X Pint numelems; X#ifdef SUN X Psrcheltypelst include, exclude; X Psrcheltype includeelems`5B10`5D, excludeelems`5B10`5D; X#endif X#ifdef VMS X Peltype srchelems`5B2`5D; X Pint numsrchelems, lstnum; X#endif X X eltptr = 0; X stop_search = FALSE; X string_found = FALSE; X numelems = ptk_elemcount(structure); X do`20 X `7B X#ifdef SUN X includeelems`5B0`5D = PSEL_TEXT3; X includeelems`5B1`5D = PSEL_TEXT; X include.number = 2; X include.elems = includeelems; X exclude.number = 0; X exclude.elems = excludeelems; X X pelemsrch(structure, eltptr, PFORWARD, &include, &exclude, X &error, &stat, &eltptr); X#endif X#ifdef VMS X numsrchelems = 2; X srchelems`5B0`5D = PEL_TEXT3; X srchelems`5B1`5D = PEL_TEXT; X X ptk_openstruct(structure); X psetelemptr(eltptr); X ptk_findelemtype(srchelems, numsrchelems, PFORWARD, &stat, &eltptr,`20 X &lstnum); X ptk_closestruct(); X error = 0; X#endif X X if (error != 0) X stop_search = TRUE; X else`20 X if (stat != PSUCCESS)`20 X stop_search = TRUE; X else`20 X `7B X ptk_inqelemtypesizecontent(structure, eltptr, &error, &databuf,`20 X &elcont); X if (error == 0)`20 X `7B X switch (elcont.eltype)`20 X `7B X `20 X case PEL_TEXT: X#ifdef SUN X if (strcmp(elcont.eldata.tx.str, str) == 0) X string_found = TRUE; X#endif X#ifdef VMS X if (strcmp(elcont.eldata.text.string, str) == 0) X string_found = TRUE; X#endif X break; X X case PEL_TEXT3: X#ifdef SUN X if (strcmp(elcont.eldata.text3.str, str) == 0) X string_found = TRUE; X#endif X#ifdef VMS X if (strcmp(elcont.eldata.text3.string, str) == 0) X string_found = TRUE; X#endif X break; X `7D X `7D X `7D X eltptr++; X free(databuf); X `7D while (!string_found && !stop_search && (eltptr <= numelems)); X return string_found; X`7D /* find_string */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void updateframe() X`7B X Ppoint3 wscale; X Pmatrix3 mat; X Ppoint position, size; X Ppoint3 shift; X X position = windptr->windowposition; X size = windptr->windowsize; X ptk_openstruct(windptr->windowstid); X ptk_seteditmode(PEDIT_REPLACE); X psetelemptr(0); X psetelemptrlabel(ptk_stringtoint("label", "globaltran")); X poffsetelemptr(1); X shift = ptk_point3(position.x, position.y, 0.0); X ptk_shift3(&shift, PREPLACE, mat); X psetlocaltran3(mat, PREPLACE); X ptk_unseteditmode(); X pdelelemslabels(ptk_stringtoint("label", "begin-frame"),`20 X ptk_stringtoint("label", "end-frame")); `20 X ptk_seteditmode(PEDIT_INSERT); `20 X buildframe(); X ptk_unseteditmode(); X ptk_closestruct(); X windptr->viewbox = windptr->viewlims =`20 X ptk_limit3(position.x - (size.x / 2.0), X position.x + (size.x / 2.0), X position.y - (size.y / 2.0), X position.y + (size.y / 2.0), X 0.0, 1.0); X`7D /* updateframe */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void updateicon() X`7B X Ppoint3 wscale, shift; X Pmatrix3 mat; X X if (windptr->defaulticon) X `7B X ptk_openstruct(windptr->iconstid); X ptk_seteditmode(PEDIT_REPLACE); X psetelemptr(0); X psetelemptrlabel(ptk_stringtoint("label", "begin-icon")); X poffsetelemptr(-1); X shift = ptk_point3(-0.5, -0.5, 0.0); X ptk_shift3(&shift, PREPLACE, mat); X wscale = ptk_point3(windptr->iconsize.x, windptr->iconsize.y, 1.0); X ptk_scale3(&wscale, PPOSTCONCATENATE, mat); X shift = ptk_point3(windptr->iconposition.x, windptr->iconposition.y,`20 X 0.0); X ptk_shift3(&shift, PPOSTCONCATENATE, mat); X psetlocaltran3(mat, PREPLACE); X ptk_unseteditmode(); X ptk_closestruct(); X `7D X`7D /* updateicon */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void updateview() X`7B X Pint err; X Pviewrep3 vrep; X Plimit3 cliplims; X X ptk_pevalvieworientationmatrix3(&windptr->vrp, &windptr->vpn,`20 X &windptr->vup, &err, vrep.orientation_matrix); X vmap.viewport = windptr->viewport; X cliplims = windptr->cliplimit; X if ((windptr->windowtype == PTKESTRUCTWINDOW) `7C`7C X (windptr->windowtype == PTKETOPOLOGYWINDOW)) `20 X `7B X evalviewport(&vmap.viewport); X evalviewport(&cliplims); X `7D X vrep.clip_limit = windptr->viewbox; X if (windptr->clipxy == PCLIP) X `7B X vrep.clip_limit.xmin = cliplims.xmin; X vrep.clip_limit.xmax = cliplims.xmax; X vrep.clip_limit.ymin = cliplims.ymin; X vrep.clip_limit.ymax = cliplims.ymax; X `7D X if (windptr->clipfront == PCLIP) X vrep.clip_limit.zmin = cliplims.zmin; X if (windptr->clipback == PCLIP) X vrep.clip_limit.zmax = cliplims.zmax; X vrep.clip_xy = PCLIP; X vrep.clip_back = vrep.clip_front = PCLIP; X vmap.window = windptr->window; X vmap.proj = windptr->proj; X vmap.prp = windptr->prp; X vmap.view_plane = windptr->viewplane; X vmap.front_plane = windptr->frontplane; X vmap.back_plane = windptr->backplane; X pevalviewmappingmatrix3(&vmap, &err, vrep.mapping_matrix); X psetviewrep3(windptr->wsid, windptr->windowviewind, &vrep); X`7D /* updateview */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void updatecamera() X`7B X Pint err; X Pviewrep3 vrep; X Pmatrix3 twistmat; X Ppoint3 origin, initvpn, inittwist; X X vrp = windptr->ptinterest; X vpn = ptk_subv3(&windptr->position, &vrp); X vpn = ptk_unitv3(&vpn); X ptk_rotatevv3(&windptr->lastvpn, &vpn, PREPLACE, twistmat, &err); X vup = ptk_transform3(twistmat, &windptr->lastvup); X vup = ptk_unitv3(&vup); X windptr->lastvup = vup; X origin = ptk_point3(0.0, 0.0, 0.0); +-+-+-+-+-+-+-+- END OF PART 279 +-+-+-+-+-+-+-+-