Functions | |
void | sh3dmask (float *x, float *y, float *z, float *nrm, int *imask) |
Determines if a point is masked. | |
void | sharrow (float *x0, float *y0, float *z0, int *idx0, int *idy0, float *x1, float *y1, float *z1, int *idx1, int *idy1) |
Draws a curved arrow from one point to another. | |
void | shchar (int *ix, int *iy, float *z, char *chr, int *ired, int *igrn, int *iblu, int *iw) |
Draws a character string at a point. | |
void | shclippg (int *n0, float *x0, float *y0, float *z0, float *nrm0, int *ic0, int *n1, float **x1, float **y1, float **z1, float **nrm1, int **ic1) |
Clips a polygon against planes added with ? | |
void | shclr () |
Clears the frame buffer to the current background color. | |
void | shcolor (float *x, float *y, float *z, float *n, int *rf, int *gf, int *bf, int *rb, int *gb, int *bb, int *r, int *g, int *b) |
Shades and renders a point. | |
void | shcs (int *ifnt, int *isx, int *isy) |
Sets the current font and shadow offset for characters. | |
void | shcube (float *xmin, float *xmax, float *ymin, float *ymax, float *zmin, float *zmax) |
Draw a wireframe cube. | |
void | shdopg (int *nt, float *xt, float *yt, float *zt, float *n) |
Shades and z-buffers a polygon. | |
void | shdraw (float *x, float *y, float *z, int *ip) |
A pen-up/pen-down style line drawing. | |
void | shfreeStrings (void) |
Clears the list of strings. | |
void | shend () |
Releases any storage that has been allocated internally. shinit must be called before sny drawing is done. | |
void | shgetz (int *ipix, int *jpix, float *zz) |
Reads the value in the z-buffer at a pixel. | |
void | shinit (int *r, int *g, int *b) |
Initializes the storage needed by sh and sets the current background color. | |
void | shlinc (int *r, int *g, int *b) |
Sets the current line color. | |
void | shqlinc (int *r, int *g, int *b) |
Reads the current line color. | |
void | shline (float *x0, float *y0, float *z0, float *x1, float *y1, float *z1) |
shades and renders a line. | |
void | shline2s (int *i0, int *j0, int *i1, int *j1, int *ixoff, int *iyoff) |
Draws a shadowed line segment in screen coordinates. | |
void | shlineoff (float *x0, float *y0, float *z0, float *x1, float *y1, float *z1, int *ixoff, int *iyoff, int *idoff) |
Draws a line with an offset. Currently this routine just draws a line. | |
void | shlit (int *m, float *x, float *y, float *z, int *r, int *g, int *b) |
Assigns values to a light source. | |
void | shSetLineWidth (int w) |
Sets the width (in pixels) used when lines are drawn. | |
void | shlnonrm (float *x0, float *y0, float *z0, float *n0, float *x1, float *y1, float *z1, float *n1, int *ixoff, int *iyoff, int *idoff) |
Draws a shaded line with an offset. The offset is used to determine visability, but not applied to the line when drawn. | |
void | shlss (char *name, int *lname, int *pmag, int *ifnt, int *ierr, int ln) |
Loads a character set into the table of character sets. | |
void | shmask (int *swtch) |
Turns the 3d mask on and off. | |
void | shSetOutputFilename (char *name) |
Sets the root of the output file name. | |
void | shnlit (int *n) |
Sets the number of light sources to be used. The first n are used, the rest are not deleted, just not used. | |
void | shnpln (int *n) |
Sets the number of clipping planes to use. The first n are used, the rest are not deleted, just no used. | |
void | shpause () |
On some systems the program can pause for the user to see the frame buffer. This just saves a version of the frame buffer with a number that is incremented by one each time pause is called. | |
void | shpers (float *x, float *y, float *z, float *s, float *t, float *depth) |
Performs the perspective transformation. | |
void | shunpers (float *ss, float *tt, float *dd, float *xx, float *yy, float *zz) |
Performs the inverse of the perspective transformation. | |
void | shvw (float *dist, float *alpha, float *beta, float *xmin, float *xmax, float *ymin, float *ymax, float *zmin, float *zmax) |
Sets the view point for the perspective transformation. | |
void | shqeye (float *xe, float *ye, float *ze) |
Returns the position of the eye. | |
void | shsize (float *scl, float *s0, float *t0, float *dsc, float *d0) |
Directly sets the scales used. | |
void | shpg (int *nv, float *xt, float *yt, float *zt) |
renders a polygon. | |
void | shpgc (int *r, int *g, int *b) |
Sets the color of the front face (determined by the normal) of polygons. | |
void | shpec (int *r, int *g, int *b) |
Sets the color of the front facing edges of polygons. | |
void | shbgc (int *r, int *g, int *b) |
Sets the color of the back face polygons. | |
void | shbec (int *r, int *g, int *b) |
Sets the color of the back facing edges of polygons. | |
void | shqpgc (int *r, int *g, int *b) |
Gets the color of the front face of polygons. | |
void | shqpec (int *r, int *g, int *b) |
Gets the color of the front facing edge of polygons. | |
void | shqbgc (int *r, int *g, int *b) |
Gets the color of the back face of polygons. | |
void | shqbec (int *r, int *g, int *b) |
Gets the color of the back facing edge of polygons. | |
void | shpgnrm (int *nv, float *xt, float *yt, float *zt, float *nrmt) |
Shades and z-buffers a polygon with specified normals. | |
void | shpl (int *n, float *x, float *y, float *z) |
Shades and draws a polyline. | |
void | shpln (int *i, float *ox, float *oy, float *oz, float *nx, float *ny, float *nz, int *iside) |
Sets a clipping plane. | |
void | shplnrm (int *nv, float *xt, float *yt, float *zt) |
Draws a polyline that is shaded according to the normals given by triplets of points (periodic). If any three consecutive points are colinear nothing is drawn. | |
void | shpnt (float *x, float *y, float *z) |
Draws a single point (one pixel). | |
void | shpntc (int *r, int *g, int *b) |
Sets the color used to draw points. | |
void | shqpntc (int *r, int *g, int *b) |
Reads the color used to draw points. | |
void | shputps (char *file, int *ln, int *m, int *n, unsigned char *imageR, unsigned char *imageG, unsigned char *imageB, int fln) |
writes an image to a postscript file. | |
void | shputtiff (char *file, int nrows, int ncols, unsigned char *r, unsigned char *g, unsigned char *b) |
writes an image to a tiff file (if libtiff was installed when sh was configured). | |
void | shqlit (int *m, float *x, float *y, float *z, int *r, int *g, int *b) |
Reads back a light source. | |
void | shqnpln (int *n) |
Reads back the number of clipping planes. | |
void | shrefsh () |
In some graphics systems the screen can be refreshed to allow the user to see intermediate frames. In sh this routine is a noop (does nothing). | |
void | shSetOutputResolution (int x, int y) |
Sets the size of the screen buffer, if called BEFORE shinit. Otherwise it does nothing until the next call of shinit. | |
void | shsave (char *name, int *ln, int nln) |
Saves the current frame buffer. If shOutputFormat is "postscript" a postscript file is written (duh). If shOutputFormat is "tiff" and libtiff was installed before sh was configured, a tiff file is written. | |
void | shscal (float *xmin, float *xmax, float *ymin, float *ymax, float *zmin, float *zmax) |
Sets the visible volume. | |
void | shsetp (int *ipix, int *jpix, int *ired, int *igrn, int *iblu, float *zz) |
Sets a pixel in the frame buffer if zz is less than the value in the z-buffer. If the pixel is changed the the value in the z-buffer is set to zz. | |
void | shsphere (float *xo, float *yo, float *zo, float *r) |
Draws a tesselated sphere, 8*4**4 triangles, smoothed. | |
void | shsrfp (float *a, float *d, float *s, int *n) |
Set the surface properties for shading. | |
void | shstr (float x, float y, float z, char *str) |
Draws a horizontal character string at a point. | |
void | shdoStrings (FILE *fid, float x, float y) |
Writes the code in a postscript file for the strings that have been made with shstr. | |
void | shstrs (int xx, int yy, char *str) |
Adds a horizontal character string in screen coordinates. | |
void | shsync () |
In some graphics systems this routine would wait until the physical screen buffer has been refreshed. In sh it is a noop. | |
void | shtri (float *xt1, float *yt1, float *zt1, float *xt2, float *yt2, float *zt2, float *xt3, float *yt3, float *zt3) |
A convenience routine to draw a triangle. | |
void | shtric (int *r, int *g, int *b) |
A convenience routine which sets the edge and face colors for polygons to the same color. | |
void | shSetOutputFormat (char *type) |
Sets the format of the file written by shsave. The default is "postscript", but if libtiff is installed when sh is configured, this routine can be used to change the format to "tiff". | |
void | shview (float *dist, float *alpha, float *beta, float *xmin, float *xmax, float *ymin, float *ymax, float *zmin, float *zmax) |
A convenience routine that calls shsize, shvw and shscal. |
|
Determines if a point is masked.
Definition at line 31 of file sh3dmask.c. Referenced by shlnonrm(). 00032 { 00033 int cx,cy,cz; 00034 float tx,ty,tz; 00035 int n; 00036 00037 n=5; 00038 00039 tx=(*x)*n-floor((*x)*n); 00040 ty=(*y)*n-floor((*y)*n); 00041 tz=(*z)*n-floor((*z)*n); 00042 if(tx<0)tx=tx+1.; 00043 if(ty<0)ty=ty+1.; 00044 if(tz<0)tz=tz+1.; 00045 00046 cx=fabs(tx-.5)<.4; 00047 cy=fabs(ty-.5)<.4; 00048 cz=fabs(tz-.5)<.4; 00049 00050 *imask=0; 00051 if(!cx&&fabs(nrm[0])<.9)*imask=1; 00052 if(!cy&&fabs(nrm[1])<.9)*imask=1; 00053 if(!cz&&fabs(nrm[2])<.9)*imask=1; 00054 00055 return; 00056 }
|
|
Draws a curved arrow from one point to another.
Definition at line 45 of file sharrow.c. References shlinc(), shline2s(), shpers(), and shqlinc(). 00046 { 00047 int rl,gl,bl; 00048 int orl=0; 00049 int ogl=0; 00050 int obl=0; 00051 float d,dx,dy; 00052 float s0=0.; 00053 float t0=0.; 00054 float d0=0.; 00055 float s1=0.; 00056 float t1=0.; 00057 float d1=0.; 00058 int ip; 00059 int i0,j0; 00060 int i1,j1; 00061 float dx0,dy0; 00062 float dx1,dy1; 00063 float s; 00064 int i,j,io,jo; 00065 int zero=0; 00066 int one=1; 00067 00068 shpers(x0,y0,z0,&s0,&t0,&d0); 00069 i0=floor(s0*shMax+.5); 00070 j0=floor(t0*shMax+.5); 00071 00072 shpers(x1,y1,z1,&s1,&t1,&d1); 00073 i1=floor(s1*shMax+.5); 00074 j1=floor(t1*shMax+.5); 00075 00076 shqlinc(&orl,&ogl,&obl); 00077 00078 d=1./sqrt((*idx0)*(*idx0)+(*idy0)*(*idy0)); 00079 dx0=(*idx0)*d; 00080 dy0=(*idy0)*d; 00081 d=1./sqrt((*idx1)*(*idx1)+(*idy1)*(*idy1)); 00082 dx1=(*idx1)*d; 00083 dy1=(*idy1)*d; 00084 00085 ip=3; 00086 for(s=0.;s<1.;s+=.01) 00087 { 00088 i=f0(s)*i0+f1(s)*i1+f2(s)*dx0+f3(s)*dx1; 00089 j=f0(s)*j0+f1(s)*j1+f2(s)*dy0+f3(s)*dy1; 00090 00091 if(ip==2) 00092 { 00093 shlinc(&rl,&gl,&bl); 00094 shline2s(&io,&jo,&i,&j,&one,&one); 00095 }else{ 00096 rl=orl; 00097 gl=ogl; 00098 bl=obl; 00099 shline2s(&io,&jo,&i,&j,&zero,&zero); 00100 } 00101 ip=2; 00102 io=i; 00103 jo=j; 00104 } 00105 00106 rl=0; 00107 gl=0; 00108 bl=0; 00109 io=i1; 00110 jo=j1; 00111 i=i1-(*idx1)+.3*(*idy0); 00112 j=j1-(*idy0)-.3*(*idx0); 00113 shline2s(&io,&jo,&i,&j,&one,&one); 00114 rl=orl; 00115 gl=ogl; 00116 bl=obl; 00117 shline2s(&io,&jo,&i,&j,&zero,&zero); 00118 00119 rl=0; 00120 gl=0; 00121 bl=0; 00122 i=i1-(*idx1)-.15*(*idy0); 00123 j=j1-(*idy0)+.15*(*idx0); 00124 shline2s(&io,&jo,&i,&j,&one,&one); 00125 rl=orl; 00126 gl=ogl; 00127 bl=obl; 00128 shline2s(&io,&jo,&i,&j,&zero,&zero); 00129 00130 rl=0; 00131 gl=0; 00132 bl=0; 00133 io=i1-(*idx1)-.15*(*idy0); 00134 jo=j1-(*idy0)+.15*(*idx0); 00135 i=i1-(*idx1)+.15*(*idy0); 00136 j=j1-(*idy0)-.15*(*idx0); 00137 shline2s(&io,&jo,&i,&j,&one,&one); 00138 rl=orl; 00139 gl=ogl; 00140 bl=obl; 00141 shline2s(&io,&jo,&i,&j,&zero,&zero); 00142 00143 return; 00144 }
Here is the call graph for this function: |
|
Sets the color of the back facing edges of polygons.
Definition at line 93 of file shpgc.c. Referenced by shtric(). 00094 { 00095 sh_rd[3] =*r; 00096 sh_gd[3] =*g; 00097 sh_bd[3] =*b; 00098 sh_ram[3]=*r; 00099 sh_gam[3]=*g; 00100 sh_bam[3]=*b; 00101 return; 00102 }
|
|
Sets the color of the back face polygons.
Definition at line 75 of file shpgc.c. Referenced by shtric(). 00076 { 00077 sh_rd[2] =*r; 00078 sh_gd[2] =*g; 00079 sh_bd[2] =*b; 00080 sh_ram[2]=*r; 00081 sh_gam[2]=*g; 00082 sh_bam[2]=*b; 00083 return; 00084 }
|
|
Draws a character string at a point.
Definition at line 33 of file shchar.c. References shsetp(). 00034 { 00035 00036 /* places a character string in the image */ 00037 00038 /* Make a list, with ix,iy,iz and the string */ 00039 /* At the end of the postsript file, loop */ 00040 /* over list, if iz is visible, place postscript commands to 00041 draw the string in the output file */ 00042 00043 /* places a character in the sh_image */ 00044 00045 int xref=0; 00046 int yref=0; 00047 int ipwid=0; 00048 int iphgt=0; 00049 int width=0; 00050 int ibyte; 00051 int ichr; 00052 int ifnt; 00053 int idir; 00054 int xx,yy; 00055 float zz; 00056 int zero=0; 00057 int i,j; 00058 int jx,jy; 00059 int ib; 00060 int level; 00061 00062 float conv; 00063 00064 /* conv converts from sp to pixels */ 00065 00066 conv=240./72.27/65536.; 00067 ifnt=sh_kfont[sh_cFont]; 00068 00069 /* Blank is width of lower case m (?) */ 00070 00071 ichr=chr[0]; 00072 if(chr[0]==' ')ichr='m'; 00073 00074 idir=sh_dir[ifnt]+4+ichr*16; 00075 sscanf(sh_image+idir,"%4.4d",&width); 00076 *iw=width*(sh_fmag[ifnt])*0.001*1.2*conv; 00077 00078 if(chr[0]==' ')return; 00079 00080 sscanf(sh_image+idir+ 4,"%4.4d",&xref); 00081 sscanf(sh_image+idir+ 6,"%4.4d",&yref); 00082 sscanf(sh_image+idir+ 8,"%4.4d",&ipwid); 00083 sscanf(sh_image+idir+10,"%4.4d",&iphgt); 00084 sscanf(sh_image+idir+12,"%4.4d",&ibyte); 00085 ibyte=ibyte+sh_dir[ifnt]-1; 00086 00087 jx=(*ix)-xref+.5; 00088 jy=(*iy)+yref+.5; 00089 00090 /* put shadow in frame */ 00091 00092 if(shadow_idx!=0||shadow_idy!=0) 00093 { 00094 ib=ibyte; 00095 for(j=0;j<iphgt;j++) 00096 { 00097 for(i=0;i<ipwid;i++) 00098 { 00099 level=sh_image[ib]; 00100 if(level!=0) 00101 { 00102 zz=*z-.01; 00103 xx=jx+i+shadow_idx; 00104 yy=jy-j+shadow_idy; 00105 shsetp(&xx,&yy,&zero,&zero,&zero,&zz); 00106 } 00107 ib++; 00108 } 00109 } 00110 } 00111 00112 /* put character in frame */ 00113 00114 ib=ibyte; 00115 for(j=0;j<iphgt;j++) 00116 { 00117 for(i=0;i<ipwid;i++) 00118 { 00119 level=sh_image[ib]; 00120 if(level!=0) 00121 { 00122 zz=*z-.01; 00123 xx=jx+i; 00124 yy=jy-j; 00125 shsetp(&xx,&yy,ired,igrn,iblu,&zz); 00126 } 00127 ib++; 00128 } 00129 } 00130 00131 return; 00132 }
Here is the call graph for this function: |
|
Clips a polygon against planes added with ?
Definition at line 45 of file shclippg.c. Referenced by shpgnrm(). 00046 { 00047 00048 /* clip a polygon */ 00049 00050 float *x2,*y2,*z2; 00051 float *nrm2; 00052 int *ic2; 00053 int in0,in1; 00054 int m1,m2; 00055 int i,j,ip; 00056 float direc; 00057 float t; 00058 int i0; 00059 int verbose; 00060 00061 verbose=0; 00062 00063 m2=maxpol; 00064 x2=(float*)malloc(m2*sizeof(float)); 00065 y2=(float*)malloc(m2*sizeof(float)); 00066 z2=(float*)malloc(m2*sizeof(float)); 00067 nrm2=(float*)malloc(3*m2*sizeof(float)); 00068 ic2=(int*)malloc(m2*sizeof(int)); 00069 00070 m1=(*n0)+1; 00071 if(*x1==(float*)NULL)*x1=(float*)malloc(m1*sizeof(float)); 00072 if(*y1==(float*)NULL)*y1=(float*)malloc(m1*sizeof(float)); 00073 if(*z1==(float*)NULL)*z1=(float*)malloc(m1*sizeof(float)); 00074 if(*nrm1==(float*)NULL)*nrm1=(float*)malloc(3*m1*sizeof(float)); 00075 if(*ic1==(int*)NULL)*ic1=(int*)malloc(m1*sizeof(int)); 00076 00077 /* Clipping Planes */ 00078 00079 /* NPLNS Number of clipping planes */ 00080 /* PLNO[2+3*M) point on plane M */ 00081 /* PLNN[2+3*M) normal to plane M */ 00082 /* IPLN(M) side of plane M to clip (IPLN*PLNN<0 ==> clipped) */ 00083 /* oper(M) whether clipping is ored or anded. */ 00084 00085 00086 /* copy polygon 0 into 1, removing near duplicates. */ 00087 00088 *n1=0; 00089 (*x1)[*n1]=x0[0]; 00090 (*y1)[*n1]=y0[0]; 00091 (*z1)[*n1]=z0[0]; 00092 (*nrm1)[0+3*(*n1)]=nrm0[0]; 00093 (*nrm1)[1+3*(*n1)]=nrm0[1]; 00094 (*nrm1)[2+3*(*n1)]=nrm0[2]; 00095 (*ic1)[*n1]=ic0[0]; 00096 (*n1)++; 00097 for(i=1;i<*n0;i++) 00098 { 00099 if(fabs(x0[i]-x0[i-1])+fabs(y0[i]-y0[i-1])+fabs(z0[i]-z0[i-1])>1.e-6) 00100 { 00101 (*x1)[*n1]=x0[i]; 00102 (*y1)[*n1]=y0[i]; 00103 (*z1)[*n1]=z0[i]; 00104 (*nrm1)[ 3*(*n1)]=nrm0[ 3*i]; 00105 (*nrm1)[1+3*(*n1)]=nrm0[1+3*i]; 00106 (*nrm1)[2+3*(*n1)]=nrm0[2+3*i]; 00107 (*ic1)[(*n1)]=ic0[i]; 00108 (*n1)++; 00109 } 00110 } 00111 00112 /* Duplicate first point */ 00113 00114 (*x1)[*n1]=x0[0]; 00115 (*y1)[*n1]=y0[0]; 00116 (*z1)[*n1]=z0[0]; 00117 (*nrm1)[ 3*(*n1)]=nrm0[ 3*0]; 00118 (*nrm1)[1+3*(*n1)]=nrm0[1+3*0]; 00119 (*nrm1)[2+3*(*n1)]=nrm0[2+3*0]; 00120 (*ic1)[(*n1)]=ic0[0]; 00121 (*n1)++; 00122 00123 /* Loop over the clipping planes */ 00124 00125 /* in0=this point visible, in1=next point visible */ 00126 00127 if(sh_nplns==0) 00128 { 00129 free(x2); 00130 free(y2); 00131 free(z2); 00132 free(nrm2); 00133 free(ic2); 00134 return; 00135 } 00136 00137 for(ip=0;ip<sh_nplns;ip++) 00138 { 00139 if(verbose)printf("plane %d is ((x,y,z)-(%f,%f,%f)).(%f,%f,%f)*%d>0\n",ip,sh_plno[ 3*ip],sh_plno[1+3*ip],sh_plno[2+3*ip],sh_plnn[ 3*ip],sh_plnn[1+3*ip],sh_plnn[2+3*ip],sh_ipln[ip]); 00140 in0=0; 00141 i0=0; 00142 for(i=0;i<*n1;i++) 00143 { 00144 if(verbose){printf("vertex %d(%d) (%f,%f,%f) is ",i,*n1,(*x1)[i],(*y1)[i],(*z1)[i]);fflush(stdout);} 00145 direc=sh_plnn[ 3*ip]*((*x1)[i]-sh_plno[ 3*ip])+sh_plnn[1+3*ip]*((*y1)[i]-sh_plno[1+3*ip])+sh_plnn[2+3*ip]*((*z1)[i]-sh_plno[2+3*ip]); 00146 in1=sh_ipln[ip]*direc>0; 00147 if(verbose){if(in1)printf("in\n");else printf("out\n");} 00148 if(!in0)i0=i; 00149 in0=in0||in1; 00150 } 00151 if(verbose)fflush(stdout); 00152 if(!in0) 00153 { 00154 if(verbose){printf("Polygon completely outside\n\n");fflush(stdout);} 00155 *n1=0; 00156 free(x2); 00157 free(y2); 00158 free(z2); 00159 free(nrm2); 00160 free(ic2); 00161 return; 00162 } 00163 00164 if(i0>0)i0--; 00165 00166 if(verbose){printf("Starting at vertex %d\n",i0);fflush(stdout);} 00167 #define JUNK 00168 #ifdef JUNK 00169 j=0; 00170 direc=sh_plnn[ 3*ip]*((*x1)[i0]-sh_plno[ 3*ip])+sh_plnn[1+3*ip]*((*y1)[i0]-sh_plno[1+3*ip])+sh_plnn[2+3*ip]*((*z1)[i0]-sh_plno[2+3*ip]); 00171 in0=sh_ipln[ip]*direc>0; 00172 i=i0; 00173 while(i+1<*n1) 00174 { 00175 if(verbose){printf("Vertex %d(%d) (%f,%f,%f) next is %d (%f,%f,%f)\n",i,*n1,(*x1)[i],(*y1)[i],(*z1)[i],i+1,(*x1)[i+1],(*y1)[i+1],(*z1)[i+1]);fflush(stdout);} 00176 direc=sh_plnn[ 3*ip]*((*x1)[i+1]-sh_plno[ 3*ip]) 00177 +sh_plnn[1+3*ip]*((*y1)[i+1]-sh_plno[1+3*ip]) 00178 +sh_plnn[2+3*ip]*((*z1)[i+1]-sh_plno[2+3*ip]); 00179 in1=sh_ipln[ip]*direc>0; 00180 if(verbose) 00181 { 00182 if(in0){printf(" %d is in\n",i);fflush(stdout);} 00183 if(!in0){printf(" %d is out\n",i);fflush(stdout);} 00184 if(in1){printf(" %d is in\n",i+1);fflush(stdout);} 00185 if(!in1){printf(" %d is out\n",i+1);fflush(stdout);} 00186 } 00187 if(!in0&&!in1) 00188 { 00189 if(verbose){printf(" !in0&&!in1\n");fflush(stdout);} 00190 in0=in1; 00191 i++; 00192 }else if(in0&&in1) 00193 { 00194 if(verbose){printf(" in0&&in1\n");fflush(stdout);} 00195 in0=in1; 00196 if(j+1>m2) 00197 { 00198 m2+=5; 00199 x2=(float*)realloc((void*)x2,m2*sizeof(float)); 00200 y2=(float*)realloc((void*)y2,m2*sizeof(float)); 00201 z2=(float*)realloc((void*)z2,m2*sizeof(float)); 00202 nrm2=(float*)realloc((void*)nrm2,3*m2*sizeof(float)); 00203 ic2=(int*)realloc((void*)ic2,m2*sizeof(int)); 00204 } 00205 x2[j]=(*x1)[i]; 00206 y2[j]=(*y1)[i]; 00207 z2[j]=(*z1)[i]; 00208 nrm2[ 3*j]=(*nrm1)[ 3*i]; 00209 nrm2[1+3*j]=(*nrm1)[1+3*i]; 00210 nrm2[2+3*j]=(*nrm1)[2+3*i]; 00211 ic2[j]=(*ic1)[i]; 00212 j++; 00213 00214 i++; 00215 }else if(!in0&&in1) 00216 { 00217 if(verbose){printf(" !in0&&in1\n");fflush(stdout);} 00218 t=-( sh_plnn[ 3*ip]*((*x1)[i]-sh_plno[ 3*ip]) 00219 +sh_plnn[1+3*ip]*((*y1)[i]-sh_plno[1+3*ip]) 00220 +sh_plnn[2+3*ip]*((*z1)[i]-sh_plno[2+3*ip]) ) 00221 /( sh_plnn[ 3*ip]*((*x1)[i+1]-(*x1)[i]) 00222 +sh_plnn[1+3*ip]*((*y1)[i+1]-(*y1)[i]) 00223 +sh_plnn[2+3*ip]*((*z1)[i+1]-(*z1)[i]) ); 00224 (*x1)[i]=(*x1)[i]+t*((*x1)[i+1]-(*x1)[i]); 00225 (*y1)[i]=(*y1)[i]+t*((*y1)[i+1]-(*y1)[i]); 00226 (*z1)[i]=(*z1)[i]+t*((*z1)[i+1]-(*z1)[i]); 00227 (*nrm1)[ 3*i]=(*nrm1)[ 3*i]+t*((*nrm1)[ 3*(i+1)]-(*nrm1)[ 3*i]); 00228 (*nrm1)[1+3*i]=(*nrm1)[1+3*i]+t*((*nrm1)[1+3*(i+1)]-(*nrm1)[1+3*i]); 00229 (*nrm1)[2+3*i]=(*nrm1)[2+3*i]+t*((*nrm1)[2+3*(i+1)]-(*nrm1)[2+3*i]); 00230 (*ic1)[i]=-1; 00231 if(j+1>m2) 00232 { 00233 m2+=5; 00234 x2=(float*)realloc((void*)x2,m2*sizeof(float)); 00235 y2=(float*)realloc((void*)y2,m2*sizeof(float)); 00236 z2=(float*)realloc((void*)z2,m2*sizeof(float)); 00237 nrm2=(float*)realloc((void*)nrm2,3*m2*sizeof(float)); 00238 ic2=(int*)realloc((void*)ic2,m2*sizeof(int)); 00239 } 00240 x2[j]=(*x1)[i]; 00241 y2[j]=(*y1)[i]; 00242 z2[j]=(*z1)[i]; 00243 nrm2[ 3*j]=(*nrm1)[ 3*i]; 00244 nrm2[1+3*j]=(*nrm1)[1+3*i]; 00245 nrm2[2+3*j]=(*nrm1)[2+3*i]; 00246 ic2[j]=(*ic1)[i]; 00247 j++; 00248 in0=1; 00249 i++; 00250 }else if(in0&&!in1) 00251 { 00252 if(verbose){printf(" in0&&!in1\n");fflush(stdout);} 00253 t=-( sh_plnn[ 3*ip]*((*x1)[i]-sh_plno[ 3*ip]) 00254 +sh_plnn[1+3*ip]*((*y1)[i]-sh_plno[1+3*ip]) 00255 +sh_plnn[2+3*ip]*((*z1)[i]-sh_plno[2+3*ip]) ) 00256 /( sh_plnn[ 3*ip]*((*x1)[i+1]-(*x1)[i]) 00257 +sh_plnn[1+3*ip]*((*y1)[i+1]-(*y1)[i]) 00258 +sh_plnn[2+3*ip]*((*z1)[i+1]-(*z1)[i]) ); 00259 if(j+2>m2) 00260 { 00261 m2+=5; 00262 x2=(float*)realloc((void*)x2,m2*sizeof(float)); 00263 y2=(float*)realloc((void*)y2,m2*sizeof(float)); 00264 z2=(float*)realloc((void*)z2,m2*sizeof(float)); 00265 nrm2=(float*)realloc((void*)nrm2,3*m2*sizeof(float)); 00266 ic2=(int*)realloc((void*)ic2,m2*sizeof(int)); 00267 } 00268 x2[j]=(*x1)[i]; 00269 y2[j]=(*y1)[i]; 00270 z2[j]=(*z1)[i]; 00271 nrm2[ 3*j]=(*nrm1)[ 3*i]; 00272 nrm2[1+3*j]=(*nrm1)[1+3*i]; 00273 nrm2[2+3*j]=(*nrm1)[2+3*i]; 00274 ic2[j]=(*ic1)[i]; 00275 j++; 00276 00277 (*x1)[i]=(*x1)[i]+t*((*x1)[i+1]-(*x1)[i]); 00278 (*y1)[i]=(*y1)[i]+t*((*y1)[i+1]-(*y1)[i]); 00279 (*z1)[i]=(*z1)[i]+t*((*z1)[i+1]-(*z1)[i]); 00280 (*nrm1)[ 3*i]=(*nrm1)[ 3*i]+t*((*nrm1)[ 3*(i+1)]-(*nrm1)[ 3*i]); 00281 (*nrm1)[1+3*i]=(*nrm1)[1+3*i]+t*((*nrm1)[1+3*(i+1)]-(*nrm1)[1+3*i]); 00282 (*nrm1)[2+3*i]=(*nrm1)[2+3*i]+t*((*nrm1)[2+3*(i+1)]-(*nrm1)[2+3*i]); 00283 (*ic1)[i]=1; 00284 00285 x2[j]=(*x1)[i]; 00286 y2[j]=(*y1)[i]; 00287 z2[j]=(*z1)[i]; 00288 nrm2[ 3*j]=(*nrm1)[ 3*i]; 00289 nrm2[1+3*j]=(*nrm1)[1+3*i]; 00290 nrm2[2+3*j]=(*nrm1)[2+3*i]; 00291 ic2[j]=(*ic1)[i]; 00292 j++; 00293 00294 in0=0; 00295 } 00296 } /* End of while(i+1<*n1) */ 00297 if(verbose){printf("done plane %d, Caught %d vertices\n",ip,j);fflush(stdout);} 00298 00299 /* Copy back from 2 into 1 */ 00300 00301 if(j+1>m1) 00302 { 00303 m1=j+3; 00304 *x1=(float*)realloc((void*)(*x1),m1*sizeof(float)); 00305 *y1=(float*)realloc((void*)(*y1),m1*sizeof(float)); 00306 *z1=(float*)realloc((void*)(*z1),m1*sizeof(float)); 00307 *nrm1=(float*)realloc((void*)(*nrm1),3*m1*sizeof(float)); 00308 *ic1=(int*)realloc((void*)(*ic1),m1*sizeof(int)); 00309 } 00310 00311 for(i=0;i<j;i++) 00312 { 00313 (*x1)[i]=x2[i]; 00314 (*y1)[i]=y2[i]; 00315 (*z1)[i]=z2[i]; 00316 (*nrm1)[ 3*i]=nrm2[ 3*i]; 00317 (*nrm1)[1+3*i]=nrm2[1+3*i]; 00318 (*nrm1)[2+3*i]=nrm2[2+3*i]; 00319 (*ic1)[i]=ic2[i]; 00320 } 00321 (*x1)[j]=x2[0]; 00322 (*y1)[j]=y2[0]; 00323 (*z1)[j]=z2[0]; 00324 (*nrm1)[ 3*j]=nrm2[ 3*0]; 00325 (*nrm1)[1+3*j]=nrm2[1+3*0]; 00326 (*nrm1)[2+3*j]=nrm2[2+3*0]; 00327 (*ic1)[j]=ic2[0]; 00328 (*n1)=j+1; 00329 #endif 00330 } /* End of for(ip=0;ip<sh_nplns;ip++) */ 00331 00332 if(verbose){printf("Part of Polygon remains unclipped, %d vertices\n\n",j);fflush(stdout);} 00333 00334 free(x2); 00335 free(y2); 00336 free(z2); 00337 free(nrm2); 00338 free(ic2); 00339 00340 return; 00341 }
|
|
Shades and renders a point.
Definition at line 39 of file shcolor.c. Referenced by shlnonrm(). 00040 { 00041 00042 /* Shade and render a point. */ 00043 00044 int rd[2]={0,0}; 00045 int gd[2]={0,0}; 00046 int bd[2]={0,0}; 00047 00048 /* Geometric Information */ 00049 00050 /* EYE[2] position of the viewer */ 00051 /* NLIT number of light sources */ 00052 /* LIT(3,M) position of light source m */ 00053 /* RS(M) color of light source m */ 00054 /* GS(M) */ 00055 /* BS(M) */ 00056 /* AM intensity of ambient illumination */ 00057 /* AD intensity of diffuse illumination */ 00058 /* AS intensity of specular illumination */ 00059 /* ND exponent of specular illumination */ 00060 00061 /* Clipping Planes */ 00062 00063 /* NPLNS Number of clipping planes */ 00064 /* PLNO(3,M) point on plane M */ 00065 /* PLNN(3,M) normal to plane M */ 00066 /* IPLN(M) side of plane M to clip (IPLN*PLNN<0 ==> clipped) */ 00067 /* oper(M) whether clipping is ored or anded. */ 00068 00069 float e[3]={0.,0.,0.}; 00070 float l[3]={0.,0.,0.}; 00071 float h[3]={0.,0.,0.}; 00072 00073 float an; 00074 float ah; 00075 float ae; 00076 float sd; 00077 float ssr; 00078 float ssg; 00079 float ssb; 00080 int k; 00081 float xxx=0.; 00082 float yyy=0.; 00083 float zzz=0.; 00084 float al; 00085 int icol; 00086 00087 an=sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); 00088 if(an<1.e-7) 00089 { 00090 *r=*rf; 00091 *g=*gf; 00092 *b=*bf; 00093 return; 00094 } 00095 00096 /* e is the vector from the pixel to the eye */ 00097 00098 e[0]=shv_eye[0]-*x; 00099 e[1]=shv_eye[1]-*y; 00100 e[2]=shv_eye[2]-*z; 00101 ae=1./sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]); 00102 e[0]=e[0]*ae; 00103 e[1]=e[1]*ae; 00104 e[2]=e[2]*ae; 00105 00106 sd =0.; 00107 ssr=0.; 00108 ssg=0.; 00109 ssb=0.; 00110 for(k=0;k<sh_nlit;k++) 00111 { 00112 00113 /* l is the vector from the pixel to light source k */ 00114 00115 if(sh_type[k]==0) 00116 { 00117 l[0]=sh_lit[ 3*k]-xxx; 00118 l[1]=sh_lit[1+3*k]-yyy; 00119 l[2]=sh_lit[2+3*k]-zzz; 00120 }else{ 00121 l[0]=sh_lit[ 3*k]; 00122 l[1]=sh_lit[1+3*k]; 00123 l[2]=sh_lit[2+3*k]; 00124 } 00125 al=1./sqrt(l[0]*l[0]+l[1]*l[1]+l[2]*l[2]); 00126 l[0]=l[0]*al; 00127 l[1]=l[1]*al; 00128 l[2]=l[2]*al; 00129 /* printf("light %d, l=(%f,%f,%f) n=(%f,%f,%f\n",k,l[0],l[1],l[2],n[0],n[1],n[2]);*/ 00130 00131 /* h will control the specular reflection */ 00132 00133 h[0]=e[0]+l[0]; 00134 h[1]=e[1]+l[1]; 00135 h[2]=e[2]+l[2]; 00136 ah=1./sqrt(h[0]*h[0]+h[1]*h[1]+h[2]*h[2]); 00137 h[0]=h[0]*ah; 00138 h[1]=h[1]*ah; 00139 h[2]=h[2]*ah; 00140 /* printf("h=(%f,%f,%f)\n",h[0],h[1],h[2]);*/ 00141 00142 /* printf("sd=%f sscol=(%f,%f,%f)\n",fabs(n[0]*l[0]+n[1]*l[1]+n[2]*l[2]),sh_rs[k]*pow(fabs(n[0]*h[0]+n[1]*h[1]+n[2]*h[2]),sh_nd),sh_gs[k]*pow(fabs(n[0]*h[0]+n[1]*h[1]+n[2]*h[2]),sh_nd),sh_bs[k]*pow(fabs(n[0]*h[0]+n[1]*h[1]+n[2]*h[2]),sh_nd));*/ 00143 00144 sd =sd +fabs(n[0]*l[0]+n[1]*l[1]+n[2]*l[2]); 00145 ssr=ssr+sh_rs[k]*pow(fabs(n[0]*h[0]+n[1]*h[1]+n[2]*h[2]),sh_nd); 00146 ssg=ssg+sh_gs[k]*pow(fabs(n[0]*h[0]+n[1]*h[1]+n[2]*h[2]),sh_nd); 00147 ssb=ssb+sh_bs[k]*pow(fabs(n[0]*h[0]+n[1]*h[1]+n[2]*h[2]),sh_nd); 00148 } 00149 /*printf("total sd=%f sscol=(%f,%f,%f)\n",sd,ssr,ssg,ssb);*/ 00150 00151 icol=0; 00152 if(n[0]*(shv_eye[0]-*x)+n[1]*(shv_eye[1]-*y)+n[2]*(shv_eye[2]-*z)<0.)icol=1; 00153 /*printf("side %d\n",icol);*/ 00154 00155 rd[0]=*rf; 00156 gd[0]=*gf; 00157 bd[0]=*bf; 00158 rd[1]=*rb; 00159 gd[1]=*gb; 00160 bd[1]=*bb; 00161 00162 *r=sh_am*rd[icol]+sh_ad*rd[icol]*sd/sh_nlit+sh_as*ssr/sh_nlit; 00163 *g=sh_am*gd[icol]+sh_ad*gd[icol]*sd/sh_nlit+sh_as*ssg/sh_nlit; 00164 *b=sh_am*bd[icol]+sh_ad*bd[icol]*sd/sh_nlit+sh_as*ssb/sh_nlit; 00165 00166 if(*r>255)*r=255; 00167 if(*g>255)*g=255; 00168 if(*b>255)*b=255; 00169 if(*r<0)*r=0; 00170 if(*g<0)*g=0; 00171 if(*b<0)*b=0; 00172 00173 return; 00174 }
|
|
Sets the current font and shadow offset for characters.
Definition at line 28 of file shcs.c. 00029 { 00030 sh_cFont=*ifnt; 00031 shadow_idx=*isx; 00032 shadow_idy=*isy; 00033 00034 return; 00035 }
|
|
Draw a wireframe cube.
Definition at line 31 of file shcube.c. References shline(). 00032 { 00033 00034 /* Draw a wireframe cube. */ 00035 00036 shline(xmin,ymin,zmin,xmax,ymin,zmin); 00037 shline(xmax,ymin,zmin,xmax,ymin,zmax); 00038 shline(xmax,ymin,zmax,xmin,ymin,zmax); 00039 shline(xmin,ymin,zmax,xmin,ymin,zmin); 00040 00041 shline(xmin,ymax,zmin,xmax,ymax,zmin); 00042 shline(xmax,ymax,zmin,xmax,ymax,zmax); 00043 shline(xmax,ymax,zmax,xmin,ymax,zmax); 00044 00045 shline(xmin,ymax,zmax,xmin,ymax,zmin); 00046 00047 shline(xmin,ymin,zmin,xmin,ymax,zmin); 00048 shline(xmin,ymin,zmax,xmin,ymax,zmax); 00049 00050 shline(xmax,ymin,zmin,xmax,ymax,zmin); 00051 00052 shline(xmax,ymin,zmax,xmax,ymax,zmax); 00053 00054 return; 00055 }
Here is the call graph for this function: |
|
Shades and z-buffers a polygon.
Definition at line 63 of file shdopg.c. Referenced by shpgnrm(). 00064 { 00065 00066 /* shade and z-buffer a polygon defined by the vertices xt,yt,zt. */ 00067 /* with specified normal */ 00068 00069 float nn[3]={1.,0.,0.}; 00070 float t; 00071 float de0,de1; 00072 00073 float xx,yy,zz; 00074 float xxx=0.; 00075 float yyy=0.; 00076 float zzz=0.; 00077 float zbuf=0.; 00078 00079 int r=0; 00080 int g=0; 00081 int b=0; 00082 int nv,imax,jmax,imin,jmin; 00083 int m,mi,mj; 00084 int mleft,mright; 00085 int kt; 00086 int nedges; 00087 float an; 00088 int imask=0; 00089 int ipix,jpix; 00090 00091 /* Project the vertices into Perspective coordinates */ 00092 /* Transform into raster coordinates */ 00093 /* SHk0[m] points to one point of each edge, */ 00094 /* SHk1[m] points to the other */ 00095 00096 #ifdef VERBOSE 00097 printf(" shdopg n=%d\n",*nt); 00098 for(m=0;m<*nt;m++) 00099 { 00100 printf(" %d (%f,%f,%f) (%f,%f,%f)\n",m,xt[m],yt[m],zt[m],n[3*m],n[1+3*m],n[2+3*m]); 00101 fflush(stdout); 00102 } 00103 #endif 00104 00105 if(*nt>SHmaxpol) 00106 { 00107 SHmaxpol+=1000; 00108 SHx=(float*)realloc((void*)SHx,SHmaxpol*sizeof(float)); 00109 if(SHx==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00110 SHy=(float*)realloc((void*)SHy,SHmaxpol*sizeof(float)); 00111 if(SHy==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00112 SHz=(float*)realloc((void*)SHz,SHmaxpol*sizeof(float)); 00113 if(SHz==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00114 SHi=(int*)realloc((void*)SHi,SHmaxpol*sizeof(int)); 00115 if(SHi==(int*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00116 SHj=(int*)realloc((void*)SHj,SHmaxpol*sizeof(int)); 00117 if(SHj==(int*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00118 SHk0=(int*)realloc((void*)SHk0,SHmaxpol*sizeof(int)); 00119 if(SHk0==(int*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00120 SHk1=(int*)realloc((void*)SHk1,SHmaxpol*sizeof(int)); 00121 if(SHk1==(int*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00122 SHke=(int*)realloc((void*)SHke,SHmaxpol*sizeof(int)); 00123 if(SHke==(int*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00124 SHo=(float*)realloc((void*)SHo,SHmaxpol*sizeof(float)); 00125 if(SHo==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00126 SHs=(float*)realloc((void*)SHs,SHmaxpol*sizeof(float)); 00127 if(SHs==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00128 SHxo=(float*)realloc((void*)SHxo,SHmaxpol*sizeof(float)); 00129 if(SHxo==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00130 SHyo=(float*)realloc((void*)SHyo,SHmaxpol*sizeof(float)); 00131 if(SHyo==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00132 SHzo=(float*)realloc((void*)SHzo,SHmaxpol*sizeof(float)); 00133 if(SHzo==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00134 SHno=(float*)realloc((void*)SHno,(2+3*SHmaxpol)*sizeof(float)); 00135 if(SHno==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00136 SHxs=(float*)realloc((void*)SHxs,SHmaxpol*sizeof(float)); 00137 if(SHxs==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00138 SHys=(float*)realloc((void*)SHys,SHmaxpol*sizeof(float)); 00139 if(SHys==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00140 SHzs=(float*)realloc((void*)SHzs,SHmaxpol*sizeof(float)); 00141 if(SHzs==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00142 SHns=(float*)realloc((void*)SHns,(2+3*SHmaxpol)*sizeof(float)); 00143 if(SHns==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00144 SHi0=(int*)realloc((void*)SHi0,SHmaxpol*sizeof(int)); 00145 if(SHi0==(int*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00146 SHx0=(float*)realloc((void*)SHx0,SHmaxpol*sizeof(float)); 00147 if(SHx0==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00148 SHy0=(float*)realloc((void*)SHy0,SHmaxpol*sizeof(float)); 00149 if(SHy0==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00150 SHz0=(float*)realloc((void*)SHz0,SHmaxpol*sizeof(float)); 00151 if(SHz0==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00152 SHn0=(float*)realloc((void*)SHn0,(2+3*SHmaxpol)*sizeof(float)); 00153 if(SHn0==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00154 SHs0=(float*)realloc((void*)SHs0,SHmaxpol*sizeof(float)); 00155 if(SHs0==(float*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00156 SHiflg=(int*)realloc((void*)SHiflg,SHmaxpol*sizeof(int)); 00157 if(SHiflg==(int*)NULL){fprintf(stderr,"shdopg: out of memory!");fflush(stderr);return;} 00158 } 00159 00160 nv=*nt; 00161 if(fabs(xt[0]-xt[nv-1])+fabs(yt[0]-yt[nv-1])+fabs(zt[0]-zt[nv-1])<3.e-7)nv--; 00162 00163 imax=0; 00164 jmax=0; 00165 imin=shIMax; 00166 jmin=shJMax; 00167 for(m=0;m<nv;m++) 00168 { 00169 shpers(xt+m,yt+m,zt+m,SHx+m,SHy+m,SHz+m); 00170 SHi[m]=SHx[m]*shMax+.5; 00171 SHj[m]=SHy[m]*shMax+.5; 00172 SHk0[m]=m; 00173 SHk1[m]=m+1; 00174 if(m==nv-1)SHk1[m]=0; 00175 if(SHi[m]>imax)imax=SHi[m]; 00176 if(SHj[m]>jmax)jmax=SHj[m]; 00177 if(SHi[m]<imin)imin=SHi[m]; 00178 if(SHj[m]<jmin)jmin=SHj[m]; 00179 } 00180 00181 #ifdef VERBOSE 00182 printf(" shdopg n=%d\n",nv); 00183 for(m=0;m<nv;m++) 00184 { 00185 printf(" %d (%d,%d)\n",m,SHi[m],SHj[m]); 00186 fflush(stdout); 00187 } 00188 #endif 00189 00190 /* Quick clip if polygon is not in image */ 00191 00192 if((imax<0||imin>=shIMax||jmax<0||jmin>=shJMax)) 00193 { 00194 #ifdef VERBOSE 00195 printf(" done shdopg -- polygon out of range (%d,%d)->(%d,%d), (0,0)->(%d,%d)\n",imin,jmin,imax,jmax,shIMax,shJMax); 00196 #endif 00197 return; 00198 } 00199 00200 if(jmax==jmin||nv<3) 00201 { 00202 shpl(&nv,xt,yt,zt); 00203 #ifdef VERBOSE 00204 printf(" done shdopg -- too few vertices, or horiSHzontal line, nv=%d, j in (%d,%d)\n",nv,jmin,jmax); 00205 #endif 00206 return; 00207 } 00208 00209 /* flip edges so that SHy[SHk0[m]]<SHy[SHk1[m]] */ 00210 00211 for(m=0;m<nv;m++) 00212 { 00213 if(SHj[SHk0[m]]>SHj[SHk1[m]]) 00214 { 00215 kt=SHk0[m]; 00216 SHk0[m]=SHk1[m]; 00217 SHk1[m]=kt; 00218 } 00219 } 00220 00221 /* sort edges by increasing SHy[SHk0[m]] */ 00222 00223 for(mi=0;mi<nv-1;mi++) 00224 { 00225 for(mj=mi+1;mj<nv;mj++) 00226 { 00227 if(SHj[SHk0[mj]]<SHj[SHk0[mi]]) 00228 { 00229 kt=SHk0[mi]; 00230 SHk0[mi]=SHk0[mj]; 00231 SHk0[mj]=kt; 00232 kt=SHk1[mi]; 00233 SHk1[mi]=SHk1[mj]; 00234 SHk1[mj]=kt; 00235 } 00236 } 00237 } 00238 00239 #ifdef VERBOSE 00240 printf(" shdopg edges\n"); 00241 for(m=0;m<nv;m++) 00242 { 00243 printf(" %d (%d,%d) (%f,%f,%f)->(%f,%f,%f)\n",m,SHk0[m],SHk1[m],SHx[SHk0[m]],SHy[SHk0[m]],SHz[SHk0[m]],SHx[SHk1[m]],SHy[SHk1[m]],SHz[SHk1[m]]); 00244 fflush(stdout); 00245 } 00246 #endif 00247 00248 /* Normalize the normal vector at each vertex */ 00249 00250 for(m=0;m<nv;m++) 00251 { 00252 an=sqrt(n[3*m]*n[3*m]+n[1+3*m]*n[1+3*m]+n[2+3*m]*n[2+3*m]); 00253 if(fabs(an)<1.e-6) 00254 { 00255 shpl(&nv,xt,yt,zt); 00256 #ifdef VERBOSE 00257 printf(" done shdopg -- flat line m=%d, n=(%f,%f,%f), |n|=%f\n",m,n[3*m],n[1+3*m],n[2+3*m],an); 00258 #endif 00259 return; 00260 }else{ 00261 an=1./an; 00262 n[3*m]=n[3*m]*an; 00263 n[1+3*m]=n[1+3*m]*an; 00264 n[2+3*m]=n[2+3*m]*an; 00265 } 00266 00267 /* Compute the equations of the edges of the polygon */ 00268 00269 00270 /* (x,y,z)=(SHxo[m],SHyo[m],SHzo[m])+j*(SHxs[m],SHys[m],SHzs[m]) */ 00271 00272 if(SHj[SHk1[m]]==SHj[SHk0[m]]) 00273 { 00274 SHs[m]=0.; 00275 SHxs[m]=0.; 00276 SHys[m]=0.; 00277 SHzs[m]=0.; 00278 SHns[3*m]=0; 00279 SHns[1+3*m]=0; 00280 SHns[2+3*m]=0; 00281 }else{ 00282 t=1./(float)(SHj[SHk1[m]]-SHj[SHk0[m]]); 00283 SHs[m]= (SHi[SHk1[m]]-SHi[SHk0[m]])*t; 00284 SHxs[m]= (SHx[SHk1[m]]-SHx[SHk0[m]])*t; 00285 SHys[m]= (SHy[SHk1[m]]-SHy[SHk0[m]])*t; 00286 SHzs[m]= (SHz[SHk1[m]]-SHz[SHk0[m]])*t; 00287 SHns[3*m]= (n[ 3*SHk1[m]]-n[ 3*SHk0[m]])*t; 00288 SHns[1+3*m]=(n[1+3*SHk1[m]]-n[1+3*SHk0[m]])*t; 00289 SHns[2+3*m]=(n[2+3*SHk1[m]]-n[2+3*SHk0[m]])*t; 00290 } 00291 SHo[m]= SHi[SHk0[m]]-SHj[SHk0[m]]*SHs[m]; 00292 SHxo[m]= SHx[SHk0[m]]-SHj[SHk0[m]]*SHxs[m]; 00293 SHyo[m]= SHy[SHk0[m]]-SHj[SHk0[m]]*SHys[m]; 00294 SHzo[m]= SHz[SHk0[m]]-SHj[SHk0[m]]*SHzs[m]; 00295 SHno[3*m]= n[ 3*SHk0[m]]-SHj[SHk0[m]]*SHns[3*m]; 00296 SHno[1+3*m]=n[1+3*SHk0[m]]-SHj[SHk0[m]]*SHns[1+3*m]; 00297 SHno[2+3*m]=n[2+3*SHk0[m]]-SHj[SHk0[m]]*SHns[2+3*m]; 00298 } 00299 00300 #ifdef VERBOSE 00301 printf(" shdopg equations\n"); 00302 for(m=0;m<nv;m++) 00303 { 00304 printf(" %4.4d s %f, SHxs (%f,%f,%f), SHns (%f,%f,%f)\n",m,SHs[m],SHxs[m],SHys[m],SHzs[m],SHns[3*m],SHns[1+3*m],SHns[2+3*m]); 00305 printf(" o %f, SHxo (%f,%f,%f), SHno (%f,%f,%f)\n",SHo[m],SHxo[m],SHyo[m],SHzo[m],SHno[3*m],SHno[1+3*m],SHno[2+3*m]); 00306 fflush(stdout); 00307 } 00308 #endif 00309 00310 /* Now fill the polygon, bottom to top */ 00311 00312 for(jpix=jmin;jpix<=jmax;jpix++) 00313 { 00314 00315 /* Find the range of edges in k which cross this value of jpix */ 00316 00317 mleft=0; 00318 mright=nv-1; 00319 for(m=0;m<nv;m++) 00320 { 00321 if(SHj[SHk1[mleft]]<jpix)mleft++; 00322 if(SHj[SHk0[mright]]>jpix)mright--; 00323 } 00324 00325 /* Compute the intersection points on each edge */ 00326 00327 #ifdef VERBOSE 00328 printf("scan line %d, left %d, right %d\n",jpix,mleft,mright); 00329 fflush(stdout); 00330 #endif 00331 00332 nedges=0; 00333 for(m=mleft;m<=mright;m++) 00334 { 00335 if(SHj[SHk1[m]]>=jpix) 00336 { 00337 if(SHj[SHk1[m]]==jpix&&SHj[SHk0[m]]==jpix) 00338 { 00339 SHi0[nedges]= SHi[SHk0[m]]; 00340 SHiflg[nedges]=3; 00341 SHs0[nedges]=fabs( SHi[SHk1[m]] - SHi[SHk0[m]] )+.5; 00342 SHx0[nedges]=SHx[SHk0[m]]; 00343 SHy0[nedges]=SHy[SHk0[m]]; 00344 SHz0[nedges]=SHz[SHk0[m]]; 00345 SHn0[3*nedges]=n[3*SHk0[m]]; 00346 SHn0[1+3*nedges]=n[1+3*SHk0[m]]; 00347 SHn0[2+3*nedges]=n[2+3*SHk0[m]]; 00348 SHke[nedges]=nedges; 00349 nedges++; 00350 00351 SHi0[nedges]= SHi[SHk1[m]]; 00352 SHiflg[nedges]=3; 00353 SHs0[nedges]=fabs( SHi[SHk1[m]] - SHi[SHk0[m]] )+.5; 00354 SHx0[nedges]=SHx[SHk1[m]]; 00355 SHy0[nedges]=SHy[SHk1[m]]; 00356 SHz0[nedges]=SHz[SHk1[m]]; 00357 SHn0[3*nedges]=n[3*SHk1[m]]; 00358 SHn0[1+3*nedges]=n[1+3*SHk1[m]]; 00359 SHn0[2+3*nedges]=n[2+3*SHk1[m]]; 00360 SHke[nedges]=nedges; 00361 nedges++; 00362 }else{ 00363 SHiflg[nedges]=0; 00364 if(SHj[SHk1[m]]==jpix)SHiflg[nedges]=1; 00365 if(SHj[SHk0[m]]==jpix)SHiflg[nedges]=2; 00366 if(SHo[m]+jpix*SHs[m]>=0.) 00367 SHi0[nedges]= SHo[m]+jpix* SHs[m]+.5; 00368 else 00369 SHi0[nedges]= SHo[m]+jpix* SHs[m]-.5; 00370 if(SHj[SHk1[m]]==SHj[SHk0[m]]) 00371 { 00372 fprintf(stderr," divide by zero in shpgnrm, SHj[%d]=SHj[%d]=%d, jpix=%d\n",SHk1[m],SHk0[m],SHj[SHk0[m]],jpix); 00373 abort(); 00374 } 00375 SHs0[nedges]=fabs((SHi[SHk1[m]]-SHi[SHk0[m]])/(float)(SHj[SHk1[m]]-SHj[SHk0[m]])); 00376 SHx0[nedges]=SHxo[m]+jpix*SHxs[m]; 00377 SHy0[nedges]=SHyo[m]+jpix*SHys[m]; 00378 SHz0[nedges]=SHzo[m]+jpix*SHzs[m]; 00379 SHn0[3*nedges]=SHno[3*m]+jpix*SHns[3*m]; 00380 SHn0[1+3*nedges]=SHno[1+3*m]+jpix*SHns[1+3*m]; 00381 SHn0[2+3*nedges]=SHno[2+3*m]+jpix*SHns[2+3*m]; 00382 SHke[nedges]=nedges; 00383 nedges++; 00384 } 00385 } 00386 } 00387 00388 /* Sort SHke by increasing SHi0 (intersection points left to right.) */ 00389 00390 for(mi=0;mi<nedges;mi++) 00391 { 00392 for(mj=mi+1;mj<nedges;mj++) 00393 { 00394 if(SHi0[SHke[mj]]<SHi0[SHke[mi]]) 00395 { 00396 kt=SHke[mi]; 00397 SHke[mi]=SHke[mj]; 00398 SHke[mj]=kt; 00399 } 00400 if(SHi0[SHke[mj]]==SHi0[SHke[mi]]&&SHiflg[SHke[mj]]<SHiflg[SHke[mi]]) 00401 { 00402 kt=SHke[mi]; 00403 SHke[mi]=SHke[mj]; 00404 SHke[mj]=kt; 00405 } 00406 } 00407 } 00408 00409 /* Remove duplicates */ 00410 00411 mi=0; 00412 while(mi<nedges-1) 00413 { 00414 if(SHi0[SHke[mi]]==SHi0[SHke[mi+1]]&&SHiflg[SHke[mi]]!=0&&SHiflg[SHke[mi+1]]!=0&&SHiflg[SHke[mi]]!=SHiflg[SHke[mi+1]]) 00415 { 00416 if(SHs0[SHke[mi+1]]>SHs0[SHke[mi]])SHs0[SHke[mi]]=SHs0[SHke[mi+1]]; 00417 SHs0[SHke[mi+1]]=SHs0[SHke[mi]]; 00418 for(mj=mi+1;mj<nedges;mj++)SHke[mj]=SHke[mj+1]; 00419 nedges--; 00420 }else{ 00421 mi++; 00422 } 00423 } 00424 00425 /* Fill the Slabs */ 00426 00427 for(m=0;m<nedges;m+=2) 00428 { 00429 de0=.5+SHs0[SHke[m]]; 00430 de1=.5+SHs0[SHke[m+1]]; 00431 for(ipix=SHi0[SHke[m]];ipix<=SHi0[SHke[m+1]];ipix++) 00432 { 00433 if(ipix>-1&&ipix<shIMax&&jpix>-1&&jpix<shJMax) 00434 { 00435 00436 /* Compute perspective coordinates of the pixel being filled (xx,yy,zz) */ 00437 00438 if(SHi0[SHke[m]]==SHi0[SHke[m+1]]) 00439 { 00440 xx=SHx0[SHke[m]]; 00441 yy=SHy0[SHke[m]]; 00442 zz=SHz0[SHke[m]]; 00443 nn[0]=SHn0[3*SHke[m]]; 00444 nn[1]=SHn0[1+3*SHke[m]]; 00445 nn[2]=SHn0[2+3*SHke[m]]; 00446 }else{ 00447 t=(float)(ipix-SHi0[SHke[m]])/(float)(SHi0[SHke[m+1]]-SHi0[SHke[m]]); 00448 xx=SHx0[SHke[m]]+t*(SHx0[SHke[m+1]]-SHx0[SHke[m]]); 00449 yy=SHy0[SHke[m]]+t*(SHy0[SHke[m+1]]-SHy0[SHke[m]]); 00450 zz=SHz0[SHke[m]]+t*(SHz0[SHke[m+1]]-SHz0[SHke[m]]); 00451 nn[0]=SHn0[3*SHke[m]]+t*(SHn0[3*SHke[m+1]]-SHn0[3*SHke[m]]); 00452 nn[1]=SHn0[1+3*SHke[m]]+t*(SHn0[1+3*SHke[m+1]]-SHn0[1+3*SHke[m]]); 00453 nn[2]=SHn0[2+3*SHke[m]]+t*(SHn0[2+3*SHke[m+1]]-SHn0[2+3*SHke[m]]); 00454 } 00455 an=sqrt(nn[0]*nn[0]+nn[1]*nn[1]+nn[2]*nn[2]); 00456 if(fabs(an)<1.e-7) 00457 { 00458 nn[0]=SHn0[3*SHke[m]]; 00459 nn[1]=SHn0[1+3*SHke[m]]; 00460 nn[2]=SHn0[2+3*SHke[m]]; 00461 an=sqrt(nn[0]*nn[0]+nn[1]*nn[1]+nn[2]*nn[2]); 00462 nn[0]=nn[0]*an; 00463 nn[1]=nn[1]*an; 00464 nn[2]=nn[2]*an; 00465 }else{ 00466 an=1./an; 00467 nn[0]=nn[0]*an; 00468 nn[1]=nn[1]*an; 00469 nn[2]=nn[2]*an; 00470 } 00471 00472 shunpers(&xx,&yy,&zz,&xxx,&yyy,&zzz); 00473 00474 /* Check against the Z-buffer */ 00475 00476 shgetz(&ipix,&jpix,&zbuf); 00477 #ifdef VERBOSE 00478 printf("shgetz %d,%d %f %f\n",ipix,jpix,zbuf,zz);fflush(stdout); 00479 #endif 00480 if(zbuf>zz) 00481 { 00482 00483 /* If pixel is visible, shade it and put it in the image */ 00484 00485 shcolor(&xxx,&yyy,&zzz,nn,&(sh_rd[0]),&(sh_gd[0]),&(sh_bd[0]),&(sh_rd[2]),&(sh_gd[2]),&(sh_bd[2]),&r,&g,&b); 00486 #ifdef VERBOSE 00487 printf("shcolor, x-( %f %f %f ) n-( %f %f %f ) fc-(%d %d %d ) bc-(%d %d %d) c %d %d %d\n",xxx,yyy,zzz,nn[0],nn[1],nn[2],sh_rd[0],sh_gd[0],sh_bd[0],sh_rd[2],sh_gd[2],sh_bd[2],r,g,b); 00488 #endif 00489 00490 if(shMask) 00491 { 00492 sh3dmask(&xxx,&yyy,&zzz,nn,&imask); 00493 if(imask==1)shsetp(&ipix,&jpix,&r,&g,&b,&zz); 00494 }else{ 00495 shsetp(&ipix,&jpix,&r,&g,&b,&zz); 00496 } 00497 } 00498 } 00499 } 00500 } 00501 } 00502 00503 #ifdef VERBOSE 00504 printf(" done shdopg -- normal end\n"); 00505 #endif 00506 return; 00507 }
|
|
Writes the code in a postscript file for the strings that have been made with shstr.
Definition at line 69 of file shstr.c. 00070 { 00071 int i; 00072 int ix,iy; 00073 00074 fprintf(fid,"initclip\n"); 00075 fprintf(fid,"/Helvetica findfont %f scalefont setfont\n",20.*shIMax/1024); 00076 fprintf(fid,"0. setgray\n"); 00077 for(i=0;i<SHnstr;i++) 00078 { 00079 ix=SHxstr[i]/x; 00080 iy=SHystr[i]/y; 00081 fflush(stdout); 00082 if((SHstr[i])[0]!='/') 00083 fprintf(fid,"%d %d moveto (%s) show\n",ix,iy,SHstr[i]); 00084 else 00085 fprintf(fid,"%s\n",SHstr[i]); 00086 } 00087 return; 00088 }
|
|
A pen-up/pen-down style line drawing.
Definition at line 29 of file shdraw.c. References shline(). 00030 { 00031 00032 /* Calcomp type interface for line drawing routine. */ 00033 00034 if(*ip==2) 00035 shline(&sh_x0,&sh_y0,&sh_z0,x,y,z); 00036 sh_x0=*x; 00037 sh_y0=*y; 00038 sh_z0=*z; 00039 return; 00040 }
Here is the call graph for this function: |
|
Reads the value in the z-buffer at a pixel.
Definition at line 28 of file shgetz.c. Referenced by shlnonrm(). 00029 { 00030 int index; 00031 00032 /* Return the z-buffer. */ 00033 00034 *zz=0.; 00035 if(*ipix<0||*jpix<0)return; 00036 if(*ipix>=shIMax||*jpix>=shJMax)return; 00037 00038 index=(*ipix)+shIMax*(*jpix); 00039 00040 *zz=shZBuffer[index]; 00041 return; 00042 }
|
|
Initializes the storage needed by sh and sets the current background color.
Definition at line 28 of file shinit.c. References shlinc(), shlit(), shmask(), shnlit(), shnpln(), shpntc(), shsetp(), shsrfp(), shtric(), and shview(). 00029 { 00030 int i,j; 00031 int full=255; 00032 int zero=0; 00033 float am; 00034 float ad; 00035 float as; 00036 int ae; 00037 float dist,alpha,beta,xmin,xmax; 00038 float ftwo=2.; 00039 int one=1; 00040 int two=2; 00041 float xp,yp,zp; 00042 /* 00043 Initialization Routine. 00044 r,g,b Background Color, integer 0-&full. 00045 00046 This routine fills the image buffer iax with the 00047 supplied color. 00048 Then sets the z-buffer to be infinitly far. (z is scaled from 00049 zero to 1., so it is set to 2.) 00050 00051 Two light sources are defined. 00052 No clipping planes. 00053 Default color is white (&full,&full,&full) 00054 Default view is looking down the x-axis, distance=10. 00055 box=(0.,1.)**3 00056 */ 00057 00058 dist=10.; 00059 alpha=0.; 00060 beta=0.; 00061 xmin=0.; 00062 xmax=1.; 00063 shview(&dist,&alpha,&beta,&xmin,&xmax,&xmin,&xmax,&xmin,&xmax); 00064 00065 shnlit(&two); 00066 xp=.3; 00067 yp=.3; 00068 zp=.5; 00069 shlit(&one,&xp,&yp,&zp,&full,&full,&full); 00070 xp=.7; 00071 yp=.3; 00072 zp=-1.; 00073 shlit(&two,&xp,&yp,&zp,&full,&full,&full); 00074 00075 shnpln(&zero); 00076 shmask(&zero); 00077 00078 shRedBackground=*r; 00079 shGreenBackground=*g; 00080 shBlueBackground=*b; 00081 00082 shtric(&full,&full,&full); 00083 shlinc(&full,&full,&full); 00084 shpntc(&full,&full,&full); 00085 00086 /* shsrfp(.3,.7,.5,5)*/ 00087 am=.3; 00088 ad=.9; 00089 as=.3; 00090 ae=5; 00091 shsrfp(&am,&ad,&as,&ae); 00092 00093 shRedBuffer=(unsigned char*)malloc(shIMax*shJMax*sizeof(unsigned char)); 00094 if(shRedBuffer==(unsigned char*)NULL) 00095 { 00096 printf("Out of memory in shinit, allocating %d, line %d in file %s\n",shIMax*shJMax*sizeof(unsigned char),__LINE__,__FILE__);fflush(stdout); 00097 abort(); 00098 } 00099 shGreenBuffer=(unsigned char*)malloc(shIMax*shJMax*sizeof(unsigned char)); 00100 if(shGreenBuffer==(unsigned char*)NULL) 00101 { 00102 printf("Out of memory in shinit, allocating %d, line %d in file %s\n",shIMax*shJMax*sizeof(unsigned char),__LINE__,__FILE__);fflush(stdout); 00103 abort(); 00104 } 00105 shBlueBuffer=(unsigned char*)malloc(shIMax*shJMax*sizeof(unsigned char)); 00106 if(shBlueBuffer==(unsigned char*)NULL) 00107 { 00108 printf("Out of memory in shinit, allocating %d, line %d in file %s\n",shIMax*shJMax*sizeof(unsigned char),__LINE__,__FILE__);fflush(stdout); 00109 abort(); 00110 } 00111 shZBuffer=(float*)malloc(shIMax*shJMax*sizeof(float)); 00112 if(shZBuffer==(float*)NULL) 00113 { 00114 printf("Out of memory in shinit, allocating %d, line %d in file %s\n",shIMax*shJMax*sizeof(float),__LINE__,__FILE__);fflush(stdout); 00115 abort(); 00116 } 00117 /*printf("shinit, shZBuffer=0x%8.8x\n",shZBuffer);fflush(stdout);*/ 00118 00119 for(j=0;j<shJMax;j++) 00120 for(i=0;i<shIMax;i++)shsetp(&i,&j,r,g,b,&ftwo); 00121 00122 /* shlss('CMR10',5,1000,0,ierr) */ 00123 /* shcs(0,-3,3) */ 00124 00125 sh_frame=0; 00126 return; 00127 }
Here is the call graph for this function: |
|
Sets the current line color.
Definition at line 36 of file shlinc.c. Referenced by sharrow(), and shinit().
|
|
shades and renders a line.
Definition at line 31 of file shline.c. References shlnonrm(). Referenced by shcube(), shdraw(), shlineoff(), and shpl(). 00032 { 00033 00034 /* Shade and render a line segment. */ 00035 00036 float nn[3]={0.,0.,0.}; 00037 int zero=0; 00038 00039 shlnonrm(x0,y0,z0,nn,x1,y1,z1,nn,&zero,&zero,&zero); 00040 00041 return; 00042 }
Here is the call graph for this function: |
|
Draws a shadowed line segment in screen coordinates.
Definition at line 32 of file shline2s.c. References shsetp(). Referenced by sharrow(). 00033 { 00034 float zz; 00035 float xc,yc; 00036 float dx,dy; 00037 int ipix,jpix; 00038 00039 /* draw a line segment */ 00040 00041 if((*i0)==(*i1)&&(*j0)==(*j1)) 00042 { 00043 if((*i0)>0&&(*i0)<shIMax&&(*j0)>0&&(*j0)<shJMax) 00044 { 00045 zz=0.; 00046 shsetp(i0,j0,&sh_rl,&sh_gl,&sh_bl,&zz); 00047 } 00048 return; 00049 } 00050 00051 xc=(*i0); 00052 yc=(*j0); 00053 dx=(*i1)-xc; 00054 dy=(*j1)-yc; 00055 zz=0.; 00056 while(fabs(dx)>.5||fabs(dy)>.5) 00057 { 00058 ipix=xc+.5+(*ixoff); 00059 jpix=yc+.5+(*iyoff); 00060 if(ipix>0&&ipix<shIMax&&jpix>0&&jpix<shJMax)shsetp(&ipix,&jpix,&sh_rl,&sh_gl,&sh_bl,&zz); 00061 00062 dx=(*i1)-xc; 00063 dy=(*j1)-yc; 00064 if(abs(dx)>.5||abs(dy)>.5) 00065 { 00066 if(abs(dx)>abs(dy)) 00067 { 00068 if(dx>0) 00069 { 00070 xc=xc+1; 00071 yc=yc+dy/dx; 00072 }else{ 00073 xc=xc-1; 00074 yc=yc-dy/dx; 00075 } 00076 }else{ 00077 if(dy>0) 00078 { 00079 yc=yc+1; 00080 xc=xc+dx/dy; 00081 }else{ 00082 yc=yc-1; 00083 xc=xc-dx/dy; 00084 } 00085 } 00086 } 00087 dx=(*i1)-xc; 00088 dy=(*j1)-yc; 00089 } 00090 00091 return; 00092 }
Here is the call graph for this function: |
|
Draws a line with an offset. Currently this routine just draws a line.
Definition at line 34 of file shlineoff.c. References shline(). 00035 { 00036 00037 /* Line routine with offset */ 00038 00039 shline(x0,y0,z0,x1,y1,z1); 00040 return; 00041 }
Here is the call graph for this function: |
|
Assigns values to a light source.
Definition at line 44 of file shlit.c. References shpers(). Referenced by shinit(). 00045 { 00046 float xt=0.; 00047 float yt=0.; 00048 float zt=0.; 00049 00050 /* This Routine Sets the parameters associated with light source m. */ 00051 00052 /* x,y,z (real) position. */ 00053 /* r,g,b (integer 0-255) color. */ 00054 /* type (integer 0-1) 0=point,1=direction. */ 00055 00056 if((*m)>=sh_mlit) 00057 { 00058 if(sh_mlit==0) 00059 { 00060 sh_mlit=(*m)+10; 00061 sh_rs=(int*)malloc(sh_mlit*sizeof(int)); 00062 sh_gs=(int*)malloc(sh_mlit*sizeof(int)); 00063 sh_bs=(int*)malloc(sh_mlit*sizeof(int)); 00064 sh_type=(int*)malloc(sh_mlit*sizeof(int)); 00065 sh_lit=(double*)malloc(3*sh_mlit*sizeof(double)); 00066 }else{ 00067 sh_mlit=(*m)+10; 00068 sh_rs=(int*)realloc((void*)sh_rs,sh_mlit*sizeof(int)); 00069 sh_gs=(int*)realloc((void*)sh_gs,sh_mlit*sizeof(int)); 00070 sh_bs=(int*)realloc((void*)sh_bs,sh_mlit*sizeof(int)); 00071 sh_type=(int*)realloc((void*)sh_type,sh_mlit*sizeof(int)); 00072 sh_lit=(double*)realloc((void*)sh_lit,sh_mlit*sizeof(double)); 00073 } 00074 } 00075 sh_rs[(*m)-1]=*r; 00076 sh_gs[(*m)-1]=*g; 00077 sh_bs[(*m)-1]=*b; 00078 00079 shpers(x,y,z,&xt,&yt,&zt); 00080 sh_lit[0+3*((*m)-1)]=xt; 00081 sh_lit[1+3*((*m)-1)]=yt; 00082 sh_lit[2+3*((*m)-1)]=zt; 00083 sh_type[(*m)-1]=1; 00084 00085 return; 00086 }
Here is the call graph for this function: |
|
Draws a shaded line with an offset. The offset is used to determine visability, but not applied to the line when drawn.
Definition at line 52 of file shlnonrm.c. References sh3dmask(), shcolor(), shgetz(), shpers(), shsetp(), and shunpers(). Referenced by shline(), and shpgnrm(). 00053 { 00054 int rr=0; 00055 int gg=0; 00056 int bb=0; 00057 int i0,j0,i1,j1; 00058 int imask=0; 00059 00060 float nn[3]={0.,0.,0.}; 00061 float zbuf=0.; 00062 float dx,dy; 00063 int ipix,jpix; 00064 00065 float s0=0.; 00066 float t0=0.; 00067 float d0; 00068 float s1=0.; 00069 float t1=0.; 00070 float d1; 00071 float xx,yy,zz; 00072 float xxx=0.; 00073 float yyy=0.; 00074 float zzz=0.; 00075 float xc,yc; 00076 int clipped; 00077 int ip; 00078 float direc; 00079 00080 /* Project into perspective coordinates. */ 00081 00082 shpers(x0,y0,z0,&s0,&t0,&d0); 00083 shpers(x1,y1,z1,&s1,&t1,&d1); 00084 00085 if((*idoff)<0) 00086 { 00087 d0=1.005*d0; 00088 d1=1.005*d1; 00089 } 00090 if((*idoff)>0) 00091 { 00092 d0=.995*d0; 00093 d1=.995*d1; 00094 } 00095 00096 /* Transform to pixel coordinates. */ 00097 00098 i0=s0*shMax+.5; 00099 j0=t0*shMax+.5; 00100 00101 i1=s1*shMax+.5; 00102 j1=t1*shMax+.5; 00103 00104 if(i0==i1&&j0==j1) 00105 { 00106 if(i0>0&&i0<shIMax&&j0>0&&j0<shJMax) 00107 { 00108 shgetz(&i0,&j0,&zbuf); 00109 if(zbuf>d0) 00110 { 00111 if(shMask) 00112 { 00113 sh3dmask(x0,y0,z0,n0,&imask); 00114 if(imask==1) 00115 { 00116 shcolor(x0,y0,z0,n0,&sh_rl,&sh_gl,&sh_bl,&sh_rl,&sh_gl,&sh_bl,&rr,&gg,&bb); 00117 if(shlw==0)shsetp(&i0,&j0,&rr,&gg,&bb,&d0); 00118 else shtmpsetp(i0,j0,rr,gg,bb,d0,shlw); 00119 } 00120 }else{ 00121 shcolor(x0,y0,z0,n0,&sh_rl,&sh_gl,&sh_bl,&sh_rl,&sh_gl,&sh_bl,&rr,&gg,&bb); 00122 if(shlw==0)shsetp(&i0,&j0,&rr,&gg,&bb,&d0); 00123 else shtmpsetp(i0,j0,rr,gg,bb,d0,shlw); 00124 } 00125 } 00126 } 00127 return; 00128 } 00129 00130 /* Trace and shade the line. */ 00131 00132 xc=i0; 00133 yc=j0; 00134 dx=i1-xc; 00135 dy=j1-yc; 00136 while(fabs(dx)>.5||fabs(dy)>.5) 00137 { 00138 if(fabs(i1-i0)>fabs(j1-j0)) 00139 { 00140 xx=s0+(float)(xc-i0)*(s1-s0)/(float)(i1-i0); 00141 yy=t0+(float)(xc-i0)*(t1-t0)/(float)(i1-i0); 00142 zz=d0+(float)(xc-i0)*(d1-d0)/(float)(i1-i0); 00143 nn[0]=n0[0]+(float)(xc-i0)*(n1[0]-n0[0])/(float)(i1-i0); 00144 nn[1]=n0[1]+(float)(xc-i0)*(n1[1]-n0[1])/(float)(i1-i0); 00145 nn[2]=n0[2]+(float)(xc-i0)*(n1[2]-n0[2])/(float)(i1-i0); 00146 }else{ 00147 xx=s0+(float)(yc-j0)*(s1-s0)/(float)(j1-j0); 00148 yy=t0+(float)(yc-j0)*(t1-t0)/(float)(j1-j0); 00149 zz=d0+(float)(yc-j0)*(d1-d0)/(float)(j1-j0); 00150 nn[0]=n0[0]+(float)(yc-j0)*(n1[0]-n0[0])/(float)(j1-j0); 00151 nn[1]=n0[1]+(float)(yc-j0)*(n1[1]-n0[1])/(float)(j1-j0); 00152 nn[2]=n0[2]+(float)(yc-j0)*(n1[2]-n0[2])/(float)(j1-j0); 00153 } 00154 00155 /* clip */ 00156 00157 clipped=0; 00158 shunpers(&xx,&yy,&zz,&xxx,&yyy,&zzz); 00159 if(sh_nplns>0) 00160 { 00161 for(ip=0;ip<sh_nplns;ip++) 00162 { 00163 direc=sh_plnn[ 3*ip]*(xxx-sh_plno[ 3*ip])+sh_plnn[1+3*ip]*(yyy-sh_plno[1+3*ip])+sh_plnn[2+3*ip]*(zzz-sh_plno[2+3*ip]); 00164 if(sh_oper[ip]==0) 00165 clipped=clipped||(sh_ipln[ip]*direc<0); 00166 else 00167 clipped=clipped&&(sh_ipln[ip]*direc<0); 00168 } 00169 } 00170 if(!clipped) 00171 { 00172 ipix=xc+.5; 00173 jpix=yc+.5; 00174 if(ipix>0&&ipix<shIMax&&jpix>0&&jpix<shJMax) 00175 { 00176 shgetz(&ipix,&jpix,&zbuf); 00177 if(zbuf>zz-.005) 00178 { 00179 if(shMask) 00180 { 00181 sh3dmask(&xxx,&yyy,&zzz,nn,&imask); 00182 if(imask==1) 00183 { 00184 shcolor(&xxx,&yyy,&zzz,nn,&sh_rl,&sh_gl,&sh_bl,&sh_rl,&sh_gl,&sh_bl,&rr,&gg,&bb); 00185 if(shlw==0)shsetp(&ipix,&jpix,&rr,&gg,&bb,&zz); 00186 else shtmpsetp(ipix,jpix,rr,gg,bb,zz,shlw); 00187 } 00188 }else{ 00189 shcolor(&xxx,&yyy,&zzz,nn,&sh_rl,&sh_gl,&sh_bl,&sh_rl,&sh_gl,&sh_bl,&rr,&gg,&bb); 00190 if(shlw==0)shsetp(&ipix,&jpix,&rr,&gg,&bb,&zz); 00191 else shtmpsetp(ipix,jpix,rr,gg,bb,zz,shlw); 00192 } 00193 } 00194 } 00195 } 00196 00197 dx=i1-xc; 00198 dy=j1-yc; 00199 if(fabs(dx)>.5||fabs(dy)>.5) 00200 { 00201 if(fabs(dx)>fabs(dy)) 00202 { 00203 if(dx>0) 00204 { 00205 xc=xc+1; 00206 yc=yc+dy/dx; 00207 }else{ 00208 xc=xc-1; 00209 yc=yc-dy/dx; 00210 } 00211 }else{ 00212 if(dy>0) 00213 { 00214 yc=yc+1; 00215 xc=xc+dx/dy; 00216 }else{ 00217 yc=yc-1; 00218 xc=xc-dx/dy; 00219 } 00220 } 00221 } 00222 } 00223 00224 return; 00225 }
Here is the call graph for this function: |
|
Loads a character set into the table of character sets.
Definition at line 40 of file shlss.c. 00041 { 00042 00043 /* loads a symbol set */ 00044 00045 char *ssname; 00046 char *cname; 00047 char *file; 00048 00049 int i,k; 00050 int len=0; 00051 int irem; 00052 int irec,nrec; 00053 00054 FILE *fid; 00055 00056 int xref,yref; 00057 char fontnm[20]; 00058 00059 /* loads a symbol set */ 00060 00061 *ierr=0; 00062 00063 cname=(char*)malloc(((*lname)+1)*sizeof(char)); 00064 ssname=(char*)malloc(((*lname)+5)*sizeof(char)); 00065 strncpy(cname,name,(*lname)); 00066 cname[(*lname)]=0x0; 00067 sprintf(ssname,"%s.%4.4d",cname,*pmag); 00068 00069 file=(char*)malloc((strlen(QUOTE( FONTPATH ))+(*lname)+10)*sizeof(char)); 00070 strcpy(file,QUOTE( FONTPATH ) ); 00071 strcat(file,ssname); 00072 strcat(file,"IAX"); 00073 free(cname); 00074 free(ssname); 00075 00076 /* Is it loaded already? */ 00077 00078 if(*ifnt>=sh_kFonts) 00079 { 00080 if(sh_kfont==(int*)NULL) 00081 { 00082 sh_kFonts=10; 00083 sh_kfont=(int*)malloc(sh_kFonts*sizeof(int)); 00084 }else{ 00085 sh_kFonts=*ifnt+10; 00086 sh_kfont=(int*)realloc((void*)sh_kfont,sh_kFonts*sizeof(int)); 00087 } 00088 } 00089 00090 if(sh_nFonts>0) 00091 { 00092 k=0; 00093 for(i=0;i<sh_nFonts;i++) 00094 { 00095 if(!strcmp(sh_fontnm[i],ssname))k=i; 00096 } 00097 } 00098 if(k!=0) 00099 { 00100 sh_kfont[*ifnt]=k; 00101 *ierr=1; 00102 return; 00103 } 00104 00105 if((fid=fopen(file,"r"))==(FILE*)NULL) 00106 { 00107 fprintf(stderr,"shSoft Font file -->%s<-- not found\n",file); 00108 free(file); 00109 return; 00110 } 00111 free(file); 00112 00113 /* read in character set */ 00114 00115 if(sh_nFonts>=sh_mFonts) 00116 { 00117 if(sh_mFonts==0) 00118 { 00119 sh_mFonts=10; 00120 sh_dir=(int*)malloc(sh_mFonts*sizeof(int)); 00121 sh_fmag=(int*)malloc(sh_mFonts*sizeof(int)); 00122 sh_fontnm=(char**)malloc(sh_mFonts*sizeof(char*)); 00123 }else{ 00124 sh_mFonts=*ifnt+10; 00125 sh_dir=(int*)realloc((void*)sh_dir,sh_mFonts*sizeof(int)); 00126 sh_fmag=(int*)realloc((void*)sh_fmag,sh_mFonts*sizeof(int)); 00127 sh_fontnm=(char**)realloc((void*)sh_fontnm,sh_mFonts*sizeof(char*)); 00128 } 00129 } 00130 00131 sh_kfont[*ifnt]=sh_nFonts; 00132 00133 fscanf(fid,"%d",&len); 00134 if(sh_nimg+len>=sh_lenimg) 00135 { 00136 if(sh_lenimg==0) 00137 { 00138 sh_lenimg=sh_nimg+len; 00139 sh_image=(char*)malloc(sh_lenimg*sizeof(char)); 00140 }else{ 00141 sh_lenimg+=sh_nimg+len; 00142 sh_image=(char*)realloc((void*)sh_image,sh_lenimg*sizeof(char)); 00143 } 00144 } 00145 00146 nrec=floor(len/512); 00147 for(irec=0;irec<nrec;irec++); 00148 { 00149 for(i=0;i<512;i++)sh_image[sh_nimg+512*irec+i]=fgetc(fid); 00150 fgetc(fid); 00151 } 00152 irem=len%512; 00153 if(irem>0) 00154 for(i=0;i<irem;i++)sh_image[sh_nimg+512*nrec+i]=fgetc(fid); 00155 fclose(fid); 00156 00157 sh_dir[sh_nFonts]=sh_nimg; 00158 sh_fmag[sh_nFonts]=*pmag; 00159 sh_fontnm[sh_nFonts]=(char*)malloc((strlen(ssname)+1)*sizeof(char)); 00160 strcpy(sh_fontnm[sh_nFonts],ssname); 00161 sh_nimg+=len; 00162 sh_nFonts++; 00163 00164 return; 00165 }
|
|
Turns the 3d mask on and off.
Definition at line 32 of file shmask.c. Referenced by shinit().
|
|
Sets the number of light sources to be used. The first n are used, the rest are not deleted, just not used.
Definition at line 26 of file shnlit.c. Referenced by shinit(). 00027 { 00028 00029 /* This Routine Sets the number of light sources to be used. */ 00030 00031 sh_nlit=*n; 00032 00033 return; 00034 }
|
|
Sets the number of clipping planes to use. The first n are used, the rest are not deleted, just no used.
Definition at line 26 of file shnpln.c. Referenced by shinit(), and shpgnrm(). 00027 { 00028 00029 /* Set the number of clipping planes. */ 00030 00031 sh_nplns=*n; 00032 return; 00033 }
|
|
Sets the color of the front facing edges of polygons.
Definition at line 57 of file shpgc.c. Referenced by shtric(). 00058 { 00059 sh_rd[1] =*r; 00060 sh_gd[1] =*g; 00061 sh_bd[1] =*b; 00062 sh_ram[1]=*r; 00063 sh_gam[1]=*g; 00064 sh_bam[1]=*b; 00065 return; 00066 }
|
|
Performs the perspective transformation.
Definition at line 32 of file shpers.c. Referenced by sharrow(), shlit(), shlnonrm(), shscal(), and shstr(). 00033 { 00034 float c1,c2,c3; 00035 float dtemp; 00036 00037 /* Project x,y,z to perspective coordinates. */ 00038 00039 c1= (*x-shv_x0)*shv_n11+(*y-shv_y0)*shv_n12+(*z-shv_z0)*shv_n13; 00040 c2= (*x-shv_x0)*shv_n21+(*y-shv_y0)*shv_n22+(*z-shv_z0)*shv_n23; 00041 c3= (*x-shv_x0)*shv_n31+(*y-shv_y0)*shv_n32+(*z-shv_z0)*shv_n33; 00042 00043 dtemp=(shv_l-shv_d)/(c1-shv_d); 00044 *s=dtemp*c2*shv_pcale+shv_soff; 00045 *t=dtemp*c3*shv_pcale+shv_toff; 00046 *depth=-dtemp*c1*shv_dscl+shv_doff; 00047 00048 return; 00049 }
|
|
renders a polygon.
Definition at line 30 of file shpg.c. Referenced by shtri(). 00031 { 00032 int r,g,b; 00033 int r0,g0,b0; 00034 int i; 00035 float an; 00036 00037 /* shade and z-buffer a polygon defined by the vertices xt,yt,zt. */ 00038 00039 float nx,ny,nz; 00040 float *nrm; 00041 00042 nrm=(float*)malloc(3*(*nv)*sizeof(float)); 00043 00044 /* find normal */ 00045 00046 nx=(yt[1]-yt[0])*(zt[2]-zt[0])-(yt[2]-yt[0])*(zt[1]-zt[0]); 00047 ny=(xt[2]-xt[0])*(zt[1]-zt[0])-(xt[1]-xt[0])*(zt[2]-zt[0]); 00048 nz=(xt[1]-xt[0])*(yt[2]-yt[0])-(xt[2]-xt[0])*(yt[1]-yt[0]); 00049 an=sqrt(nx*nx+ny*ny+nz*nz); 00050 if(an==0.)return; 00051 an=1./an; 00052 nx=nx*an; 00053 ny=ny*an; 00054 nz=nz*an; 00055 00056 for(i=0;i<*nv;i++) 00057 { 00058 nrm[ 3*i]=nx; 00059 nrm[1+3*i]=ny; 00060 nrm[2+3*i]=nz; 00061 } 00062 00063 shpgnrm(nv,xt,yt,zt,nrm); 00064 00065 free(nrm); 00066 00067 return; 00068 }
|
|
Sets the color of the front face (determined by the normal) of polygons.
Definition at line 39 of file shpgc.c. Referenced by shtric(). 00040 { 00041 sh_rd[0] =*r; 00042 sh_gd[0] =*g; 00043 sh_bd[0] =*b; 00044 sh_ram[0]=*r; 00045 sh_gam[0]=*g; 00046 sh_bam[0]=*b; 00047 return; 00048 }
|
|
Shades and z-buffers a polygon with specified normals.
Definition at line 32 of file shpgnrm.c. References shclippg(), shdopg(), shlnonrm(), shnpln(), and shqnpln(). 00033 { 00034 int r=0; 00035 int g=0; 00036 int b=0; 00037 int r0=0; 00038 int g0=0; 00039 int b0=0; 00040 int zero=0; 00041 int one=1; 00042 int full=255; 00043 int i; 00044 00045 /* shade and z-buffer a polygon defined by the vertices xt,yt,zt. */ 00046 00047 float *x,*y,*z; 00048 float nx,ny,nz; 00049 int *ict,*ic; 00050 float *nrm; 00051 int nn=0; 00052 int np=0; 00053 00054 x=(float*)NULL; 00055 y=(float*)NULL; 00056 z=(float*)NULL; 00057 nrm=(float*)NULL; 00058 ic=(int*)NULL; 00059 00060 ict=(int*)malloc((*nv)*sizeof(int)); 00061 00062 for(i=0;i<*nv;i++)ict[i]=1; 00063 shclippg(nv,xt,yt,zt,nrmt,ict,&nn,&x,&y,&z,&nrm,&ic); 00064 shdopg(&nn,x,y,z,nrm); 00065 00066 #ifdef FGHJKL 00067 x=(float*)realloc((void*)x,(nn+1)*sizeof(float)); 00068 y=(float*)realloc((void*)y,(nn+1)*sizeof(float)); 00069 z=(float*)realloc((void*)z,(nn+1)*sizeof(float)); 00070 ic=(int*)realloc((void*)ic,(nn+1)*sizeof(int)); 00071 00072 x[nn]=x[0]; 00073 y[nn]=y[0]; 00074 z[nn]=z[0]; 00075 ic[nn]=ic[0]; 00076 00077 shqnpln(&np); 00078 shnpln(&zero); 00079 for(i=0;i<nn;i++) 00080 { 00081 if(0||ic[i+1]!=1) 00082 { 00083 /* shqlinc(&r,&g,&b); 00084 shlinc(&full,&full,&full);*/ 00085 if(fabs(x[i]-x[i+1])>1.e-6||fabs(y[i]-y[i+1])>1.e-6||fabs(z[i]-z[i+1])>1.e-6) 00086 { 00087 shlnonrm(&(x[i]),&(y[i]),&(z[i]),&(nrm[3*i]),&(x[i+1]),&(y[i+1]),&(z[i+1]),&(nrm[3*i+3]),&zero,&zero,&one); 00088 /* shlinc(&r,&g,&b);*/ 00089 } 00090 }else{ 00091 if(fabs(x[i]-x[i+1])>1.e-6||fabs(y[i]-y[i+1])>1.e-6||fabs(z[i]-z[i+1])>1.e-6) 00092 { 00093 shqlinc(&r0,&g0,&b0); 00094 shqpec(&r,&g,&b); 00095 if(r0!=r&&g0!=g&&b0!=b) 00096 { 00097 shlinc(&r,&g,&b); 00098 shlnonrm(&(x[i]),&(y[i]),&(z[i]),&(nrm[3*i]),&(x[i+1]),&(y[i+1]),&(z[i+1]),&(nrm[3*i+3]),&zero,&zero,&one); 00099 shlinc(&r0,&g0,&b0); 00100 } 00101 } 00102 } 00103 } 00104 shnpln(&np); 00105 #endif 00106 00107 free(x); 00108 free(y); 00109 free(z); 00110 free(nrm); 00111 free(ict); 00112 free(ic); 00113 00114 return; 00115 }
Here is the call graph for this function: |
|
Shades and draws a polyline.
Definition at line 29 of file shpl.c. References shline(). 00030 { 00031 int i; 00032 00033 /* Shade and render a polyline */ 00034 00035 for(i=0;i<*n-1;i++) 00036 shline(x+i,y+i,z+i,x+i+1,y+i+1,z+i+1); 00037 00038 return; 00039 }
Here is the call graph for this function: |
|
Sets a clipping plane.
Definition at line 33 of file shpln.c. 00034 { 00035 int ip; 00036 00037 ip=(*i)-1; 00038 00039 /* Set the clipping plane info. */ 00040 00041 if(*i>=sh_mplns) 00042 { 00043 if(sh_mplns==0) 00044 { 00045 sh_mplns=10; 00046 sh_plno=(float*)malloc(3*sh_mplns*sizeof(float)); 00047 sh_plnn=(float*)malloc(3*sh_mplns*sizeof(float)); 00048 sh_ipln=(int*)malloc(sh_mplns*sizeof(int)); 00049 sh_oper=(int*)malloc(sh_mplns*sizeof(int)); 00050 }else{ 00051 sh_mplns+=10; 00052 sh_plno=(float*)realloc((void*)sh_plno,3*sh_mplns*sizeof(float)); 00053 sh_plnn=(float*)realloc((void*)sh_plnn,3*sh_mplns*sizeof(float)); 00054 sh_ipln=(int*)realloc((void*)sh_ipln,sh_mplns*sizeof(int)); 00055 sh_oper=(int*)realloc((void*)sh_oper,sh_mplns*sizeof(int)); 00056 } 00057 } 00058 00059 sh_plno[ 3*ip]=*ox; 00060 sh_plno[1+3*ip]=*oy; 00061 sh_plno[2+3*ip]=*oz; 00062 00063 sh_plnn[ 3*ip]=*nx; 00064 sh_plnn[1+3*ip]=*ny; 00065 sh_plnn[2+3*ip]=*nz; 00066 00067 sh_ipln[ip]=*iside; 00068 sh_oper[ip]=0; 00069 00070 /*printf("plane %d is ((x,y,z)-(%f,%f,%f)).(%f,%f,%f)*%d>0\n",ip,sh_plno[ 3*ip],sh_plno[1+3*ip],sh_plno[2+3*ip],sh_plnn[ 3*ip],sh_plnn[1+3*ip],sh_plnn[2+3*ip],sh_ipln[ip]);fflush(stdout);*/ 00071 00072 00073 return; 00074 }
|
|
Draws a polyline that is shaded according to the normals given by triplets of points (periodic). If any three consecutive points are colinear nothing is drawn.
Definition at line 31 of file shplnrm.c. 00032 { 00033 float *n; 00034 float an; 00035 int m,m1,m2,m3; 00036 int i; 00037 int zero=0; 00038 00039 /* Shade and render a polyline with normals */ 00040 00041 n=(float*)malloc(3*(*nv)*sizeof(float)); 00042 00043 for(m=0;m<*nv;m++) 00044 { 00045 m1=m; 00046 m3=m-1; 00047 if(m3<1)m3=*nv; 00048 m2=m+1; 00049 if(m2>*nv)m2=1; 00050 m1=1; 00051 m2=2; 00052 m3=3; 00053 n[3*m]=(yt[m2]-yt[m1])*(zt[m3]-zt[m1])-(yt[m3]-yt[m1])*(zt[m2]-zt[m1]); 00054 n[1+3*m]=(xt[m3]-xt[m1])*(zt[m2]-zt[m1])-(xt[m2]-xt[m1])*(zt[m3]-zt[m1]); 00055 n[2+3*m]=(xt[m2]-xt[m1])*(yt[m3]-yt[m1])-(xt[m3]-xt[m1])*(yt[m2]-yt[m1]); 00056 an=sqrt(n[3*m]*n[3*m]+n[1+3*m]*n[1+3*m]+n[2+3*m]*n[2+3*m]); 00057 if(an==0.)return; 00058 an=1./an; 00059 n[3*m]=n[3*m]*an; 00060 n[1+3*m]=n[1+3*m]*an; 00061 n[2+3*m]=n[2+3*m]*an; 00062 } 00063 00064 for(i=0;i<*nv-1;i++) 00065 shlnonrm(xt+i,yt+i,zt+i,&(n[3*i]),xt+i+1,yt+i+1,zt+i+1,&(n[3*i+3]),&zero,&zero,&zero); 00066 return; 00067 }
|
|
Draws a single point (one pixel).
Definition at line 28 of file shpnt.c. 00029 { 00030 00031 /* Shade and Render a point. */ 00032 00033 float s=0.; 00034 float t=0.; 00035 float d=0.; 00036 int clipped; 00037 int ip; 00038 float direc; 00039 int ipix,jpix; 00040 float zbuf=0.; 00041 00042 /* clip */ 00043 00044 clipped=0; 00045 if(sh_nplns>0) 00046 { 00047 for(ip==0;ip<sh_nplns;ip++) 00048 { 00049 direc=sh_plnn[ 3*ip]*((*x)-sh_plno[ 3*ip])+sh_plnn[1+3*ip]*((*y)-sh_plno[1+3*ip])+sh_plnn[2+3*ip]*((*z)-sh_plno[2+3*ip]); 00050 if(sh_oper[ip]==0) 00051 clipped=clipped||(sh_ipln[ip]*direc==0); 00052 else 00053 clipped=clipped&&(sh_ipln[ip]*direc==0); 00054 } 00055 if(clipped)return; 00056 } 00057 00058 shpers(x,y,z,&s,&t,&d); 00059 ipix=s*shMax+.5; 00060 jpix=t*shMax+.5; 00061 if(ipix>0&&ipix<shIMax&&jpix>0&&jpix<shJMax) 00062 { 00063 shgetz(&ipix,&jpix,&zbuf); 00064 if(zbuf>d)shsetp(&ipix,&jpix,&sh_rp,&sh_gp,&sh_bp,&d); 00065 } 00066 00067 return; 00068 }
|
|
Sets the color used to draw points.
Definition at line 36 of file shpntc.c. Referenced by shinit().
|
|
writes an image to a postscript file.
Definition at line 34 of file shputps.c. Referenced by shsave(). 00035 { 00036 char title[255]=""; 00037 FILE *fid; 00038 int i,j; 00039 int i0,j0,i1,j1; 00040 int xll,yll,xur,yur; 00041 float w; 00042 00043 i0=*m; 00044 j0=*n; 00045 i1=-1; 00046 j1=-1; 00047 for(j=0;j<*n;j++) 00048 { 00049 for(i=0;i<*m;i++) 00050 { 00051 if(shRedBuffer[i+j*shIMax]!=255||shGreenBuffer[i+j*shIMax]!=255||shBlueBuffer[i+j*shIMax]!=255) 00052 { 00053 if(j<=j0)j0=j; 00054 if(i<=i0)i0=i; 00055 if(j>=j1)j1=j; 00056 if(i>=i1)i1=i; 00057 } 00058 } 00059 } 00060 w=(*n)*504./(*m); 00061 xll=i0*w/(*m); 00062 yll=j0*w/(*n); 00063 xur=i1*w/(*m); 00064 yur=j1*w/(*n); 00065 00066 strncpy(title,file,*ln); 00067 title[*ln]=0x0; 00068 00069 fid=fopen(file,"w"); 00070 if(fid==(FILE*)NULL) 00071 { 00072 fprintf(stderr,"shputps: Problem opening file -->%s<-- for writing.\n",file); 00073 fflush(stderr); 00074 return; 00075 } 00076 fprintf(fid,"%s\n","%!PS-Adobe-3.0"); 00077 fprintf(fid,"%s\n","%%Creator: SH by Michael E. Henderson, 03/17/93"); 00078 fprintf(fid,"%s%s\n","%%Title: ",title); 00079 fprintf(fid,"%s %d %d %d %d\n","%%BoundingBox:",xll+50,yll+50,xur+52,yur+52); 00080 fprintf(fid,"%s\n","%%EndComments"); 00081 fprintf(fid,"%s\n","%%BeginProlog"); 00082 fprintf(fid,"%s\n","%%BeginResource: "); 00083 fprintf(fid,"%s\n"," "); 00084 fprintf(fid,"%s\n","% see if we have the ""colorimage"" operator."); 00085 fprintf(fid,"%s\n","% define one if we don""t"); 00086 fprintf(fid,"%s\n","/colorimage where % do we know about ""colorimage""?"); 00087 fprintf(fid,"%s\n"," { pop } % yes: pop off the ""dict"" returned"); 00088 fprintf(fid,"%s\n"," { % no: define one"); 00089 fprintf(fid,"%s\n"," /str1 1 string def"); 00090 fprintf(fid,"%s\n"," /str3 3 string def"); 00091 fprintf(fid,"%s\n"," /colorimage"); 00092 fprintf(fid,"%s\n"," { pop pop % pop off ""false"", ""3"" operands"); 00093 fprintf(fid,"%s\n"," pop % pop off old ""readhexstring"" proc"); 00094 fprintf(fid,"%s\n"," % and define a new one for ""image"""); 00095 fprintf(fid,"%s\n"," { currentfile str3 readhexstring pop pop"); 00096 fprintf(fid,"%s\n"," str1 0 % for the ""put"" below"); 00097 fprintf(fid,"%s\n"," str3 0 get 20 mul % Red"); 00098 fprintf(fid,"%s\n"," str3 1 get 32 mul % Green"); 00099 fprintf(fid,"%s\n"," str3 2 get 12 mul % Blue"); 00100 fprintf(fid,"%s\n"," add add 64 idiv % I = .5G + .31R + .18B"); 00101 fprintf(fid,"%s\n"," put str1 % str1 = intensity of R,G,B triplet"); 00102 fprintf(fid,"%s\n"," } image"); 00103 fprintf(fid,"%s\n"," } def % end of colorimage def"); 00104 fprintf(fid,"%s\n"," } ifelse % end of ""false"" case"); 00105 fprintf(fid,"%s\n"," "); 00106 fprintf(fid,"%s\n","%%EndResource"); 00107 fprintf(fid,"%s\n","%%EndProlog"); 00108 fprintf(fid,"%s\n"," "); 00109 fprintf(fid,"%s\n","%%Page: 1 1"); 00110 fprintf(fid,"%s\n"," "); 00111 fprintf(fid,"%s\n","%%BeginPageSetup"); 00112 fprintf(fid,"%s\n"," "); 00113 fprintf(fid," newpath\n"); 00114 fprintf(fid," %d %d moveto\n",xll+50,yll+50); 00115 fprintf(fid," %d %d lineto\n",xur+52,yll+50); 00116 fprintf(fid," %d %d lineto\n",xur+52,yur+52); 00117 fprintf(fid," %d %d lineto\n",xll+50,yur+52); 00118 fprintf(fid," closepath clip\n"); 00119 fprintf(fid,"%s\n","% Image size (1/72 inch coords,"); 00120 fprintf(fid,"%d %f %s\n",504,w," scale"); 00121 00122 fprintf(fid,"%s\n"," "); 00123 fprintf(fid,"%s\n","%%EndPageSetup"); 00124 fprintf(fid,"%s\n"," "); 00125 fprintf(fid,"%f %f %s\n",.1,.1," translate"); 00126 fprintf(fid,"%s %d %s\n","/readstr ",3*(*m)," string def"); 00127 fprintf(fid,"%d %d %d %s %d %d %d %d %d %d %s\n",*m,*n,8,"[ ", *m, 0,0,*n,0,0, " ]"); 00128 fprintf(fid,"%s\n","{currentfile readstr readhexstring pop}"); 00129 fprintf(fid,"%s\n","false 3 colorimage"); 00130 00131 for(j=0;j<*n;j++) 00132 { 00133 for(i=0;i<*m;i++) 00134 { 00135 fprintf(fid,"%2.2x%2.2x%2.2x",shRedBuffer[i+j*shIMax],shGreenBuffer[i+j*shIMax],shBlueBuffer[i+j*shIMax]); 00136 if(i%20==19)fprintf(fid,"\n"); 00137 } 00138 if((*m-1)%20!=19)fprintf(fid,"\n"); 00139 } 00140 00141 fprintf(fid,"%s\n"," "); 00142 fprintf(fid,"%f %f %s\n",1./504.,1./w," scale"); 00143 shdoStrings(fid,shIMax/512.,shJMax/w); 00144 00145 fprintf(fid,"%s\n"," showpage"); 00146 fclose(fid); 00147 00148 return; 00149 }
|
|
writes an image to a tiff file (if libtiff was installed when sh was configured).
Definition at line 40 of file shputtiff.c. Referenced by shsave(). 00041 { 00042 #ifdef HAVE_LIBTIFF 00043 TIFF *out = NULL; 00044 00045 char *fn; 00046 char *buf; 00047 unsigned int i,j; 00048 unsigned red=0; 00049 unsigned green=1; 00050 unsigned blue=2; 00051 00052 int rc; 00053 int ln; 00054 int separate; 00055 00056 separate=0; 00057 00058 ln=nrows*ncols; 00059 00060 fn=(char *)malloc((strlen(file)+1)*sizeof(char)); 00061 strcpy(fn,file); 00062 00063 /*printf(" puttiff for ==>%s<==\n",fn);*/ 00064 /*printf(" Image is %dx%d\n",nrows,ncols);*/ 00065 00066 out = TIFFOpen(fn, "w"); 00067 free(fn); 00068 if (out == NULL)return; 00069 00070 TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (unsigned long) ncols); 00071 TIFFSetField(out, TIFFTAG_IMAGELENGTH, (unsigned long) nrows); 00072 TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); 00073 TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 3); 00074 TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8,8,8); 00075 TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE); 00076 TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, 1); 00077 /*TIFFSetField(out, TIFFTAG_STRIPBYTECOUNTS, ncols);*/ 00078 00079 TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); 00080 00081 if(separate) 00082 { 00083 TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_SEPARATE); 00084 buf=(char *)malloc(ncols*sizeof(char)); 00085 }else{ 00086 TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); 00087 buf=(char *)malloc(3*ncols*sizeof(char)); 00088 } 00089 TIFFSetField(out, TIFFTAG_SOFTWARE, "puttiff"); 00090 00091 for(i=0;i<nrows;i++) 00092 { 00093 if(separate) 00094 { 00095 for(j=0;j<ncols;j++)buf[j]=r[j+i*ncols]; 00096 /* rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)i, red);*/ 00097 rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)(nrows-i-1), red); 00098 00099 for(j=0;j<ncols;j++)buf[j]=g[j+i*ncols]; 00100 /* rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)i, green);*/ 00101 rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)(nrows-i-1), green); 00102 00103 for(j=0;j<ncols;j++)buf[j]=b[j+i*ncols]; 00104 /* rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)i, blue);*/ 00105 rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)(nrows-i-1), blue); 00106 }else{ 00107 for(j=0;j<ncols;j++)buf[3*j ]=r[j+i*ncols]; 00108 for(j=0;j<ncols;j++)buf[3*j+1]=g[j+i*ncols]; 00109 for(j=0;j<ncols;j++)buf[3*j+2]=b[j+i*ncols]; 00110 /* rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)i, 0);*/ 00111 rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)(nrows-i-1), 0); 00112 } 00113 } 00114 free(buf); 00115 00116 TIFFWriteDirectory(out); 00117 00118 TIFFClose(out); 00119 #endif 00120 return; 00121 }
|
|
Gets the color of the back facing edge of polygons.
Definition at line 156 of file shpgc.c.
|
|
Gets the color of the back face of polygons.
Definition at line 141 of file shpgc.c.
|
|
Returns the position of the eye.
Definition at line 132 of file shpers.c. 00133 { 00134 00135 /* Entry to return viewpoint. */ 00136 00137 *xe=shv_d*shv_n11; 00138 *ye=shv_d*shv_n12; 00139 *ze=shv_d*shv_n13; 00140 return; 00141 }
|
|
Reads the current line color.
Definition at line 50 of file shlinc.c. Referenced by sharrow().
|
|
Reads back a light source.
Definition at line 32 of file shqlit.c. 00033 { 00034 00035 /* This Routine Returns the parameters associated with light source */ 00036 00037 /* x,y,z (real) position. */ 00038 /* r,g,b (integer 0-255) color. */ 00039 /* type (integer 0-1) 0=point,1=direction. */ 00040 00041 *r=sh_rs[*m]; 00042 *g=sh_gs[*m]; 00043 *b=sh_bs[*m]; 00044 00045 *x=sh_lit[ +3*(*m)]; 00046 *y=sh_lit[1+3*(*m)]; 00047 *z=sh_lit[2+3*(*m)]; 00048 00049 return; 00050 }
|
|
Reads back the number of clipping planes.
Definition at line 26 of file shqnpln.c. Referenced by shpgnrm(). 00027 { 00028 00029 /* Return the number of clipping planes. */ 00030 00031 *n=sh_nplns; 00032 return; 00033 }
|
|
Gets the color of the front facing edge of polygons.
Definition at line 126 of file shpgc.c.
|
|
Gets the color of the front face of polygons.
Definition at line 111 of file shpgc.c.
|
|
Reads the color used to draw points.
Definition at line 51 of file shpntc.c.
|
|
Saves the current frame buffer. If shOutputFormat is "postscript" a postscript file is written (duh). If shOutputFormat is "tiff" and libtiff was installed before sh was configured, a tiff file is written.
Definition at line 36 of file shsave.c. References shputps(), and shputtiff(). Referenced by shpause(). 00037 { 00038 00039 /* Write image to disk.*/ 00040 00041 if(!strcmp(shOutputFormat,"postscript")) 00042 shputps(name,ln,&shIMax,&shJMax,shRedBuffer,shGreenBuffer,shBlueBuffer,nln); 00043 #ifdef HAVE_LIBTIFF 00044 else if(!strcmp(shOutputFormat,"tiff")) 00045 shputtiff(name, shIMax,shJMax, shRedBuffer,shGreenBuffer,shBlueBuffer); 00046 #endif 00047 else 00048 shputps(name,ln,&shIMax,&shJMax,shRedBuffer,shGreenBuffer,shBlueBuffer,nln); 00049 return; 00050 }
Here is the call graph for this function: |
|
Sets the visible volume.
Definition at line 31 of file shscal.c. References shpers(), and shsize(). Referenced by shview(). 00032 { 00033 int i,j; 00034 00035 float one=1.; 00036 float zero=0.; 00037 float smax,smin; 00038 float tmax,tmin; 00039 float dmax,dmin; 00040 float s=0.; 00041 float t=0.; 00042 float d=0.; 00043 float x,y,z; 00044 float as,at,pcale; 00045 float soff; 00046 float toff; 00047 float dcale; 00048 float doff; 00049 00050 float I[8*6]={0.,0.,0.,0.,1.,1.,1.,1., 00051 1.,1.,1.,1.,0.,0.,0.,0., 00052 0.,0.,1.,1.,0.,0.,1.,1., 00053 1.,1.,0.,0.,1.,1.,0.,0., 00054 0.,1.,0.,1.,0.,1.,0.,1., 00055 1.,0.,1.,0.,1.,0.,1.,0.}; 00056 00057 /* Perform Scaling for the perspective transform. */ 00058 00059 shsize(&one,&zero,&zero,&one,&zero); 00060 00061 smax=-1.e5; 00062 smin=1.e5; 00063 tmax=-1.e5; 00064 tmin=1.e5; 00065 dmax=-1.e5; 00066 dmin=1.e5; 00067 00068 for(j=0;j<8;j++) 00069 { 00070 x=I[j+8*0]*(*xmax)+I[j+8*1]*(*xmin); 00071 y=I[j+8*2]*(*ymax)+I[j+8*3]*(*ymin); 00072 z=I[j+8*4]*(*zmax)+I[j+8*5]*(*zmin); 00073 shpers(&x,&y,&z,&s,&t,&d); 00074 if(s>smax)smax=s; 00075 if(s<smin)smin=s; 00076 if(t>tmax)tmax=t; 00077 if(t<tmin)tmin=t; 00078 if(d>dmax)dmax=d; 00079 if(d<dmin)dmin=d; 00080 } 00081 00082 as=1.*shIMax/shMax; 00083 at=1.*shJMax/shMax; 00084 pcale=.9*as/(smax-smin); 00085 if(pcale*(tmax-tmin)>.9*at)pcale=.9*at/(tmax-tmin); 00086 soff=.5*(as-pcale*(smax+smin)); 00087 toff=.5*(at-pcale*(tmax+tmin)); 00088 dcale=.9/(dmax-dmin); 00089 doff=.5*(1.-dcale*(dmax+dmin)); 00090 shsize(&pcale,&soff,&toff,&dcale,&doff); 00091 return; 00092 }
Here is the call graph for this function: |
|
Sets the width (in pixels) used when lines are drawn.
Definition at line 29 of file shlnonrm.c.
|
|
Sets the root of the output file name.
Definition at line 35 of file shname.c. 00036 { 00037 shOutputName=(char*)realloc(shOutputName,(strlen(name)+10)*sizeof(char)); 00038 strcpy(shOutputName,name); 00039 if(!strcmp(shOutputFormat,"tiff")) 00040 strcat(shOutputName,".tiff"); 00041 else 00042 strcat(shOutputName,".ps"); 00043 00044 return; 00045 }
|
|
Sets the format of the file written by shsave. The default is "postscript", but if libtiff is installed when sh is configured, this routine can be used to change the format to "tiff".
Definition at line 35 of file shtype.c. 00036 { 00037 shOutputFormat=(char*)realloc(shOutputFormat,(strlen(type)+1)*sizeof(char)); 00038 strcpy(shOutputFormat,type); 00039 00040 return; 00041 }
|
|
Sets the size of the screen buffer, if called BEFORE shinit. Otherwise it does nothing until the next call of shinit.
Definition at line 31 of file shres.c.
|
|
Sets a pixel in the frame buffer if zz is less than the value in the z-buffer. If the pixel is changed the the value in the z-buffer is set to zz.
Definition at line 33 of file shsetp.c. Referenced by shchar(), shclr(), shinit(), shline2s(), and shlnonrm(). 00034 { 00035 /* 00036 Set the pixel color and z-buffer. 00037 */ 00038 int index; 00039 00040 /*printf("shsetp %d %d %d %d %d %f\n",*ipix,*jpix,*ired,*igrn,*iblu,*zz);fflush(stdout); 00041 printf("shsetp, shZBuffer=0x%8.8x\n",shZBuffer);fflush(stdout);*/ 00042 if(*ipix<0||*jpix<0)return; 00043 if(*ipix>=shIMax||*jpix>=shJMax)return; 00044 00045 index=*ipix+shIMax*(*jpix); 00046 shRedBuffer[index]=*ired; 00047 shGreenBuffer[index]=*igrn; 00048 shBlueBuffer[index]=*iblu; 00049 shZBuffer[index]=*zz; 00050 00051 return; 00052 }
|
|
Directly sets the scales used.
Definition at line 152 of file shpers.c. Referenced by shscal(), and shview(). 00153 { 00154 00155 /* Entry to set scale factors. */ 00156 00157 shv_pcale=*scl; 00158 shv_soff=*s0; 00159 shv_toff=*t0; 00160 shv_doff=*d0; 00161 shv_dscl=*dsc; 00162 00163 return; 00164 }
|
|
Draws a tesselated sphere, 8*4**4 triangles, smoothed.
Definition at line 31 of file shsphere.c. 00032 { 00033 float *xt,*yt,*zt; 00034 float x[3]={0.,0.,0.}; 00035 float y[3]={0.,0.,0.}; 00036 float z[3]={0.,0.,0.}; 00037 float nrm[9]={0.,0.,0.,0.,0.,0.,0.,0.,0.}; 00038 float xa,ya,za,xb,yb,zb,xc,yc,zc; 00039 float x0,y0,z0,x1,y1,z1,x2,y2,z2; 00040 float d; 00041 int maxtri; 00042 int i; 00043 int itri,ntri,mtri; 00044 int n,ismooth; 00045 int nlevel; 00046 00047 /* Draws a tesselated sphere, 8*4**n triangles, if ismooth^=0 smoothed. */ 00048 00049 ismooth=1; 00050 nlevel=4; 00051 00052 maxtri=8; 00053 for(i=0;i<nlevel;i++)maxtri=maxtri*4; 00054 00055 xt=(float*)malloc(3*maxtri*sizeof(float)); 00056 yt=(float*)malloc(3*maxtri*sizeof(float)); 00057 zt=(float*)malloc(3*maxtri*sizeof(float)); 00058 00059 /* 1 */ 00060 ntri=0; 00061 xt[ 3*ntri]= 0.; 00062 yt[ 3*ntri]= 1.; 00063 zt[ 3*ntri]= 0.; 00064 xt[1+3*ntri]= 0.; 00065 yt[1+3*ntri]= 0.; 00066 zt[1+3*ntri]= 1.; 00067 xt[2+3*ntri]= 1.; 00068 yt[2+3*ntri]= 0.; 00069 zt[2+3*ntri]= 0.; 00070 ntri++; 00071 00072 /* 2 */ 00073 xt[ 3*ntri]= 0.; 00074 yt[ 3*ntri]= 1.; 00075 zt[ 3*ntri]= 0.; 00076 xt[1+3*ntri]=-1.; 00077 yt[1+3*ntri]= 0.; 00078 zt[1+3*ntri]= 0.; 00079 xt[2+3*ntri]= 0.; 00080 yt[2+3*ntri]= 0.; 00081 zt[2+3*ntri]= 1.; 00082 ntri++; 00083 00084 /* 3 */ 00085 xt[ 3*ntri]= 0.; 00086 yt[ 3*ntri]= 1.; 00087 zt[ 3*ntri]= 0.; 00088 xt[1+3*ntri]= 0.; 00089 yt[1+3*ntri]= 0.; 00090 zt[1+3*ntri]=-1.; 00091 xt[2+3*ntri]=-1.; 00092 yt[2+3*ntri]= 0.; 00093 zt[2+3*ntri]= 0.; 00094 ntri++; 00095 00096 /* 4 */ 00097 xt[ 3*ntri]= 0.; 00098 yt[ 3*ntri]= 1.; 00099 zt[ 3*ntri]= 0.; 00100 xt[1+3*ntri]= 1.; 00101 yt[1+3*ntri]= 0.; 00102 zt[1+3*ntri]= 0.; 00103 xt[2+3*ntri]= 0.; 00104 yt[2+3*ntri]= 0.; 00105 zt[2+3*ntri]=-1.; 00106 ntri++; 00107 00108 /* 5 */ 00109 xt[ 3*ntri]= 0.; 00110 yt[ 3*ntri]=-1.; 00111 zt[ 3*ntri]= 0.; 00112 xt[2+3*ntri]= 0.; 00113 yt[2+3*ntri]= 0.; 00114 zt[2+3*ntri]= 1.; 00115 xt[1+3*ntri]= 1.; 00116 yt[1+3*ntri]= 0.; 00117 zt[1+3*ntri]= 0.; 00118 ntri++; 00119 00120 /* 6 */ 00121 xt[ 3*ntri]= 0.; 00122 yt[ 3*ntri]=-1.; 00123 zt[ 3*ntri]= 0.; 00124 xt[2+3*ntri]=-1.; 00125 yt[2+3*ntri]= 0.; 00126 zt[2+3*ntri]= 0.; 00127 xt[1+3*ntri]= 0.; 00128 yt[1+3*ntri]= 0.; 00129 zt[1+3*ntri]= 1.; 00130 ntri++; 00131 00132 /* 7 */ 00133 xt[ 3*ntri]= 0.; 00134 yt[ 3*ntri]=-1.; 00135 zt[ 3*ntri]= 0.; 00136 xt[2+3*ntri]= 0.; 00137 yt[2+3*ntri]= 0.; 00138 zt[2+3*ntri]=-1.; 00139 xt[1+3*ntri]=-1.; 00140 yt[1+3*ntri]= 0.; 00141 zt[1+3*ntri]= 0.; 00142 ntri++; 00143 00144 /* 8 */ 00145 xt[ 3*ntri]= 0.; 00146 yt[ 3*ntri]=-1.; 00147 zt[ 3*ntri]= 0.; 00148 xt[2+3*ntri]= 1.; 00149 yt[2+3*ntri]= 0.; 00150 zt[2+3*ntri]= 0.; 00151 xt[1+3*ntri]= 0.; 00152 yt[1+3*ntri]= 0.; 00153 zt[1+3*ntri]=-1.; 00154 ntri++; 00155 00156 if(nlevel>0) 00157 { 00158 for(i=0;i<nlevel;i++) 00159 { 00160 mtri=ntri; 00161 for(itri=0;itri<ntri;itri++) 00162 { 00163 x0=xt[3*itri]; 00164 y0=yt[3*itri]; 00165 z0=zt[3*itri]; 00166 x1=xt[1+3*itri]; 00167 y1=yt[1+3*itri]; 00168 z1=zt[1+3*itri]; 00169 x2=xt[2+3*itri]; 00170 y2=yt[2+3*itri]; 00171 z2=zt[2+3*itri]; 00172 00173 xa=.5*(x0+x1); 00174 ya=.5*(y0+y1); 00175 za=.5*(z0+z1); 00176 d=1./sqrt(xa*xa+ya*ya+za*za); 00177 xa=xa*d; 00178 ya=ya*d; 00179 za=za*d; 00180 00181 xb=.5*(x1+x2); 00182 yb=.5*(y1+y2); 00183 zb=.5*(z1+z2); 00184 d=1./sqrt(xb*xb+yb*yb+zb*zb); 00185 xb=xb*d; 00186 yb=yb*d; 00187 zb=zb*d; 00188 00189 xc=.5*(x2+x0); 00190 yc=.5*(y2+y0); 00191 zc=.5*(z2+z0); 00192 d=1./sqrt(xc*xc+yc*yc+zc*zc); 00193 xc=xc*d; 00194 yc=yc*d; 00195 zc=zc*d; 00196 00197 xt[ 3*itri]=x0; 00198 yt[ 3*itri]=y0; 00199 zt[ 3*itri]=z0; 00200 xt[1+3*itri]=xa; 00201 yt[1+3*itri]=ya; 00202 zt[1+3*itri]=za; 00203 xt[2+3*itri]=xc; 00204 yt[2+3*itri]=yc; 00205 zt[2+3*itri]=zc; 00206 00207 xt[ 3*mtri]=xa; 00208 yt[ 3*mtri]=ya; 00209 zt[ 3*mtri]=za; 00210 xt[1+3*mtri]=x1; 00211 yt[1+3*mtri]=y1; 00212 zt[1+3*mtri]=z1; 00213 xt[2+3*mtri]=xb; 00214 yt[2+3*mtri]=yb; 00215 zt[2+3*mtri]=zb; 00216 mtri++; 00217 00218 xt[ 3*mtri]=xb; 00219 yt[ 3*mtri]=yb; 00220 zt[ 3*mtri]=zb; 00221 xt[1+3*mtri]=x2; 00222 yt[1+3*mtri]=y2; 00223 zt[1+3*mtri]=z2; 00224 xt[2+3*mtri]=xc; 00225 yt[2+3*mtri]=yc; 00226 zt[2+3*mtri]=zc; 00227 mtri++; 00228 00229 xt[ 3*mtri]=xa; 00230 yt[ 3*mtri]=ya; 00231 zt[ 3*mtri]=za; 00232 xt[1+3*mtri]=xb; 00233 yt[1+3*mtri]=yb; 00234 zt[1+3*mtri]=zb; 00235 xt[2+3*mtri]=xc; 00236 yt[2+3*mtri]=yc; 00237 zt[2+3*mtri]=zc; 00238 mtri++; 00239 } 00240 ntri=mtri; 00241 } 00242 } 00243 00244 for(itri=0;itri<ntri;itri++) 00245 { 00246 for(i=0;i<3;i++) 00247 { 00248 nrm[0+3*i]= xt[i+3*itri]; 00249 nrm[1+3*i]= yt[i+3*itri]; 00250 nrm[2+3*i]= zt[i+3*itri]; 00251 x[i]=(*xo)+(*r)*xt[i+3*itri]; 00252 y[i]=(*yo)+(*r)*yt[i+3*itri]; 00253 z[i]=(*zo)+(*r)*zt[i+3*itri]; 00254 } 00255 n=3; 00256 if(ismooth!=0)shpgnrm(&n,x,y,z,nrm); 00257 else if(ismooth<0)shpl(&n,x,y,z); 00258 else shpg(&n,x,y,z); 00259 } 00260 00261 free(xt); 00262 free(yt); 00263 free(zt); 00264 00265 return; 00266 }
|
|
Set the surface properties for shading.
Definition at line 29 of file shsrfp.c. Referenced by shinit(). 00030 { 00031 00032 /* This Routine Sets the surface properties used for the Shading */ 00033 00034 /* a ambient intensity. */ 00035 /* d difuse intensity. */ 00036 /* s specular intensity. */ 00037 /* n specular exponent. */ 00038 00039 sh_am=*a; 00040 sh_ad=*d; 00041 sh_as=*s; 00042 sh_nd=*n; 00043 00044 return; 00045 }
|
|
Draws a horizontal character string at a point.
Definition at line 39 of file shstr.c. References shpers(). 00040 { 00041 float xx=0.; 00042 float yy=0.; 00043 float zz=0.; 00044 00045 SHstr=(char**)realloc(SHstr,(SHnstr+1)*sizeof(char*)); 00046 SHxstr=(int*)realloc(SHxstr,(SHnstr+1)*sizeof(int)); 00047 SHystr=(int*)realloc(SHystr,(SHnstr+1)*sizeof(int)); 00048 SHzstr=(double*)realloc(SHzstr,(SHnstr+1)*sizeof(double)); 00049 00050 shpers(&x,&y,&z,&xx,&yy,&zz); 00051 00052 SHxstr[SHnstr]=xx*shMax+.5; 00053 SHystr[SHnstr]=yy*shMax+.5; 00054 SHzstr[SHnstr]=zz; 00055 SHstr[SHnstr]=(char*)malloc((strlen(str)+1)*sizeof(char)); 00056 strcpy(SHstr[SHnstr],str); 00057 SHnstr++; 00058 00059 return; 00060 }
Here is the call graph for this function: |
|
Adds a horizontal character string in screen coordinates.
Definition at line 34 of file shstrs.c. 00035 { 00036 SHstr=(char**)realloc(SHstr,(SHnstr+1)*sizeof(char*)); 00037 SHxstr=(int*)realloc(SHxstr,(SHnstr+1)*sizeof(int)); 00038 SHystr=(int*)realloc(SHystr,(SHnstr+1)*sizeof(int)); 00039 SHzstr=(double*)realloc(SHzstr,(SHnstr+1)*sizeof(double)); 00040 00041 SHxstr[SHnstr]=xx; 00042 SHystr[SHnstr]=yy; 00043 SHzstr[SHnstr]=-1.; 00044 SHstr[SHnstr]=(char*)malloc((strlen(str)+1)*sizeof(char)); 00045 strcpy(SHstr[SHnstr],str); 00046 SHnstr++; 00047 00048 return; 00049 }
|
|
A convenience routine to draw a triangle.
Definition at line 34 of file shtri.c. References shpg(). 00035 { 00036 00037 /* Shade a triangle. Note this just calls shpg.*/ 00038 00039 float x[3]={0.,0.,0.}; 00040 float y[3]={0.,0.,0.}; 00041 float z[3]={0.,0.,0.}; 00042 int n; 00043 00044 x[0]=*xt1; 00045 x[1]=*xt2; 00046 x[2]=*xt3; 00047 y[0]=*yt1; 00048 y[1]=*yt2; 00049 y[2]=*yt3; 00050 z[0]=*zt1; 00051 z[1]=*zt2; 00052 z[2]=*zt3; 00053 n=3; 00054 shpg(&n,x,y,z); 00055 00056 return; 00057 }
Here is the call graph for this function: |
|
A convenience routine which sets the edge and face colors for polygons to the same color.
Definition at line 28 of file shtric.c. References shbec(), shbgc(), shpec(), and shpgc(). Referenced by shinit(). 00029 { 00030 shpgc(r,g,b); 00031 shpec(r,g,b); 00032 shbgc(r,g,b); 00033 shbec(r,g,b); 00034 return; 00035 }
Here is the call graph for this function: |
|
Performs the inverse of the perspective transformation.
Definition at line 60 of file shpers.c. Referenced by shlnonrm(). 00061 { 00062 float c1,c2,c3; 00063 00064 /* Entry to invert perspective transform. */ 00065 00066 c1=shv_d*(*dd-shv_doff)/(*dd-shv_doff+shv_dscl*(shv_l-shv_d)); 00067 c2=(*ss-shv_soff)*(c1-shv_d)/(shv_l-shv_d)/shv_pcale; 00068 c3=(*tt-shv_toff)*(c1-shv_d)/(shv_l-shv_d)/shv_pcale; 00069 00070 *xx=shv_x0+c1*shv_n11+c2*shv_n21+c3*shv_n31; 00071 *yy=shv_y0+c1*shv_n12+c2*shv_n22+c3*shv_n32; 00072 *zz=shv_z0+c1*shv_n13+c2*shv_n23+c3*shv_n33; 00073 00074 return; 00075 }
|
|
A convenience routine that calls shsize, shvw and shscal.
Definition at line 34 of file shview.c. References shscal(), shsize(), and shvw(). Referenced by shinit(). 00035 { 00036 float zero=0.; 00037 float one=0.; 00038 00039 /* Set view point and scale. */ 00040 00041 shsize(&one,&zero,&zero,&one,&zero); 00042 shvw(dist,alpha,beta,xmin,xmax,ymin,ymax,zmin,zmax); 00043 shscal(xmin,xmax,ymin,ymax,zmin,zmax); 00044 return; 00045 }
Here is the call graph for this function: |
|
Sets the view point for the perspective transformation.
Definition at line 90 of file shpers.c. Referenced by shview(). 00091 { 00092 float a,b,pi; 00093 00094 /* Entry to set view point. */ 00095 00096 shv_x0=((*xmin)+(*xmax))/2.; 00097 shv_y0=((*ymin)+(*ymax))/2.; 00098 shv_z0=((*zmin)+(*zmax))/2.; 00099 00100 pi=3.1415926; 00101 a=(*alpha-90.)*pi/180.; 00102 b=*beta*pi/180.; 00103 00104 shv_n11=cos(b)*cos(a); 00105 shv_n12=cos(b)*sin(a); 00106 shv_n13=sin(b); 00107 00108 shv_eye[0]=*dist*shv_n11; 00109 shv_eye[1]=*dist*shv_n12; 00110 shv_eye[2]=*dist*shv_n13; 00111 00112 shv_n21=-sin(a); 00113 shv_n22=cos(a); 00114 shv_n23=0.0; 00115 00116 shv_n31=-sin(b)*cos(a); 00117 shv_n32=-sin(b)*sin(a); 00118 shv_n33=cos(b); 00119 00120 shv_d=*dist; 00121 shv_l=0.75*shv_d; 00122 return; 00123 }
|