⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewport.c

📁 Intro/: Directory containing introductory examples. HelloWorld.c A simple program that draws a bo
💻 C
字号:
#include <phigs.h>			/* get HP-PHIGS definitions for C */#include <stdio.h>			/* get standard I/O definitions */#define  FALSE			0	/* boolean false is integer 0 */#define	 TRUE			1	/* boolean true is integer 1 */main()					/* file "Viewport.c" */{    Pint	WorkstnID = 1;		/* workstation identifier */    Pint	ConnID;			/* connection identifier */    Pint	WorkstnType = POIDDX;	/* out/in, direct, dbl bfr, Xwindow */    Pint	TheCurve = 1;		/* structure ID (chosen by user) */    Ppoint	LinePts[100];		/* points for the polyline */    Ppoint_list	LineData;		/* data for the polyline */    FILE	*datafile;		/* file pointer */    int		I = 0;			/* loop control variable */    /*=== read data file into the structure array ==========================*/    datafile = fopen("data", "r");	/* open data file (2 numbers/line) */    while (fscanf(datafile, "%f%f", &LinePts[I].x, &LinePts[I].y) != EOF)	I++;    fclose(datafile);    LineData.num_points = I;    LineData.points = LinePts;    /*=== set up HP-PHIGS to plot data =====================================*/    popen_phigs((char *) stderr, 0);	/* errors go to "stderr" */    pescape_u4("/dev/screen/phigs_window", &ConnID);    popen_ws(WorkstnID, (void *) ConnID, WorkstnType);    DefineView(WorkstnID, 1,		/* mapping for view index 1: */      0.0,  1.0,  0.0,  1.0,		/*   window: 0-1, 0-1 */      0.12, 0.98, 0.10, 0.88,		/*   viewport: in a subset */      FALSE);				/*   don't clip at view window */    popen_struct(TheCurve);    pset_view_ind(1);    DefineRectangle(0.0, 1.0, 0.0, 1.0);    ppolyline(&LineData);    pclose_struct();    /*=== post the image and close up shop =================================*/    ppost_struct(WorkstnID, TheCurve, 1.0);    pupd_ws(WorkstnID, PFLAG_PERFORM);	/* (regeneration flag) */    pclose_ws(WorkstnID);    pclose_phigs();}/****************************************************************************/DefineView(WorkstnID, ViewIndex, Wxmin, Wxmax, Wymin, Wymax,  Vxmin, Vxmax, Vymin, Vymax, ClipAtWindow)int	WorkstnID;			/* workstation identifier */int	ViewIndex;			/* the view being defined */float	Wxmin, Wxmax, Wymin, Wymax;	/* view window limits */float	Vxmin, Vxmax, Vymin, Vymax;	/* projection viewport limits */int	ClipAtWindow;			/* window (or display surface?) */{    Pview_map	Mapping;		/* window-onto-viewport mapping */    Pint	ErrorReturn;		/* error return variable */    Pview_rep	ViewRep;		/* complete description of view */    int		I, J;			/* loop control variables */    /*--- define the view orientation matrix as identity -------------------*/    for (I = 0; I < 3; I++)	for (J = 0; J < 3; J++)	    ViewRep.ori_matrix[I][J] = (I == J);    /*--- define view mapping matrix ---------------------------------------*/    Mapping.win.x_min = Wxmin;			/* \			    */    Mapping.win.x_max = Wxmax;			/*  \ put individual values */    Mapping.win.y_min = Wymin;			/*  / into the structure    */    Mapping.win.y_max = Wymax;			/* /			    */    Mapping.proj_vp.x_min = Vxmin;		/* \			    */    Mapping.proj_vp.x_max = Vxmax;		/*  \ put individual values */    Mapping.proj_vp.y_min = Vymin;		/*  / into the structure    */    Mapping.proj_vp.y_max = Vymax;		/* /			    */    peval_view_map_matrix(&Mapping, &ErrorReturn, ViewRep.map_matrix);    if (ErrorReturn != 0) {			/* did we get an error? */        printf("%s %d %s %s\n", "Error", ErrorReturn, "occurred during",          "call to Evaluate View Mapping Matrix.");        exit(1);    }    /*--- define the clip limits -------------------------------------------*/    if (ClipAtWindow)	ViewRep.clip_limit = Mapping.proj_vp;	/* clip at viewport */    else {	ViewRep.clip_limit.x_min = 0.0;		/* \		       */	ViewRep.clip_limit.x_max = 1.0;		/*  \ clip at edges of */	ViewRep.clip_limit.y_min = 0.0;		/*  / display surface  */	ViewRep.clip_limit.y_max = 1.0;		/* /		       */    }    /*--- define clip indicator --------------------------------------------*/    ViewRep.xy_clip = PIND_CLIP;    /*--- set the view representation --------------------------------------*/    pset_view_rep(WorkstnID, ViewIndex, &ViewRep);}/****************************************************************************/DefineRectangle(Xmin, Xmax, Ymin, Ymax)float	Xmin, Xmax, Ymin, Ymax;			/* rectangle's limits */{    Ppoint_list	Rectangle;    Ppoint	Corners[5];          Rectangle.num_points = 5;    Corners[0].x = Xmin, Corners[0].y = Ymin;	/* lower left corner */    Corners[1].x = Xmax, Corners[1].y = Ymin;	/* lower right corner */    Corners[2].x = Xmax, Corners[2].y = Ymax;	/* upper right corner */    Corners[3].x = Xmin, Corners[3].y = Ymax;	/* upper left corner */    Corners[4].x = Xmin, Corners[4].y = Ymin;	/* lower left corner */    Rectangle.points = Corners;    ppolyline(&Rectangle);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -