Patch Code Example
 
 
 

Below is some sample code that shows the interpolation of the surface points, the book keeping code for shared edges, the construction of the mesh faces, the handling of texture vertices and faces, and how bind patches are handled.

// vertices ( a b c d ) are in counter clockwise order when viewed from
// outside the surface
static void MakeQuad(int nVerts, Face *f,
          int a, int b , int c , int d,
          DWORD sm, MtlID m,
          int e1a, int e1b, int e1c,
          int e2a, int e2b, int e2c,
          int hide )
{
   //DebugPrint("Make quad %d %d %d %d \n",a,b,c,d);
   assert(a<nVerts);
   assert(b<nVerts);
   assert(c<nVerts);
   assert(d<nVerts);
   f[0].setVerts( a, b, c);
   f[0].setSmGroup(sm);
   f[0].setEdgeVisFlags(e1a,e1b,e1c);
   f[0].setMatID(m);
   f[0].SetHide(hide);
   f[1].setVerts( c, d, a);
   f[1].setSmGroup(sm);
   f[1].setEdgeVisFlags(e2a,e2b,e2c);
   f[1].setMatID(m);
   f[1].SetHide(hide);
}
 
//watje 12-8-98
#define MAKE_QUAD(na,nb,nc,nd,sm,m,e1a,e1b,e1c,e2a,e2b,e2c,hide) { MakeQuad(nVerts,&(mesh.faces[face]),na, nb, nc, nd, sm, m,e1a,e1b,e1c,e2a,e2b,e2c,hide); face+=2; }
 
// Make texture face quad
static void MakeTQuad(int chan, int nTVerts, TVFace *f, int a, int b , int c , int d)
{
   assert(a<nTVerts);
   assert(b<nTVerts);
   assert(c<nTVerts);
   assert(d<nTVerts);
   f[0].setTVerts( a, b, c);
   f[1].setTVerts( c, d, a);
}
 
#define MAKE_TQUAD(ch,na,nb,nc,nd) { MakeTQuad(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),na, nb, nc, nd); tface+=2; }
// vertices ( a b c d ) are in counter clockwise order when viewed from
// outside the surface
//watje 12-8-98
staticvoidMakeTri(intnVerts, Face *f,
          int a, int b, int c,
          DWORD sm, MtlID m,
          int ea, int eb, int ec,
          int hide)
{
   assert(a<nVerts);
   assert(b<nVerts);
   assert(c<nVerts);
  
   //DebugPrint("Making tri %d %d %d \n",a,b,c);
   f->setVerts( a, b, c);
   f->setSmGroup(sm);
   f->setEdgeVisFlags(ea,eb,ec);
   f->setMatID(m);
   f->SetHide(hide);
}
//watje 12-8-98
#define MAKE_TRI(na,nb,nc,sm,mat,ea,eb,ec,hide) { MakeTri(nVerts,&(mesh.faces[face]),na, nb, nc, sm, mat,ea,eb,ec,hide); face++; }
 
#define MAKE_QUAD_SPECIAL(na,nm,nb,nc,sm,mat,ea,eb,ec,ed,hide) \
{ MakeTri(nVerts,&(mesh.faces[face]),na, nm, nc, sm, mat,ea,0,ed,hide); face++; \
MakeTri(nVerts,&(mesh.faces[face]),nm, nb, nc, sm, mat,eb,ec,0,hide); face++; }
 
#define MAKE_PENTA_EDGE1(na,nm,nb,nc,nd,sm,mat,ea,eb,ec,ed,hide) { \
MakeTri(nVerts,&(mesh.faces[face]),na, nm, nc, sm, mat,ea,0,0,hide); face++; \
MakeTri(nVerts,&(mesh.faces[face]),nm, nb, nc, sm, mat,ea,eb,0,hide); face++; \
MakeTri(nVerts,&(mesh.faces[face]),nc, nd, na, sm, mat,ec,ed,0,hide); face++; \
}
 
#define MAKE_PENTA_EDGE2(na,nb,nm,nc,nd,sm,mat,ea,eb,ec,ed,hide) { \
MakeTri(nVerts,&(mesh.faces[face]),na,nb,nm, sm, mat,ea,eb,0,hide); face++; \
MakeTri(nVerts,&(mesh.faces[face]),na, nm, nc, sm, mat,0,eb,0,hide); face++; \
MakeTri(nVerts,&(mesh.faces[face]),nc, nd, na, sm, mat,ec,ed,0,hide); face++; \
} 
 
#define MAKE_PENTA_EDGE3(na,nb,nc,nm,nd,sm,mat,ea,eb,ec,ed,hide) { \
MakeTri(nVerts,&(mesh.faces[face]),na,nb,nc, sm, mat,ea,eb,0,hide); face++; \
MakeTri(nVerts,&(mesh.faces[face]),nc, nm, na, sm, mat,ec,0,0,hide); face++; \
MakeTri(nVerts,&(mesh.faces[face]),nm, nd, na, sm, mat,ec,ed,0,hide); face++; \
} 
 
#define MAKE_PENTA_EDGE4(na,nb,nc,nd,nm,sm,mat,ea,eb,ec,ed,hide) { \
MakeTri(nVerts,&(mesh.faces[face]),na,nb,nc, sm, mat,ea,eb,0,hide); face++; \
MakeTri(nVerts,&(mesh.faces[face]),nc, nd, nm, sm, mat,ec,ed,0,hide); face++; \
MakeTri(nVerts,&(mesh.faces[face]),nc, nm, na, sm, mat,0,ed,0,hide); face++; \
}
 
 
// Make texture face triangle
static void MakeTTri(int chan, int nTVerts, TVFace *f, int a, int b, int c)
{
   assert(a<nTVerts);
   assert(b<nTVerts);
   assert(c<nTVerts);
   f->setTVerts( a, b, c);
}
#define MAKE_TTRI(ch,na,nb,nc) { MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),na, nb, nc); tface++; }
#define MAKE_TQUAD_SPECIAL(ch,na,nm,nb,nc) \
{ MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),na, nm, nc); tface++; \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),nm, nb, nc); tface++; \
tvertHookStart++; }
 
#define MAKE_TPENTA_EDGE1(ch,na,nm,nb,nc,nd) \
{ \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),na, nm, nc); tface++; \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),nm, nb, nc); tface++; \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),nc, nd, na); tface++; \
tvertHookStart++; }
 
#define MAKE_TPENTA_EDGE2(ch,na,nb,nm,nc,nd) \
{ \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),na, nb, nm); tface++; \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),na, nm, nc); tface++; \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),nc, nd, na); tface++; \
tvertHookStart++; }
 
#define MAKE_TPENTA_EDGE3(ch,na,nb,nc,nm,nd) \
{ \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),na, nb, nc); tface++; \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),nc, nm, na); tface++; \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),nm, nd, na); tface++; \
tvertHookStart++; }
 
#define MAKE_TPENTA_EDGE4(ch,na,nb,nc,nd,nm) \
{ \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),na, nb, nc); tface++; \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),nc, nd, nm); tface++; \
MakeTTri(ch, nTVerts[ch], &(mesh.mapFaces(ch)[tface]),nc, nm, na); tface++; \
tvertHookStart++; }