-+-+-+-+-+-+-+-+ START OF PART 280 -+-+-+-+-+-+-+-+ X ptk_rotateline3(&origin, &vpn, windptr->twistangle, PPOSTCONCATENATE, X twistmat, &err); X vup = ptk_transform3(twistmat, &vup); X ptk_pevalvieworientationmatrix3(&vrp, &vpn, &vup, &err,`20 X vrep.orientation_matrix); X windptr->lastvpn = vpn; X vrep.clip_limit = windptr->viewlims; X vrep.clip_xy = PCLIP; X vrep.clip_back = vrep.clip_front = PCLIP; X vmap.window = ptk_limit(-windptr->viewvolume.x / 2.0,`20 X windptr->viewvolume.x / 2.0,`20 X -windptr->viewvolume.y / 2.0,`20 X windptr->viewvolume.y / 2.0); X vmap.viewport = windptr->viewbox; X vmap.proj = windptr->cameraproj; X vmap.prp = ptk_point3(0.0, 0.0, windptr->viewvolume.z); X vmap.front_plane = windptr->viewvolume.z / 2.0; X vmap.view_plane = 0.0; X vmap.back_plane = -windptr->viewvolume.z / 2.0; X X pevalviewmappingmatrix3(&vmap, &err, vrep.mapping_matrix); X psetviewrep3(windptr->wsid, windptr->windowviewind, &vrep); X`7D /* updatecamera */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void updatewindowview() X`7B X if (windptr->cameraswitch == PTKECAMERAON) X updatecamera(); X else X updateview(); X`7D /* updatewindowview */ X X/*-------------------------------------------------------------------------- V*/ X Xstatic void initialiseterminal() X`7B X Pfloat oneline; X X /* view mapping */ X windptr->proj = PPARALLEL; X windptr->prp = ptk_point3(windptr->windowsize.x / 2.0, X windptr->windowsize.y / 2.0, 1.0); X windptr->window = ptk_limit(0.0, windptr->windowsize.x, 0.0,`20 X windptr->windowsize.y); X windptr->viewport = windptr->cliplimit = windptr->viewlims; X windptr->backplane = windptr->viewplane = 0.0; X windptr->frontplane = 1.0; X /* view orientation */ X oneline = -windptr->windowsize.y/(Pfloat)windptr->term.lines; X windptr->vrp = ptk_point3(0.0, -windptr->windowsize.y +`20 X (oneline * (Pfloat)(windptr->term.visline - 1)), 0.0); X windptr->vpn = ptk_point3(0.0, 0.0, 1.0); X windptr->vup = ptk_point3(0.0, 1.0, 0.0); X /* set view rep */ X updateview(); X`7D /* initialiseterminal */ X`20 X/*-------------------------------------------------------------------------- V*/ X/*------------------------ Camera functions -------------------------------- V*/ X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_rotatecameraposition(C(Pint) windid, C(Pfloat) angle) XPreANSI(Pint windid)`20 XPreANSI(Pfloat angle) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPfloat`7D`7Bangle`7D`7Brotation angle in degrees`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function rotates the camera position in a circle centred X** at the point of interest and about the axis defined by the function X** `7B\tt ptk\_setpositionaxis`7D. The amount of rotation is `7B\tt angle`7D X** degrees and the function is useful for rotating around an object.`7D X*/ X`7B X Pmatrix3 spinmat, mat; X Ppoint3 origin; X Ppoint3 shiftprp; X Pint err; X X setwindow(windid); X if (windptr != NULL) X `7B X /* shift by -(vrp), rotate about arbitrary axis, shift by (vrp) */ X shiftprp = ptk_scalev3(&windptr->ptinterest, -1.0);`20 X ptk_shift3(&shiftprp, PREPLACE, spinmat); X origin = ptk_point3(0.0, 0.0, 0.0); X ptk_rotateline3(&origin, &windptr->positionaxis,`20 X angle, PPOSTCONCATENATE, spinmat, &err); X ptk_shift3(&windptr->ptinterest, PPOSTCONCATENATE, spinmat); X windptr->position = ptk_transform3(spinmat, &windptr->position); X /* transform fixed x and y axes */ X ptk_rotateline3(&origin, &windptr->positionaxis, angle,`20 X PREPLACE, mat, &err); X windptr->xaxis = ptk_transform3(mat, &windptr->xaxis); X windptr->yaxis = ptk_transform3(mat, &windptr->yaxis); X updatecamera(); X `7D X`7D /* ptk_rotatecameraposition */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_setpositionaxis(C(Pint) windid, C(Ppoint3 *) axis) XPreANSI(Pint windid) XPreANSI(Ppoint3 *axis) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPpoint3 *`7D`7Baxis`7D`7Baxis of rotation`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function sets the axis of rotation for rotating`20 X** the camera position using the function `7B\tt ptk\_rotatecameraposition`7 VD.`7D X*/ X`7B X setwindow(windid); X if (windptr != NULL) X windptr->positionaxis = *axis; X`7D /* ptk_setpositionaxis */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_setptinterestaxis(C(Pint) windid, C(Ppoint3 *) axis) XPreANSI(Pint windid) XPreANSI(Ppoint3 *axis) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPpoint3 *`7D`7Baxis`7D`7Baxis of rotation`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function sets the axis of rotation for rotating`20 X** the camera point of interest using the function X** `7B\tt ptk\_rotatecameraptinterest`7D.`7D X*/ X`7B X setwindow(windid); X if (windptr != NULL) X windptr->ptinterestaxis = *axis; X`7D /* ptk_setptinterestaxis */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_scaleviewwindow(C(Pint) windid, C(Pfloat) scalefactor) XPreANSI(Pint windid)`20 XPreANSI(Pfloat scalefactor) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPfloat`7D`7Bscalefactor`7D`7Bscale factor`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function scales the view window uniformly X** by `7B\tt scalefactor`7D. A scalefactor in the range `5B0, 1`5D will X** scale down the view window and create a zoom-in effect. X** A scalefactor greater than 1.0 will give a zoom-out effect.`7D X*/ X`7B X setwindow(windid); X if (windptr != NULL) X `7B X if (scalefactor != 0.0) X `7B X windptr->viewvolume.x *= scalefactor; X windptr->viewvolume.y *= scalefactor; X updatecamera(); X `7D X `7D X`7D /* ptk_scaleviewwindow */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_rotatecameraptinterest(C(Pint) windid, C(Pfloat) angle) XPreANSI(Pint windid)`20 XPreANSI(Pfloat angle) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPfloat`7D`7Bangle`7D`7Brotation angle in degrees`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function rotates the camera point of interest in a circle`2 V0 X** centred at the camera position and about the axis defined by the function X** `7B\tt ptk\_setptinterestaxis`7D. The amount of rotation is `7B\tt angle` V7D X** degrees and the function is useful for panning around a scene.`7D X*/ X`7B X Pmatrix3 spinmat, mat; X Ppoint3 origin; X Ppoint3 shiftprp; X Pint err; X X setwindow(windid); X if (windptr != NULL) X `7B X /* shift by -(prp), rotate about arbitrary axis, shift by (prp) */ X shiftprp = ptk_scalev3(&windptr->position, -1.0); X ptk_shift3(&shiftprp, PREPLACE, spinmat); X origin = ptk_point3(0.0, 0.0, 0.0); X ptk_rotateline3(&origin, &windptr->ptinterestaxis,`20 X angle, PPOSTCONCATENATE, spinmat, &err); X ptk_shift3(&windptr->position, PPOSTCONCATENATE, spinmat); X windptr->ptinterest = ptk_transform3(spinmat, &windptr->ptinterest); X /* transform fixed x and y axes */ X ptk_rotateline3(&origin, &windptr->ptinterestaxis, angle,`20 X PREPLACE, mat, &err); X windptr->xaxis = ptk_transform3(mat, &windptr->xaxis); X windptr->yaxis = ptk_transform3(mat, &windptr->yaxis); X updatecamera(); X `7D X`7D /* ptk_rotatecameraptinterest */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_rotatecameraupvector(C(Pint) windid, C(Pfloat) angle) XPreANSI(Pint windid)`20 XPreANSI(Pfloat angle) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPfloat`7D`7Bangle`7D`7Brotation angle in degrees`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function rotates the camera up vector`20 X** about the axis joining the camera position to the point of interest by X** `7B\tt angle`7D degrees.`7D X*/ X`7B X Pmatrix3 mat; X Pint err; X Ppoint3 zaxis; X X setwindow(windid); X if (windptr != NULL) X `7B X /* rotate about z axis */ X windptr->twistangle += angle; X zaxis = ptk_crossv3(&windptr->xaxis, &windptr->yaxis); X ptk_rotateline3(&origin, &zaxis, angle, PREPLACE, mat, &err); X windptr->xaxis = ptk_transform3(mat, &windptr->xaxis); X windptr->yaxis = ptk_transform3(mat, &windptr->yaxis); X updatecamera(); X `7D X`7D /* ptk_rotatecameraupvector */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_rotatepositionyaxis(C(Pint) windid, C(Pfloat) angle) XPreANSI(Pint windid)`20 XPreANSI(Pfloat angle) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPfloat`7D`7Bangle`7D`7Brotation angle in degrees`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function rotates the camera position in a circle centred X** at the point of interest and about the y axis of a right-handed X** coordinate system whose z axis is defined by the camera position and X** point of interest.`7D X*/ X`7B X Pmatrix3 mat; X Pint err; X X setwindow(windid); X if (windptr != NULL) X `7B X ptk_setpositionaxis(windid, &windptr->yaxis); X ptk_rotatecameraposition(windid, -angle); X /* rotate x axis about current y axis */ X updatecamera(); X `7D X`7D /* ptk_rotatepositionyaxis */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_rotatepositionxaxis(C(Pint) windid, C(Pfloat) angle) XPreANSI(Pint windid)`20 XPreANSI(Pfloat angle) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPfloat`7D`7Bangle`7D`7Brotation angle in degrees`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function rotates the camera position in a circle centred X** at the point of interest and about the x axis of a right-handed X** coordinate system whose z axis is defined by the camera position and X** point of interest.`7D X*/ X`7B X Pmatrix3 mat; X Pint err; X X setwindow(windid); X if (windptr != NULL) X `7B X ptk_setpositionaxis(windid, &windptr->xaxis); X ptk_rotatecameraposition(windid, -angle); X `7D X`7D /* ptk_rotatepositionxaxis */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_rotateptinterestyaxis(C(Pint) windid, C(Pfloat) angle) XPreANSI(Pint windid)`20 XPreANSI(Pfloat angle) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPfloat`7D`7Bangle`7D`7Brotation angle in degrees`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function rotates the camera point of interest X** in a circle centred X** at the camera position and about the y axis of a right-handed X** coordinate system whose z axis is defined by the camera position and X** point of interest.`7D X*/ X`7B X Pmatrix3 mat; X Pint err; X X setwindow(windid); X if (windptr != NULL) X `7B X ptk_setptinterestaxis(windid, &windptr->yaxis); X ptk_rotatecameraptinterest(windid, -angle); X `7D X`7D /* ptk_rotateptinterestyaxis */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_rotateptinterestxaxis(C(Pint) windid, C(Pfloat) angle) XPreANSI(Pint windid)`20 XPreANSI(Pfloat angle) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPfloat`7D`7Bangle`7D`7Brotation angle in degrees`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function rotates the camera point of interest X** in a circle centred X** at the camera position and about the x axis of a right-handed X** coordinate system whose z axis is defined by the camera position and X** point of interest.`7D X*/ X`7B X Pmatrix3 mat; X Pint err; X X setwindow(windid); X if (windptr != NULL) X `7B X ptk_setptinterestaxis(windid, &windptr->xaxis); X ptk_rotatecameraptinterest(windid, -angle); X `7D X`7D /* ptk_rotateptinterestxaxis */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_setcameraposition(C(Pint) windid, C(Ppoint3 *) position) XPreANSI(Pint windid) XPreANSI(Ppoint3 *position) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPpoint3 *`7D`7Bposition`7D`7Bcamera position`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function sets the camera position to `7B\tt position`7D X** which is given in World Coordinates.`7D X*/ X`7B X setwindow(windid); X if (windptr != NULL) X `7B X windptr->position = *position; X updatecamera(); X `7D X`7D /* ptk_setcameraposition */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_setcameraptinterest(C(Pint) windid, C(Ppoint3 *) ptinterest) XPreANSI(Pint windid) XPreANSI(Ppoint3 *ptinterest) X/* X** \parambegin X** \param`7BPint`7D`7Bwindid`7D`7Bwindow identifier`7D`7BIN`7D X** \param`7BPpoint3 *`7D`7Bptinterest`7D`7Bpoint of interest`7D`7BIN`7D X** \paramend`20 X** \blurb`7BThis function sets the camera point of interest to X** `7B\tt ptinterest`7D which is given in World Corrdinates.`7D X*/ X`7B X setwindow(windid); X if (windptr != NULL) X `7B X windptr->ptinterest = *ptinterest; X updatecamera(); X `7D X`7D /* ptk_setcameraptinterest */ X X/*-------------------------------------------------------------------------- V*/ X X/*function:external*/ Xextern void ptk_setcameraprojtype(C(Pint) windid, C(Pprojtype) proj) XPreANSI(Pint windid) +-+-+-+-+-+-+-+- END OF PART 280 +-+-+-+-+-+-+-+-