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

📄 phigscbs.c

📁 很不错的tcl编程实例
💻 C
字号:
/*
# Copyright 1996

# Authors

# Lakshmi Sastry
# Computing and Information Systems Department
# Rutherford Appleton Laboratory, Chilton, Didcot. OX11 0QX
# lakshmi.sastry@rl.ac.uk

#                         and

# Venkat VSS Sastry
# Department of Applied Mathematics and Operational Research
# Cranfield University, RMCS Shrivenham, Swindon, SN6 8LA
# sastry@rmcs.cran.ac.uk

# Permission to use, copy, modify, and distribute this
# software and its documentation for any purpose and without
# fee is hereby granted, provided that this copyright
# notice appears in all copies.
  
# The authors, RAL, RMCS Shrivenham, Cranfield University and AGOCG
# make no representations about the suitability of this
# software for any purpose.  It is provided "as is" without
# express or implied warranty. Likewise they accept no responsibility
# whatsoever for any public domain software modules used (which are
# hereby acknowledged) in this software 


# The 3D box with the text "It's a square world" in the routine "MakeCube" is 
# adopted from A Practical Introduction to PHIGS and PHIGS Plus.
*/

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <phigs/phigs.h>
#include "tcl.h"
#include "tk.h"

#define CUBE (Pint) 1
#define WS_ID (Pint) 1
#define PRIORITY (Pfloat) 1.0
#define PI (Pfloat) 3.141592654
#define CMAX (Pfloat)0.7
#define CMIN (Pfloat)0.3

static Ppoint3 ORIGIN ={0.5,0.5,0.5};

#define set_colour(colrv,typ,r,g,b) colrv.type=typ; \
	colrv.val.general.x=r;colrv.val.general.y= g;colrv.val.general.z=b;

#define fill_struc(A,B,C,D) A.x = B; A.y = C; A.z = D;

extern Pconnid_x_drawable conn_id;
static char text1[] = "It's a ";
static char text2[] = "square world!";

int CleanupAndQuitProc (ClientData clientdata, Tcl_Interp *interp,
	 int argc, char *argv[])
{
pclose_ws(WS_ID);
pclose_phigs();
exit(0);
}

int redrawProc (ClientData  clientdata, XEvent *evptr)
{
Pint error;
Pupd_st upd_st;
Plimit req_win,req_vp,cur_win,cur_vp,new_vp;

if (evptr->type == Expose) {
	if(evptr->xexpose.count == 0)
		predraw_all_structs(WS_ID,PFLAG_ALWAYS);
		
	
	return 0;
	}
else if (evptr->type == ConfigureNotify) {
	new_vp.x_min = 0;
	new_vp.y_min=0;
	new_vp.x_max=evptr->xconfigure.width;
	new_vp.y_max = evptr->xconfigure.height;
	pinq_ws_tran(WS_ID, &error,&upd_st,&req_win,&cur_win,
		&req_vp,&cur_vp);
	if (new_vp.x_max != cur_vp.x_max || new_vp.y_max != cur_vp.y_max)
		pset_ws_vp(WS_ID,&new_vp);
	return 0;
	}

}

int MakeCubeProc (ClientData clientdata, Tcl_Interp *interp,
	 int argc, char *argv[])

{
Pfloat angle;
Pint err;
Pmatrix3 transform;
Pfloat mid;
Ppoint3 front_face[5], back_face[5],link1[2], link2[2],  link3[2], link4[2]; 
Ppoint_list3 list1,list2,list3,list4,list5,list6;
Pgcolr yellow,white;


static Pvec3 shift = {0.0,0.0,0.0};
static Pvec3 scale = {1,1,1};
static Ppoint3 textloc1 = {0.5,0.6,0.7};
static Ppoint3 textloc2 = {0.5,0.5,0.7};
static Pvec textdir[] = {1.0,0.0,0.0,0.0,1.0,0.0};
static Ptext_align txalign = {PHOR_CTR, PVERT_HALF};

set_colour(yellow,PMODEL_RGB,1.0,1.0,0.0);
set_colour(white,PMODEL_RGB,1.0,1.0,1.0);


fill_struc(front_face[0], CMIN,CMIN,CMAX);
fill_struc(front_face[1], CMIN,CMAX,CMAX);
fill_struc(front_face[2], CMAX,CMAX,CMAX);
fill_struc(front_face[3], CMAX,CMIN,CMAX);
fill_struc(front_face[4], CMIN,CMIN,CMAX);

fill_struc(back_face[0], CMIN,CMIN,CMIN);
fill_struc(back_face[1], CMIN,CMAX,CMIN);
fill_struc(back_face[2], CMAX,CMAX,CMIN);
fill_struc(back_face[3], CMAX,CMIN,CMIN);
fill_struc(back_face[4], CMIN,CMIN,CMIN);


fill_struc(link1[0],CMIN,CMIN,CMIN);
fill_struc(link1[1],CMIN,CMIN,CMAX);

fill_struc(link2[0],CMIN,CMAX,CMIN);
fill_struc(link2[1],CMIN,CMAX,CMAX);

fill_struc(link3[0],CMAX,CMAX,CMIN);
fill_struc(link3[1],CMAX,CMAX,CMAX);

fill_struc(link4[0],CMAX,CMIN,CMIN);
fill_struc(link4[1],CMAX,CMIN,CMAX);

list1.num_points =  list2.num_points= 5;
list3.num_points = list4.num_points = list5.num_points = list6.num_points = 2;
list1.points = front_face;
list2.points = back_face;
list3.points =link1;
list4.points  = link2;
list5.points = link3;
list6.points  = link4;

popen_ws (WS_ID, (void *)&conn_id,phigs_ws_type_x_drawable);
pset_disp_upd_st(WS_ID, PDEFER_WAIT, PMODE_NIVE);

popen_struct(CUBE);
angle = 0;
pset_line_colr(&white);
pbuild_tran_matrix3 ( &ORIGIN, &shift, angle, angle, angle, &scale, &err, transform);
pset_local_tran3(transform,PTYPE_REPLACE);
ppolyline3(list1);
ppolyline3(list2);
ppolyline3(list3);
ppolyline3(list4);
ppolyline3(list5);
ppolyline3(list6);
pset_text_align(&txalign);
pset_char_ht((Pfloat)0.015);
pset_text_colr(&yellow);
ptext3(&textloc1,textdir,text1);
ptext3(&textloc2,textdir,text2);
pclose_struct();
ppost_struct(WS_ID, CUBE, PRIORITY);
return 0;
}

int rotate_boxProc ( ClientData clientdata, Tcl_Interp *interp, int argc, char *argv[])

{ 
Pint val;
Pfloat angle;
Pint err, i;
Pmatrix3 transform;
Ppoint3 origin;
Pint cube;
static Pvec3 shift = {0.0,0.0,0.0};
static Pvec3 scale = {1,1,1};  
val = (Pint ) argv[1];

val = (Pint ) atoi(argv[1]);
angle =val*PI/180;

popen_struct(CUBE);               /* Open the structure. */
pset_edit_mode(PEDIT_REPLACE);     /* Select REPLACE mode. */
pset_elem_ptr(2);
pbuild_tran_matrix3(&ORIGIN, &shift, angle,angle,angle, 
                   &scale, &err, transform);
pset_local_tran3(transform, PTYPE_REPLACE); 
pclose_struct();
pupd_ws(WS_ID, PFLAG_PERFORM);
return 0;
}



int ChColProc(ClientData clientdata, Tcl_Interp *interp,
	 int argc, char *argv[])

{
Pgcolr magenta,yellow,white,colr;

set_colour(magenta,PMODEL_RGB,1.0,0.0,1.0); 
set_colour(yellow,PMODEL_RGB,1.0,1.0,0.0);
set_colour(white,PMODEL_RGB,1.0,1.0,1.0);

if ((int) strcmp(argv[1],"Magenta") == 0)
	colr = magenta;
else if (strcmp(argv[1],"Yellow") == 0)
	colr = yellow;
else
	colr = white;
popen_struct(CUBE);               /* Open the structure. */
pset_edit_mode(PEDIT_REPLACE);     /* Select REPLACE mode. */
pset_elem_ptr(1);
pset_line_colr(&colr);
pclose_struct();
pupd_ws(WS_ID, PFLAG_PERFORM);
return 0;
}



 

⌨️ 快捷键说明

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