src/shpg.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: shpg.c,v 1.2 2006/08/17 19:28:17 mhender Exp $";
00018 
00019 #include <shInternal.h>
00020 #include <math.h>
00021 
00030 void shpg(int *nv,float *xt,float *yt,float *zt)
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  }

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