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

📄 triquad.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 */#include <math.h>			/* link with library "-lm" */#define Longitudes	30		/* sections along equator and... */#define Latitudes	15		/* from pole to pole of sphere */main()					/* file "TriQuad.c" */{    Pint	WorkstnID = 1;		/* workstation identifier */    Pint	ConnID;			/* connection identifier */    Pint	WorkstnType = POIDDX;	/* out/in, direct, dbl bfr, Xwindow */    Pint	TheStructure = 1;	/* structure ID (chosen by user) */    Pvertex3_array Sphere;		/* globe (with latitudes/longitudes) */    Ppoint3	SpherePts[Latitudes + 1][Longitudes + 1];    Pvertex3_list Belt;			/* strip girdling the globe */    Ppoint3	BeltPts[62];		/* data points of belt */    Pgcolr	Black, White;		/* working colours */    Pvec3	Vector;			/* for various scales/translations */    float	Theta, Phi, CosPhi;	/* working variables */    Pmatrix3	xform;			/* transformation matrix */    int	Longitude, Latitude, I; 	/* loop control variables */    int	Error;				/* error-return variable */    float	rad();			/* forward reference */    popen_phigs((char *) stderr, 0);	/* errors go to "stderr" */    pescape_u4("/dev/screen/phigs_window", &ConnID);    popen_ws(WorkstnID, (void *) ConnID, WorkstnType);    Black.colr_type = PCOLR_RGB;    Black.colr_value.colr_rep.rgb.red	= 0.0;    Black.colr_value.colr_rep.rgb.green = 0.0;    Black.colr_value.colr_rep.rgb.blue	= 0.0;    White.colr_type = PCOLR_RGB;    White.colr_value.colr_rep.rgb.red	= 1.0;    White.colr_value.colr_rep.rgb.green = 1.0;    White.colr_value.colr_rep.rgb.blue	= 1.0;    popen_struct(TheStructure);    /*--- define the data bases --------------------------------------------*/    Sphere.dims.size_x = Longitudes+1;    Sphere.dims.size_y = Latitudes+1;    Sphere.num_data_per_vertex = 0;    for (Longitude = 0; Longitude <= Longitudes; Longitude++) {	Theta = 360.0 * Longitude / Longitudes;	for (Latitude = 0; Latitude <= Latitudes; Latitude++) {	    Phi = -89.99 + 179.98 * Latitude / Latitudes;	    CosPhi = cos(rad(Phi));	    SpherePts[Latitude][Longitude].x = CosPhi * cos(rad(Theta));	    SpherePts[Latitude][Longitude].y = CosPhi * sin(rad(Theta));	    SpherePts[Latitude][Longitude].z = sin(rad(Phi));	}    }    Sphere.vertex_points = &(SpherePts[0][0]);    Sphere.vertex_colrvs.colr_reps.rgb = NULL;    Sphere.vertex_norms = NULL;    Sphere.vertex_data = NULL;    Belt.num_vertices = 62;    Belt.num_data_per_vertex = 0;    for (Longitude = 0; Longitude <= Longitudes; Longitude++) {	Theta = 360.0 * (Longitude+1) / Longitudes;	BeltPts[2 * Longitude	 ].x = 1.4 * cos(rad(Theta));	BeltPts[2 * Longitude	 ].y = 1.4 * sin(rad(Theta));	BeltPts[2 * Longitude	 ].z = 0.15;	BeltPts[2 * Longitude + 1].x = 1.4 * cos(rad(Theta));	BeltPts[2 * Longitude + 1].y = 1.4 * sin(rad(Theta));	BeltPts[2 * Longitude + 1].z = -0.15;    }    Belt.vertex_points = BeltPts;    Belt.vertex_colrvs.colr_reps.rgb = NULL;    Belt.vertex_norms = NULL;    Belt.vertex_data = NULL;    /*--- render the sphere and its encircling belt ------------------------*/    pset_hlhsr_mode(WorkstnID, PHRZBF);    pset_int_style(PSTYLE_SOLID);    pset_int_colr(&Black);    pset_edge_flag(PEDGE_ON);    pset_edge_colr(&White);    protate_x(rad(110.0), &Error, xform);    pset_local_tran3(xform, PTYPE_POSTCONCAT);    protate_z(rad(-20.0), &Error, xform);    pset_local_tran3(xform, PTYPE_POSTCONCAT);    Vector.delta_x = Vector.delta_y = Vector.delta_z = 0.35;    pscale3(&Vector, &Error, xform);    pset_local_tran3(xform, PTYPE_POSTCONCAT);    Vector.delta_x = Vector.delta_y = Vector.delta_z = 0.5;    ptranslate3(&Vector, &Error, xform);    pset_local_tran3(xform, PTYPE_POSTCONCAT);    pquad_mesh3_data(PCOLR_RGB, NULL, NULL, &Sphere);    ptri_strip3_data(PCOLR_RGB, NULL, NULL, &Belt);    pclose_struct();    ppost_struct(WorkstnID, TheStructure, 1.0);    pupd_ws(WorkstnID, PFLAG_PERFORM);    pclose_ws(WorkstnID);    pclose_phigs();}/****************************************************************************/float rad(deg)float	deg;{    return (deg * 3.14159265358979 / 180.0);	/* convert deg to radians */}

⌨️ 快捷键说明

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