src/shpgnrm.c

00001 
00006 /*
00007  *  PROGRAM NAME:  sh
00008  *
00009  *  (c) COPYRIGHT INTERNATIONAL BUSINESS MACHINES
00010  *  CORPORATION 12/1/2001.  ALL RIGHTS RESERVED.
00011  *
00012  *  Please refer to the LICENSE file in the top directory
00013  *
00014  *      author: Mike Henderson mhender@watson.ibm.com
00015  */
00016 
00017 static char *id="@(#) $Id: shpgnrm.c,v 1.2 2006/08/17 19:28:17 mhender Exp $";
00018 
00019 #include <shInternal.h>
00020 #include <math.h>
00021 #include <stdio.h>
00022 
00032 void shpgnrm(int *nv,float *xt,float *yt,float *zt,float *nrmt)
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  }

Generated on Thu Aug 17 15:29:43 2006 for sh by  doxygen 1.4.6