#include /* get HP-PHIGS definitions for C */ #include /* get standard I/O definitions */ #define CopyMatrix(src,dest) {int I, J; \ for (I = 0; I < 4; I++) \ for (J = 0; J < 4; J++) \ dest[I][J] = src[I][J]; \ } #define CheckError(err, rtn) if (err) { \ fprintf(stderr, "Error %d in %s; %s", \ err, rtn, "terminating.\n"); \ exit(1); \ } main() /* file "FourViews.c" */ { Pint WorkstnID = 1; /* workstation identifier */ Pint ConnID; /* connection identifier */ Pint Scene = 1, Cube = 2; /* structure IDs */ Pint Error; /* error indicator */ Pmatrix3 ViewMapMatrix; /* from "peval_view_map_matrix3" */ Pmatrix3 ViewOriMatrix; /* from "peval_view_ori_matrix3" */ /*--- viewing parameters for View 1 ------------------------------------*/ static Pview_map3 ViewMapping1 = {/* sent to "peval_view_map_matrix3" */ {-1.75, 1.75, -1.75, 1.75}, /* window limits */ {0.5, 1.0, 0.5, 1.0, 0.0, 1.0}, /* projection viewport limits */ PTYPE_PERSPECT, /* perspective projection */ {0.0, 0.0, 10.0}, /* projection reference point */ 0.0, -2.5, 2.5}; /* view/back/front plane distances */ static Ppoint3 ViewRefPt1 = {0.0, 0.0, 0.0}; static Pvec3 ViewNormVec1 = {0.4, 0.3, 1.0}; static Pvec3 ViewUpVec1 = {0.0, 1.0, 0.0}; static Plimit3 ClipLimits1 = {0.5, 1.0, 0.5, 1.0, 0.0, 1.0}; Pview_rep3 ViewRep1; /*--- viewing parameters for View 2 ------------------------------------*/ static Pview_map3 ViewMapping2 = {/* sent to "peval_view_map_matrix3" */ {-1.25, 1.25, -1.25, 1.25}, /* window limits */ {0.0, 0.5, 0.5, 1.0, 0.0, 1.0}, /* projection viewport limits */ PTYPE_PARAL, /* parallel projection */ {0.0, 0.0, 10.0}, /* projection reference point */ 0.0, -2.5, 2.5}; /* view/back/front plane distances */ static Ppoint3 ViewRefPt2 = {0.0, 0.0, 0.0}; static Pvec3 ViewNormVec2 = {0.0, 0.5, 0.0}; static Pvec3 ViewUpVec2 = {0.0, 0.0, -1.0}; static Plimit3 ClipLimits2 = {0.0, 0.5, 0.5, 1.0, 0.0, 1.0}; Pview_rep3 ViewRep2; /*--- viewing parameters for View 3 ------------------------------------*/ static Pview_map3 ViewMapping3 = {/* sent to "peval_view_map_matrix3" */ {-1.25, 1.25, -1.25, 1.25}, /* window limits */ {0.0, 0.5, 0.0, 0.5, 0.0, 1.0}, /* projection viewport limits */ PTYPE_PARAL, /* parallel projection */ {0.0, 0.0, 10.0}, /* projection reference point */ 0.0, -2.5, 2.5}; /* view/back/front plane distances */ static Ppoint3 ViewRefPt3 = {0.0, 0.0, 0.0}; static Pvec3 ViewNormVec3 = {0.0, 0.0, 0.5}; static Pvec3 ViewUpVec3 = {0.0, 1.0, 0.0}; static Plimit3 ClipLimits3 = {0.0, 0.5, 0.0, 0.5, 0.0, 1.0}; Pview_rep3 ViewRep3; /*--- viewing parameters for View 4 ------------------------------------*/ static Pview_map3 ViewMapping4 = {/* sent to "peval_view_map_matrix3" */ {-1.25, 1.25, -1.25, 1.25}, /* window limits */ {0.5, 1.0, 0.0, 0.5, 0.0, 1.0}, /* projection viewport limits */ PTYPE_PARAL, /* parallel projection */ {0.0, 0.0, 10.0}, /* projection reference point */ 0.0, -2.5, 2.5}; /* view/back/front plane distances */ static Ppoint3 ViewRefPt4 = {0.0, 0.0, 0.0}; static Pvec3 ViewNormVec4 = {0.8, 0.0, 0.0}; static Pvec3 ViewUpVec4 = {0.0, 1.0, 0.0}; static Plimit3 ClipLimits4 = {0.5, 1.0, 0.0, 0.5, 0.0, 1.0}; Pview_rep3 ViewRep4; popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE); /* errors go to "stderr" */ popen_ws(WorkstnID, NULL, phigs_ws_type_x_tool); /*--- set up view 1 (upper right) --------------------------------------*/ peval_view_map_matrix3(&ViewMapping1, &Error, ViewMapMatrix); CheckError(Error, "peval_view_map_matrix3"); peval_view_ori_matrix3(&ViewRefPt1, &ViewNormVec1, &ViewUpVec1, &Error, ViewOriMatrix); /* +---+---+ */ CheckError(Error, "peval_view_ori_matrix3"); /* | | X | */ CopyMatrix(ViewOriMatrix, ViewRep1.ori_matrix); /* +---+---+ */ CopyMatrix(ViewMapMatrix, ViewRep1.map_matrix); /* | | | */ ViewRep1.clip_limit = ClipLimits1; /* +---+---+ */ ViewRep1.xy_clip = ViewRep1.back_clip = ViewRep1.front_clip = PIND_CLIP; pset_view_rep3(WorkstnID, 1, &ViewRep1); /*--- set up view 2 (upper left) ---------------------------------------*/ peval_view_map_matrix3(&ViewMapping2, &Error, ViewMapMatrix); CheckError(Error, "peval_view_map_matrix3"); peval_view_ori_matrix3(&ViewRefPt2, &ViewNormVec2, &ViewUpVec2, &Error, ViewOriMatrix); /* +---+---+ */ CheckError(Error, "peval_view_ori_matrix3"); /* | X | | */ CopyMatrix(ViewOriMatrix, ViewRep2.ori_matrix); /* +---+---+ */ CopyMatrix(ViewMapMatrix, ViewRep2.map_matrix); /* | | | */ ViewRep2.clip_limit = ClipLimits2; /* +---+---+ */ ViewRep2.xy_clip = ViewRep2.back_clip = ViewRep2.front_clip = PIND_CLIP; pset_view_rep3(WorkstnID, 2, &ViewRep2); /*--- set up view 3 (lower left) ---------------------------------------*/ peval_view_map_matrix3(&ViewMapping3, &Error, ViewMapMatrix); CheckError(Error, "peval_view_map_matrix3"); peval_view_ori_matrix3(&ViewRefPt3, &ViewNormVec3, &ViewUpVec3, &Error, ViewOriMatrix); /* +---+---+ */ CheckError(Error, "peval_view_ori_matrix3"); /* | | | */ CopyMatrix(ViewOriMatrix, ViewRep3.ori_matrix); /* +---+---+ */ CopyMatrix(ViewMapMatrix, ViewRep3.map_matrix); /* | X | | */ ViewRep3.clip_limit = ClipLimits3; /* +---+---+ */ ViewRep3.xy_clip = ViewRep3.back_clip = ViewRep3.front_clip = PIND_CLIP; pset_view_rep3(WorkstnID, 3, &ViewRep3); /*--- set up view 4 (lower right) --------------------------------------*/ peval_view_map_matrix3(&ViewMapping4, &Error, ViewMapMatrix); CheckError(Error, "peval_view_map_matrix3"); peval_view_ori_matrix3(&ViewRefPt4, &ViewNormVec4, &ViewUpVec4, &Error, ViewOriMatrix); /* +---+---+ */ CheckError(Error, "peval_view_ori_matrix3"); /* | | | */ CopyMatrix(ViewOriMatrix, ViewRep4.ori_matrix); /* +---+---+ */ CopyMatrix(ViewMapMatrix, ViewRep4.map_matrix); /* | | X | */ ViewRep4.clip_limit = ClipLimits4; /* +---+---+ */ ViewRep4.xy_clip = ViewRep4.back_clip = ViewRep4.front_clip = PIND_CLIP; pset_view_rep3(WorkstnID, 4, &ViewRep4); /*--- draw all four views ----------------------------------------------*/ BuildCube(Cube); popen_struct(Scene); pset_view_ind(1); pexec_struct(Cube); pset_view_ind(2); pexec_struct(Cube); pset_view_ind(3); pexec_struct(Cube); pset_view_ind(4); pexec_struct(Cube); pclose_struct(); ppost_struct(WorkstnID, Scene, 1.0); pupd_ws(WorkstnID, PFLAG_PERFORM); sleep(10); pclose_ws(WorkstnID); pclose_phigs(); } /****************************************************************************/ BuildCube(StructID) int StructID; /* structure ID for cube structure */ { static Ppoint3 TopPoints[5] = {-1,1,-1, -1,1,1, 0,1,1, 1,1,0, 1,1,-1}; static Ppoint_list3 Top = {5, TopPoints}; static Ppoint3 BottomPoints[4] = {-1,-1,1, -1,-1,-1, 1,-1,-1, 1,-1,1}; static Ppoint_list3 Bottom = {4, BottomPoints}; static Ppoint3 RightPoints[5] = {1,-1,-1, 1,1,-1, 1,1,0, 1,0,1, 1,-1,1}; static Ppoint_list3 Right = {5, RightPoints}; static Ppoint3 LeftPoints[4] = {-1,-1,1, -1,1,1, -1,1,-1, -1,-1,-1}; static Ppoint_list3 Left = {4, LeftPoints}; static Ppoint3 FrontPoints[5] = {1,-1,1, 1,0,1, 0,1,1, -1,1,1, -1,-1,1}; static Ppoint_list3 Front = {5, FrontPoints}; static Ppoint3 BackPoints[4] = {-1,-1,-1, -1,1,-1, 1,1,-1, 1,-1,-1}; static Ppoint_list3 Back = {4, BackPoints}; static Ppoint3 CornerPoints[3] = {1,0,1, 1,1,0, 0,1,1}; static Ppoint_list3 Corner = {3, CornerPoints}; static Ppoint_list3 CubePoints[7]; Ppoint_list_list3 Cube; /*--- text locations and orientations ----------------------------------*/ static Ppoint3 TopTextPos = {-0.75, 1.0, 0.0}; static Pvec3 TopTextOri[2] = {1,0,0, 0,0,-1}; static Ppoint3 RightTextPos = {1.0, -0.75, 0.75}; static Pvec3 RightTextOri[2] = {0,0,-1, 0,1,0}; static Ppoint3 FrontTextPos = {-0.75, -0.75, 1.0}; static Pvec3 FrontTextOri[2] = {1,0,0, 0,1,0}; int I; /* loop control variable */ CubePoints[0] = Top; CubePoints[1] = Bottom; CubePoints[2] = Right; CubePoints[3] = Left; CubePoints[4] = Front; CubePoints[5] = Back; CubePoints[6] = Corner; popen_struct(StructID); pset_face_cull_mode(PCULL_BACKFACE); Cube.num_point_lists = 1; for (I = 0; I < 7; I++) { Cube.point_lists = &(CubePoints[I]); pfill_area_set3(&Cube); } pset_char_ht(0.4); pset_char_expan(0.7); ptext3(&TopTextPos, TopTextOri, "Top"); ptext3(&RightTextPos, RightTextOri, "Right"); ptext3(&FrontTextPos, FrontTextOri, "Front"); pclose_struct(); }