📄 surface.c
字号:
include 'phigs.f1.0h'; /* get the HP-PHIGS aliases */main(){ include 'phigs.f2.0h'; /* get the HP-PHIGS constants */ int WorkstnID; /* workstation identifier */ parameter (WorkstnID = 1); /* value chosen by the user */ int ConnID; /* connection identifier */ int WorkstnType; /* workstation type */ parameter (WorkstnType = POIDDX); /* out/in, direct, sngl bfr, X */ float CtrlPtsX(12),CtrlPtsY(12),CtrlPtsZ(12) /* control points */ data CtrlPtsX / 0.0, 0.5,1.0, 0.0, 0.5,1.0, 0.0, 0.5,1.0, 0.0, 0.5,1.0/ data CtrlPtsY / 0.0, 0.3, 0.2, 0.1, 0.5, 0.4, 0.3, 0.4, 0.1, 0.0, 0.2, 0.3/ data CtrlPtsZ / 0.0, 0.0, 0.0, 0.3, 0.3, 0.3, 0.6, 0.6, 0.6, 0.9, 0.9, 0.9/ float uKnotVector(6), vKnotVector(8) /* knot vectors */ data uKnotVector /0.0, 0.0, 0.0, 1.0, 1.0, 1.0/ data vKnotVector /0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0/ float StepSizeData(4); /* sent to "pprec" */ data StepSizeData / 0.1, 0.1, 0.1, 0.1/ /* u, v exterior; u, v interior */ int TheMesh, MeshLabel; /* structure identifier, label */ parameter (TheMesh = 1, MeshLabel = 1) /* values chosen by the user */ int LightsOn(2); /* sent to "pslss" */ data LightsOn /1, 2/; /* turn both lights on */ float Gray(3); /* define RGB triple */ data Gray / 0.5, 0.0, 0.0/; /* RGB for 50% gray */ float ThetaMin,ThetaMax, dTheta, Theta/* loop control variables */ parameter (ThetaMin = 0.0, ThetaMax = 770.0, dTheta = 0.5); float xform(4,4); /* transformation matrix */ int Error; /* error-return variable */ char DataRec[80] (10); /* sent to "pprec" */ int DataRecLen; /* ditto */ int Dummy(1); /* dummy variable */ int ChoiceStatus, ChoiceNum; /* choice status and value */ int u, v; /* loop control variables */ int I, Iu, Iv; /* temporary array indexes */ float rad, deg; /* type the statement function */ rad(deg) = ((deg) * 3.14159265358979/180.0) /* convert degrees to radians */ popen_phigs(stderr, 0) /* open phigs */ pescape_u4('/dev/screen/phigs_window', ConnID) /* get connection ID */ popen_ws(WorkstnID, ConnID, WorkstnType)/* open workstation */ pescape_u250(WorkstnID, 0); /* set colour env.: Direct */ pset_hlhsr_mode(WorkstnID, PHRZBF); /* set HLHSR mode */ DefineLight(WorkstnID, 1,; /* define light source 1.0.. */ + 1,; /* type: ambient */ + 0.0, 0.0, 0.0,; /* location: don't care */ + 0.2, 0.2, 0.2,; /* colour: gray */ + 0.0, 0.0); /* attenuation: don't care */ DefineLight(WorkstnID, 2,; /* define light source 2.0.. */ + 2,; /* type: directional */ + 5.0, 2.0, 7.0,; /* location: right shoulder */ + 0.5, 0.5, 0.5,; /* colour: gray */ + 0.0, 0.0); /* attenuation: don't care */ ppost_struct(WorkstnID, TheMesh, 1.0) /* mark structure for display */ /* = = = define the spline-generating structure = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ popen_struct(TheMesh); /* open structure */ pset_light_source_st(2, LightsOn, 0, Dummy); /* set light source state */ psire(4); /* set int. reflectance eq'n */ /*---- set up transformations -------------------------------------------*/ ptranslate3(- 0.5, 0.0, - 0.5, Error, xform) /* 3d translate: to origin */ pset_local_tran3(xform, PTYPE_REPLACE); /* set local transformation */ pscale3(0.7, 0.7, 0.7, Error, xform) /* 3d scale to 70% */ pset_local_tran3(xform, PTYPE_POSTCONCAT); /* set local transformation */ protate_x(rad(30), Error, xform); /* rotate about X axis */ pset_local_tran3(xform, PTYPE_POSTCONCAT); /* set local transformation */ protate_y(rad(0), Error, xform); /* rotate about Y axis */ plabel(MeshLabel); /* label */ pset_local_tran3(xform, PTYPE_POSTCONCAT); /* set local transformation */ ptranslate3(0.5, 0.3, 0.5, Error, xform) /* 3d translate: into position */ pset_local_tran3(xform, PTYPE_POSTCONCAT); /* set local transformation */ /*---- delta t (independent variable) of 0.1 ----------------------------*/ pprec(0, Dummy, 4, StepSizeData, /* pack data record */ + 0, 0, '', 10, Error, DataRecLen, DataRec); if (Error <> 0){ printf("Error", Error, "in pprec."); exit(1); } pset_surf_approx_crit(-3, DataRecLen, DataRec) /* set surface approx. criteria */ /*---- define the b-spline surface --------------------------------------*/ pset_int_colr(1, 0, Gray); /* set interior colour */ pset_int_style(PSTYLE_SOLID); /* set interior style */ pnubss(; /* non-uniform b-spline surface */ + 3, 4,; /* u, v order */ + 3, 4,; /* u, v control points */ + 6, 8,; /* u, v knots */ + uKnotVector, vKnotVector,; /* u, v knot vectors */ + PNRAT,; /* non-rational surface */ + CtrlPtsX, CtrlPtsY, CtrlPtsZ,; /* control points' XYZs */ + Dummy,; /* dummy homogeneous coords */ + 0.0, 0.0, 0.0, 0.0,; /* u/v min/max: ignored */ + 0, Dummy); /* no trimming curves */ /*---- draw control-point grid ------------------------------------------*/ pset_linetype(PLINE_DOT); /* set line type */ for (u = 1; u <= 3; u++) { for (v = 1; v <= 4; v++) { I = (v-1) * 3 + u; /* index of X(u,v) */ Iu = (v-1) * 3 + u + 1; /* index of X(u + 1,v) */ Iv = v * 3 + u; /* index of X(u,v + 1) */ if (u < 3); /* unless on right edge... */ + Line(CtrlPtsX(I), CtrlPtsY(I), CtrlPtsZ(I), + CtrlPtsX(Iu), CtrlPtsY(Iu), CtrlPtsZ(Iu)); if (v < 4); /* unless on right edge... */ + Line(CtrlPtsX(I), CtrlPtsY(I), CtrlPtsZ(I), + CtrlPtsX(Iv), CtrlPtsY(Iv), CtrlPtsZ(Iv)); } } pclst; /* close structure */ /* = = = rotate the spline surface = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ Theta = ThetaMin; /* initialize loop control var. */ do while (Theta < ThetaMax); /* for each angle... */ popen_struct(TheMesh); /* open structure */ protate_y(rad(Theta), Error, xform) /* rotate about Y axis */ pset_elem_ptranslate(1); /* set element pointer: BOS */ pseplabel(MeshLabel); /* set element pointer at label */ poffset_elem_ptranslate(1); /* offset element pointer: + 1 */ pset_edit_mode(PEDIT_REPLACE); /* set edit mode */ pset_local_tran3(xform, PTYPE_POSTCONCAT); /* set local transformation */ pclst; /* close structure */ pupd_ws(WorkstnID, PFLAG_PERFORM); /* update the workstation */ Theta = Theta + dTheta; /* increment angle */ } /*---- make keyboard a choice device so "[Return] to quit." works ------*/ pset_choice_mode(WorkstnID, 2, POP_REQ, PSWITCH_NO_ECHO)/* set choice mode on keyboard */ preq_choice(WorkstnID, 2, ChoiceStatus, ChoiceNum) /* request choice */ pclose_ws(WorkstnID); /* close workstation */ pclph; /* close phigs */}; /* end of program *//* ***************************************************************************** */ subroutine Line(X1, Y1, Z1, X2, Y2, Z2); float X1, Y1, Z1, X2, Y2, Z2; /* "from" point, "to" point */ float X(2), Y(2), Z(2); /* for 3D polyline */ X(1) = X1; /* \ */ Y(1) = Y1; /* \ */ Z(1) = Z1; /* \ put the individual */ X(2) = X2; /* / values into the arrays */ Y(2) = Y2; /* / */ Z(2) = Z2; /* / */ ppolyline3(2, X, Y, Z); /* polyline 3D */ return}/* ***************************************************************************** */ subroutine DefineLight(WorkstnID, LightNo, LightType, X,Y,Z, + R,G,B, A1,A2); int WorkstnID; /* workstation identifier */ int LightNo; /* which light being defined? */ int LightType; /* ambient? directional? posit.? */ float X, Y, Z; /* location/direction of light */ float R, G, B; /* color of light */ float A1, A2; /* atten. factors for positional */ int Offset; /* to put RGB values in array */ int Error; /* error-return variable */ int UseRGB(2); /* use RGB, not indexes */ data UseRGB /1, 0/; /* say it so "pprec" understands */ float Reals(8); /* defined for "pprec" */ int Recs; /* defined by "pprec" */ char DataRec[80] (8); /* defined by "pprec" */ if (LightType == 1){; /* defining ambient light */ Offset = 0; /* offset of RGB in float array */ else Reals(1) = X; /* \ */ Reals(2) = Y; /* > insert location/direction */ Reals(3) = Z; /* / */ if (LightType == 2){; /* defining directional light */ Offset = 3; /* offset of RGB in float array */ else /* (LightType = 3) ! defining positional light */ Offset = 5; /* offset of RGB in float array */ Reals(4) = A1; /* 1st attenuation coefficient */ Reals(5) = A2; /* 2nd attenuation coefficient */ } } Reals(Offset + 1) = R; /* \ */ Reals(Offset + 2) = G; /* > install colour value */ Reals(Offset + 3) = B; /* / */ if (LightType == 1); /* ambient */ + pprec(2,UseRGB, 3,Reals, 0,80,'', 8, Error, Recs,DataRec); if (LightType == 2); /* directional */ + pprec(2,UseRGB, 6,Reals, 0,80,'', 8, Error, Recs,DataRec); if (LightType == 3); /* positional */ + pprec(2,UseRGB, 8,Reals, 0,80,'', 8, Error, Recs,DataRec); if (Error <> 0){ printf("Error", Error, "in pprec. Terminating."); exit(1); } pset_light_source_rep(WorkstnID, LightNo, LightType, /* set light source rep. */ + Recs, DataRec); return}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -