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

📄 zoomview.c

📁 Intro/: Directory containing introductory examples. HelloWorld.c A simple program that draws a bo
💻 C
📖 第 1 页 / 共 2 页
字号:
    Points[0].x = X1, Points[0].y = Y1, Points[0].z = Z1;    Points[1].x = X2, Points[1].y = Y2, Points[1].z = Z2;    PointList.num_points = 2;    PointList.points = Points;    ppolyline3(&PointList);}/****************************************************************************/SupinePolygon(Sides)int		Sides;			/* number of sides of polygon */{    Ppoint_list3	PointList;	/* entirety of data for POLYLINE 3 */    Ppoint3		Points[360];	/* XYZ data for POLYLINE 3 */    int			dTheta, I, Index;/* loop control variables */    float		Theta;		/* temporary variable */    dTheta = 360/Sides;			/* degrees per side */    Index = 0;				/* for array subscripts */    for (I = 0; I <= 360; I += dTheta) {	Theta = rad((float) I);		/* convert degrees to radians */	Points[Index].x = cos(Theta);	/* \                     */	Points[Index].y = sin(Theta);	/*  > calculate XYZ data */	Points[Index].z = 0.0;		/* /                     */	Index++;			/* increment array subscript */    }    PointList.num_points = Sides + 1;    PointList.points = Points;    ppolyline3(&PointList);}/****************************************************************************/Cylinder(Radius, dRadius, Height, dHeight)float	Radius;				/* radius of cylinder */float	dRadius;			/* dist. between circles in top/btm */float	Height;				/* total height of cylinder */float	dHeight;			/* dist. between layers in cylinder */{    Pmatrix3	M1, M2, M;		/* transformation matrices */    Pvec3	XformVec;		/* for C binding */    int		Error;			/* error return variable */    float	R, Z;			/* loop control variables */        R = dRadius;			/* initial radius */    while (R <= Radius) {	/*--- do bottom first ----------------------------------------------*/	XformVec.delta_x = XformVec.delta_y = R;	XformVec.delta_z = 1.0;	pscale3(&XformVec, &Error, M1);	if (Error) printf("Error %d in pscale3.\n", Error), exit(1);	pset_local_tran3(M1, PTYPE_REPLACE);	pexec_struct(CircleID);	/*--- do top -------------------------------------------------------*/	XformVec.delta_x = XformVec.delta_y = 0.0;	XformVec.delta_z = Height;	ptranslate3(&XformVec, &Error, M2);	if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);	pcompose_matrix3(M1, M2, &Error, M);	if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);	pset_local_tran3(M, PTYPE_REPLACE);	pexec_struct(CircleID);	R += dRadius;			/* increment the radius */    }    Z = 0.0;    XformVec.delta_x = XformVec.delta_y = Radius;    XformVec.delta_z = 1.0;    pscale3(&XformVec, &Error, M1);    if (Error) printf("Error %d in pscale3.\n", Error), exit(1);    while (Z <= Height) {	XformVec.delta_x = XformVec.delta_y = 0.0;	XformVec.delta_z = Z;	ptranslate3(&XformVec, &Error, M2);	if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);	pcompose_matrix3(M1, M2, &Error, M);	if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);	pset_local_tran3(M, PTYPE_REPLACE);	pexec_struct(CircleID);	Z += dHeight;			/* increment the height */    }}/****************************************************************************/Cone(Radius, Height, dHeight)float		Radius;			/* radius of sphere */float		Height;			/* height of whole cone */float		dHeight;		/* distance between rings */{    Pmatrix3	M1, M2, M;		/* transformation matrices */    Pvec3	XformVec;		/* for C binding */    int		Error;			/* error return variable */    float	Z, R;			/* loop control variable */    Z = dHeight;			/* initial height */    while (Z <= Height) {	R = Radius * ((Height - Z)/Height);	XformVec.delta_x = XformVec.delta_y = R;	XformVec.delta_z = 1.0;	pscale3(&XformVec, &Error, M1);	if (Error) printf("Error %d in pscale3.\n", Error), exit(1);	XformVec.delta_x = XformVec.delta_y = 0;	XformVec.delta_z = Z;	ptranslate3(&XformVec, &Error, M2);	if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);	pcompose_matrix3(M1, M2, &Error, M);	if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);	pset_local_tran3(M, PTYPE_REPLACE);	pexec_struct(CircleID);	Z += dHeight;			/* increment the height */    }}/****************************************************************************/Sphere(Radius, dPhi)float		Radius;			/* radius of sphere */float		dPhi;			/* angular dist. between latitudes */{    Pmatrix3	M1, M2, M;		/* transformation matrices */    Pvec3	XformVec;		/* for C binding */    int		Error;			/* error return variable */    float	Phi, R, Z;		/* loop control variables */    Phi = dPhi;				/* initial radius */    while (Phi < 180.0) {	R = Radius * sin(rad(Phi));	Z = Radius * cos(rad(Phi));	XformVec.delta_x = XformVec.delta_y = R;	XformVec.delta_z = 1.0;	pscale3(&XformVec, &Error, M1);	if (Error) printf("Error %d in pscale3.\n", Error), exit(1);	XformVec.delta_x = XformVec.delta_y = 0.0;	XformVec.delta_z = Z;	ptranslate3(&XformVec, &Error, M2);	if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);	pcompose_matrix3(M1, M2, &Error, M);	if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);	pset_local_tran3(M, PTYPE_REPLACE);	pexec_struct(CircleID);	Phi += dPhi;			/* increment Phi */    }}/****************************************************************************/Cube(Distance, dDistance, Height, dHeight)float		Distance;		/* center-to-corner distance */float		dDistance;		/* dist. between vert. in top/btm */float		Height;			/* total height of cube */float		dHeight;		/* distance between layers in cube */{    Pmatrix3	M1, M2, M;		/* transformation matrices */    Pvec3	XformVec;		/* for C binding */    int		Error;			/* error return variable */    float	Dist, Z;		/* loop control variables */        Dist = dDistance;			/* initial radius */    while (Dist <= Distance) {	/*--- do bottom first ----------------------------------------------*/	XformVec.delta_x = XformVec.delta_y = Dist;	XformVec.delta_z = 1.0;	pscale3(&XformVec, &Error, M1);	if (Error) printf("Error %d in pscale3.\n", Error), exit(1);	pset_local_tran3(M1, PTYPE_REPLACE);	pexec_struct(SquareID);	/*--- do top -------------------------------------------------------*/	XformVec.delta_x = XformVec.delta_y = 0.0;	XformVec.delta_z = Height;	ptranslate3(&XformVec, &Error, M2);	if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);	pcompose_matrix3(M1, M2, &Error, M);	if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);	pset_local_tran3(M, PTYPE_REPLACE);	pexec_struct(SquareID);	Dist += dDistance;		/* increment the radius */    }    Z = 0.0;    XformVec.delta_x = XformVec.delta_y = Distance;    XformVec.delta_z = 1.0;    pscale3(&XformVec, &Error, M1);    if (Error) printf("Error %d in pscale3.\n", Error), exit(1);    while (Z <= Height) {	XformVec.delta_x = XformVec.delta_y = 0.0;	XformVec.delta_z = Z;	ptranslate3(&XformVec, &Error, M2);	if (Error) printf("Error %d in ptranslate3.\n", Error), exit(1);	pcompose_matrix3(M1, M2, &Error, M);	if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);	pset_local_tran3(M, PTYPE_REPLACE);	pexec_struct(SquareID);	Z += dHeight;			/* increment the height */    }}/****************************************************************************/DefineCameraView(WorkstnID, ViewNo, PRPx, PRPy, PRPz, VRPx, VRPy, VRPz,  FieldOfView, ProjType, VUPx, VUPy, VUPz)int		WorkstnID, ViewNo;	/* workstn id, view to be defined */float		PRPx, PRPy, PRPz;	/* Proj Ref Pt (point looked from) */float		VRPx, VRPy, VRPz;	/* View Ref Pt (point looked at) */float		FieldOfView;		/* "zoomness" in degrees */Pproj_type	ProjType;		/* parallel or perspective? */float		VUPx, VUPy, VUPz;	/* view up vector */{    Pview_map3	MapStruct;		/* structure for view mapping info */    Ppoint3	ViewRefPt;		/* View Reference Point */    Pvec3	ViewNrmVc, ViewUpVec;	/* View Normal/Up Vectors */    Pmatrix3	Mapping;		/* view mapping matrix */    Pmatrix3	Orientation;		/* view orientation matrix */    float	Distance;		/* distance from PRP to VRP */    float	Wndw;			/* window limits */    Pview_rep3	ViewRep;		/* view representation */    int		Error;			/* error return variable */    int		I, J;			/* loop control variables */        ViewRefPt.x = VRPx, ViewRefPt.y = VRPy, ViewRefPt.z = VRPz;    ViewNrmVc.delta_x = PRPx - VRPx;	/* \  View Plane Normal determined  */    ViewNrmVc.delta_y = PRPy - VRPy;	/*  > by Projection Reference Point */    ViewNrmVc.delta_z = PRPz - VRPz;	/* /  and View Reference Point.     */    ViewUpVec.delta_x = VUPx, ViewUpVec.delta_y = VUPy,      ViewUpVec.delta_z = VUPz;    peval_view_ori_matrix3(&ViewRefPt, &ViewNrmVc, &ViewUpVec, &Error,      Orientation);    if (Error) printf("Error %d in peval_view_ori_matrix3.\n", Error), exit(1);    Distance = sqrt((PRPx-VRPx)*(PRPx-VRPx) + (PRPy-VRPy)*(PRPy-VRPy) +      (PRPz-VRPz)*(PRPz-VRPz));    Wndw = Distance * tan(rad(FieldOfView/2));	/* FOV controls window size */    MapStruct.win.x_min =		/* \                               */      MapStruct.win.y_min = -Wndw;	/*  \ This assumes a square window */    MapStruct.win.x_max =		/*  / (aspect ratio = 1.00).       */      MapStruct.win.y_max = Wndw;	/* /                               */    MapStruct.proj_vp.x_min = MapStruct.proj_vp.y_min =      MapStruct.proj_vp.z_min = 0.0;    MapStruct.proj_vp.x_max = MapStruct.proj_vp.y_max =      MapStruct.proj_vp.z_max = 1.0;    MapStruct.proj_type = ProjType;    MapStruct.proj_ref_point.x = 0.0, MapStruct.proj_ref_point.y = 0.0,      MapStruct.proj_ref_point.z = Distance;    MapStruct.view_plane = 0.0;    MapStruct.back_plane = -450 * Distance;	/* "virtually infinite" */    MapStruct.front_plane = Distance - 0.01;	/* right in front of eye pt */    peval_view_map_matrix3(&MapStruct, &Error, Mapping);    if (Error) printf("Error %d in peval_view_map_matrix3.\n", Error), exit(1);    for (I = 0; I < 4; I++)	for (J = 0; J < 4; J++) {	    ViewRep.ori_matrix[I][J] = Orientation[I][J];	    ViewRep.map_matrix[I][J] = Mapping[I][J];	}    ViewRep.clip_limit.x_min = 0.0;    ViewRep.clip_limit.x_max = 1.0;    ViewRep.clip_limit.y_min = 0.0;    ViewRep.clip_limit.y_max = 1.0;    ViewRep.clip_limit.z_min = 0.0;    ViewRep.clip_limit.z_max = 1.0;    ViewRep.xy_clip = ViewRep.back_clip = ViewRep.front_clip = PIND_CLIP;    pset_view_rep3(WorkstnID, ViewNo, &ViewRep);}/****************************************************************************/PolarToRectangular(R, Theta, Phi, X, Y, Z)float	R, Theta, Phi;		/* input: 3D polar (spherical) coords */float	*X, *Y, *Z;		/* output: 3D rect. (Cartesian) coords */{        *X = R * sin(Phi) * cos(Theta);    *Y = R * sin(Phi) * sin(Theta);    *Z = R * cos(Phi);}/****************************************************************************/AppendTransformation(MainTransform, Appendix)Pmatrix3	MainTransform;	/* the transformation to be appended to */Pmatrix3	Appendix;	/* the transformation to be appended */{        Pmatrix3	Temp;		/* temporary matrix holder */    int		Error;		/* error indicator */    int		I, J;		/* loop control variables */        pcompose_matrix3(Appendix, MainTransform, &Error, Temp);    if (Error) printf("Error %d in pcompose_matrix3.\n", Error), exit(1);    for (I = 0; I < 4; I++)			/* \  Copy result matrix  */	for (J = 0; J < 4; J++)			/*  > back into the first */	    MainTransform[I][J] = Temp[I][J];	/* /  argument matrix.    */}/****************************************************************************/Pfloat rad(Degrees)			/* convert degrees to radians */float	Degrees;{    return (Degrees * 3.1415926535897932384 / 180);}

⌨️ 快捷键说明

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