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

📄 zoomview.c

📁 Intro/: Directory containing introductory examples. HelloWorld.c A simple program that draws a bo
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <phigs.h>			/* get HP-PHIGS definitions for C */#include <stdio.h>			/* get standard I/O definitions */#include <math.h>			/* link with library "-lm" */Pint	SceneID = 1, PlaneID = 2, CircleID = 3, CylinderID = 4,	ConeID = 5, SphereID = 6, SquareID = 7,	CubeID = 8;Pfloat	rad();				/* forward reference */main()					/* file "ZoomView.c" */{    Pint	WorkstnID = 1;		/* workstation identifier */    Pint	ConnID;			/* connection identifier */    Pint	WorkstnType = POIDDX;	/* out/in, direct, dbl bfr, Xwindow */    Pint	Error;			/* error indicator */    float	CenterX = 5.0, CenterY = 5.0;	/* center of image rotation */    Pmatrix3	M1, M2, M3, M4, M;	/* transformation matrices */    Pvec3	XformVec1, XformVec2;	/* for scalings and translations */    static Ppoint3 Origin  = {0.0, 0.0, 0.0};	/* 3D Cartesian origin */    static Pvec3   ZeroVec = {0.0, 0.0, 0.0};	/* all-zero vector */    static Pvec3   OneVec  = {1.0, 1.0, 1.0};	/* all-one vector */    float	X, Y, Z;		/* temporary position variables */    float	X1, Y1, Z1, X2, Y2, Z2;	/* position last time/this time */    float	VelX1, VelY1, VelZ1;	/* velocity last time */    float	VelX2, VelY2, VelZ2;	/* velocity this time */    float	AccelX1, AccelY1, AccelZ1;	/* acceleration last time */    float	AccelX2, AccelY2, AccelZ2;	/* acceleration this time */    int		I,J;			/* loop control variable */    /*=== open PHIGS and workstation =======================================*/    popen_phigs((char *) stderr, 0);		/* errors go to "stderr" */    pescape_u4("/dev/screen/phigs_window", &ConnID);    popen_ws(WorkstnID, (void *) ConnID, WorkstnType);    /*=== define all needed structures =====================================*/    /*---- define the "floor" plane ----------------------------------------*/    popen_struct(PlaneID);			/* open structure  */    Plane(0.0, 10.0, 1.0, 0.0, 10.0, 2.0);	/* define plane */    pclose_struct();				/* close structure */    /*---- define the 2D shapes with supporting roles ----------------------*/    popen_struct(CircleID);			/* open structure */    SupinePolygon(24);				/* define a "circle" */    pclose_struct();				/* close structure */    popen_struct(SquareID);			/* open structure */    SupinePolygon(4);				/* define a square */    pclose_struct();				/* close structure */    /*---- define the cylinder ---------------------------------------------*/    popen_struct(CylinderID);			/* open structure  */    Cylinder(1.0, 0.2, 1.0, 0.1);		/* define cylinder */    pclose_struct();				/* close structure */    /*---- define the cone -------------------------------------------------*/    popen_struct(ConeID);			/* open structure */    Cone(1.0, 2.0, 0.05);			/* define cone */    pclose_struct();				/* close structure */    /*---- define the sphere -----------------------------------------------*/    popen_struct(SphereID);			/* open structure  */    Sphere(1.0, 5.0);				/* define sphere */    pclose_struct();				/* close structure */    /*---- define the cube -------------------------------------------------*/    popen_struct(CubeID);			/* open structure */    Cube(sqrt(2.0)/2, 0.1, 1.0, 0.1);		/* define cube */    pclose_struct();				/* close structure */    /*=== define the scene =================================================*/    popen_struct(SceneID);    pset_view_ind(1);    pexec_struct(PlaneID);    /*---- cone ------------------------------------------------------------*/    XformVec1.delta_x = 5.0, XformVec1.delta_y = 1.0, XformVec1.delta_z = 0.0;    ptranslate3(&XformVec1, &Error, M);    if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);    pset_local_tran3(M, PTYPE_REPLACE);    pexec_struct(ConeID);    /*---- cylinders -------------------------------------------------------*/    XformVec1.delta_x = 2.0, XformVec1.delta_y = 8.0, XformVec1.delta_z = 0.0;    ptranslate3(&XformVec1, &Error, M);    if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);    pset_local_tran3(M, PTYPE_REPLACE);    pexec_struct(CylinderID);		/* short, fat cylinder */    XformVec1.delta_x = 0.0, XformVec1.delta_y = 0.0, XformVec1.delta_z =-0.5;    ptranslate3(&XformVec1, &Error, M);    if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);    XformVec1.delta_x = 0.4, XformVec1.delta_y = 0.4, XformVec1.delta_z = 2.0;    pscale3(&XformVec1, &Error, M1);    if (Error) printf("Error %d in pscale3.\n", Error), exit(1);    AppendTransformation(M, M1);    protate_x(rad(90.0), &Error, M1);    if (Error) printf("Error %d in protate_x.\n", Error), exit(1);    AppendTransformation(M, M1);    protate_z(rad(30.0), &Error, M1);    if (Error) printf("Error %d in protate_z.\n", Error), exit(1);    AppendTransformation(M, M1);    XformVec1.delta_x = 2.3, XformVec1.delta_y = 8.3, XformVec1.delta_z = 1.4;    ptranslate3(&XformVec1, &Error, M1);    if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);    AppendTransformation(M, M1);    pset_local_tran3(M, PTYPE_REPLACE);    pexec_struct(CylinderID);		/* tall, thin cylinder */    /*---- spheroids -------------------------------------------------------*/    pbuild_tran_matrix3(&Origin, &OneVec, rad(45.0), 0.0, 0.0, &OneVec,      &Error, M);    if (Error) printf("Error %d in pbuild_tran_matrix3.\n", Error), exit(1);    pset_local_tran3(M, PTYPE_REPLACE);    pexec_struct(SphereID);		/* sphere */    XformVec1.delta_x = 8.0, XformVec1.delta_y = 6.0, XformVec1.delta_z = 2.0;    XformVec2.delta_x = 0.5, XformVec2.delta_y = 0.5, XformVec2.delta_z = 2.0;    pbuild_tran_matrix3(&Origin, &XformVec1, 0.0, 0.0, 0.0, &XformVec2,      &Error, M);    if (Error) printf("Error %d in pbuild_tran_matrix3.\n", Error), exit(1);    pset_local_tran3(M, PTYPE_REPLACE);    pexec_struct(SphereID);		/* prolate spheroid */    XformVec1.delta_x = 5.0, XformVec1.delta_y = 1.0, XformVec1.delta_z = 2.5;    XformVec2.delta_x = 1.0, XformVec2.delta_y = 1.0, XformVec2.delta_z = 0.5;    pbuild_tran_matrix3(&Origin, &XformVec1, 0.0, 0.0, 0.0, &XformVec2,      &Error, M);    if (Error) printf("Error %d in pbuild_tran_matrix3.\n", Error), exit(1);    pset_local_tran3(M, PTYPE_REPLACE);    pexec_struct(SphereID);		/* oblate spheroid */    /*---- cubes -----------------------------------------------------------*/    protate_z(rad(45.0), &Error, M);    if (Error) printf("Error %d in protate_z.\n", Error), exit(1);    XformVec1.delta_x = 2.0, XformVec1.delta_y = 1.0, XformVec1.delta_z = 1.0;    pscale3(&XformVec1, &Error, M1);    if (Error) printf("Error %d in pscale3.\n", Error), exit(1);    AppendTransformation(M, M1);    protate_x(rad(90.0), &Error, M1);    if (Error) printf("Error %d in protate_x.\n", Error), exit(1);    AppendTransformation(M, M1);    protate_z(rad(30.0), &Error, M1);    if (Error) printf("Error %d in protate_z.\n", Error), exit(1);    AppendTransformation(M, M1);    XformVec1.delta_x = 8.0, XformVec1.delta_y = 3.0, XformVec1.delta_z = 0.5;    ptranslate3(&XformVec1, &Error, M1);    if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);    AppendTransformation(M, M1);    pset_local_tran3(M, PTYPE_REPLACE);    pexec_struct(CubeID);		/* bottom block */    protate_z(rad(45.0), &Error, M1);    if (Error) printf("Error %d in protate_z.\n", Error), exit(1);    protate_y(rad(90.0), &Error, M2);    if (Error) printf("Error %d in protate_y.\n", Error), exit(1);    pcompose_matrix3(M2, M1, &Error, M3);    if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);    protate_z(rad(50.0), &Error, M4);    if (Error) printf("Error %d in protate_z.\n", Error), exit(1);    pcompose_matrix3(M4, M3, &Error, M1);    if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);    XformVec1.delta_x = 7.8, XformVec1.delta_y = 2.5, XformVec1.delta_z = 1.5;    ptranslate3(&XformVec1, &Error, M2);    if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);    pcompose_matrix3(M2, M1, &Error, M);    if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);    pset_local_tran3(M, PTYPE_REPLACE);    pexec_struct(CubeID);		/* top cube */    pclose_struct();			/* close structure */    /*=== move around/in the scene =========================================*/    ppost_struct(WorkstnID, SceneID, 1.0);	/* post structure */    /*---- go around the scene once ----------------------------------------*/    for (I = 0; I <= 360; I += 2) {	PolarToRectangular(25.0, rad(I-90.0), rad(80.0), &X, &Y, &Z);	DefineCameraView(WorkstnID, 1,	/* workstation id, view number */	  X + CenterX, Y + CenterY, Z,	/* PRP (point looked from) */	  5.0, 5.0, 0.0,		/* VRP (point looked at) */	  30.0, PTYPE_PERSPECT,		/* field of view, proj. type */	  0.0, 0.0, 1.0);		/* up vector */	pupd_ws(1, PFLAG_PERFORM);	/* update workstation */    }    /*---- look down on the scene from above -------------------------------*/    pset_disp_upd_st(WorkstnID, PDEFER_ASAP, PMODE_NIVE);    for (I = 80; I >= 4; I--) {	PolarToRectangular(25.0, rad(-90.0), rad((float) I), &X, &Y, &Z);	DefineCameraView(WorkstnID, 1,	/* workstation id, view number */	  X + CenterX, Y + CenterY, Z,	/* PRP (point looked from) */	  5.0, 5.0, 0.0,		/* VRP (point looked at) */	  30.0, PTYPE_PERSPECT,		/* field of view, proj. type */	  0.0, 0.0, 1.0);		/* up vector */    }    for (I = 4; I <= 90; I += 2) {	PolarToRectangular(25.0, rad(-90.0), rad((float) I), &X, &Y, &Z);	DefineCameraView(WorkstnID, 1,	/* workstation id, view number */	  X + CenterX, Y + CenterY, Z,	/* PRP (point looked from) */	  5.0, 5.0, 0.0,		/* VRP (point looked at) */	  30.0, PTYPE_PERSPECT,		/* field of view, proj. type */	  0.0, 0.0, 1.0);		/* up vector */    }    /*---- move into the scene ---------------------------------------------*/    X1 = X + CenterX; Y1 = Y + CenterY; Z1 = Z;	/* starting point of move */    X2 = 7.0; Y2 = 10.0; Z2 = 1.0;		/* ending point of move */    for (I = 0; I <= 100; I++) {	X = (100-I)*X1*0.01 + I*X2*0.01;	/* \  Move linearly from  */	Y = (100-I)*Y1*0.01 + I*Y2*0.01;	/*  > point 1 to point 2, */	Z = (100-I)*Z1*0.01 + I*Z2*0.01;	/* /  in 101 easy steps   */	DefineCameraView(WorkstnID, 1,	/* workstation id, view number */	  X, Y, Z,			/* PRP (point looked from) */	  5.0, 5.0, 0.0,		/* VRP (point looked at) */	  30.0, PTYPE_PERSPECT,		/* field of view, proj. type */	  0.0, 0.0, 1.0);		/* up vector */    }    /*---- look up at the the cone/spheroid juncture -----------------------*/    X1 = 5.0; Y1 = 5.0; Z1 = 0.0;	/* starting point of pan/tilt */    X2 = 5.0; Y2 = 1.0; Z2 = 2.0;	/* ending point of pan/tilt */    for (I = 0; I <= 50; I++) {	X = (50-I)*X1*0.02 + I*X2*0.02;	/* \  Move linearly from point */	Y = (50-I)*Y1*0.02 + I*Y2*0.02;	/*  > 1 to point 2, in 51 */	Z = (50-I)*Z1*0.02 + I*Z2*0.02;	/* /  easy steps */	DefineCameraView(WorkstnID, 1,	/* workstation id, view number */	  7.0, 10.0, 1.0,		/* PRP (point looked from) */	  X, Y, Z,			/* VRP (point looked at) */	  30.0, PTYPE_PERSPECT,		/* field of view, proj. type */	  0.0, 0.0, 1.0);		/* up vector */    }    /*---- zoom in on the cone/spheroid juncture ---------------------------*/    for (I = 60; I >= 4; I--) {	DefineCameraView(WorkstnID, 1,	/* workstation id, view number */	  7.0, 10.0, 1.0,		/* PRP (point looked from) */	  X2, Y2, Z2,			/* VRP (point looked at) */	  I * 0.5, PTYPE_PERSPECT,	/* field of view, proj. type */	  0.0, 0.0, 1.0);		/* up vector */    }    for (I = 4; I <= 270; I += 2) {	DefineCameraView(WorkstnID, 1,	/* workstation id, view number */	  7.0, 10.0, 1.0,		/* PRP (point looked from) */	  X2, Y2, Z2,			/* VRP (point looked at) */	  I * 0.5, PTYPE_PERSPECT,	/* field of view, proj. type */	  0.0, 0.0, 1.0);		/* up vector */    }    for (I = 270; I >= 120; I--) {	DefineCameraView(WorkstnID, 1,	/* workstation id, view number */	  7.0, 10.0, 1.0,		/* PRP (point looked from) */	  X2, Y2, Z2,			/* VRP (point looked at) */	  I * 0.5, PTYPE_PERSPECT,	/* field of view, proj. type */	  0.0, 0.0, 1.0);		/* up vector */    }    /*---- fly away as in an airplane --------------------------------------*/    AccelX1 = 0.0; AccelY1 = 0.0; AccelZ1 = 1.0;    for (I = 0; I <= 1082; I++) {	/*---- devise a complex, but smooth, steadily rising flight path ---*/	X2 = 5 - 1.5*sin(rad(I*1.7)) - 0.9*cos(rad(I*0.34));	Y2 = 4 + (I*0.004 + 1)*cos(rad(I*1.3 + 15)) + 0.5*sin(rad(I*1.6));	Z2 = I * 0.003;	VelX2 = X2-X1, VelY2 = Y2-Y1, VelZ2 = Z2-Z1;	AccelX2 = VelX2-VelX1, AccelY2 = VelY2-VelY1, AccelZ2 = VelZ2-VelZ1;	if (I > 3) {		/* ignore anomalous values */	    DefineCameraView(WorkstnID,1,/* workstation id, view number */	      X1, Y1, Z1,		/* PRP (point looked from) */	      X2, Y2, Z2,		/* VRP (point looked at) */	      90.0, PTYPE_PERSPECT,	/* field of view, proj. type */	      AccelX1, AccelY1, 0.003);	/* up vector */	}	X1 = X2, Y1 = Y2, Z1 = Z2;	VelX1 = VelX2, VelY1 = VelY2, VelZ1 = VelZ2;	AccelX1 = AccelX2, AccelY1 = AccelY2, AccelZ1 = AccelZ2;    }    pupd_ws(WorkstnID, PFLAG_PERFORM);	/* (regeneration flag) */    pclose_ws(WorkstnID);    pclose_phigs();}/****************************************************************************/Plane(Xmin, Xmax, dX, Ymin, Ymax, dY)float	Xmin, Xmax, Ymin, Ymax;		/* defines size of floor */float	dX, dY;				/* size of tiles in floor */{    float	X, Y;			/* loop control variables */    X = Xmin;    while (X <= Xmax + 0.00001) {	OneLine(X, Ymin, 0.0, X, Ymax, 0.0);	X = X + dX;    }    Y = Ymin;    while (Y <= Ymax + 0.00001) {	OneLine(Xmin, Y, 0.0, Xmax, Y, 0.0);	Y = Y + dY;    }}/****************************************************************************/OneLine(X1, Y1, Z1, X2, Y2, Z2)float	X1, Y1, Z1, X2, Y2, Z2;		/* point 1, point 2 */{    Ppoint_list3	PointList;	/* entirety of data for POLYLINE 3 */    Ppoint3		Points[2];	/* XYZ data for POLYLINE 3 */    

⌨️ 快捷键说明

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