home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / Face.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-06  |  1.6 KB  |  88 lines

  1. #include "Face.h"
  2.  
  3. #include "vectormath.h"
  4. #include "stdio.h"
  5.  
  6. Face::Face(){
  7.     mesh=NULL;
  8.     material=NULL;
  9.  
  10.     vertices=NULL;
  11.     colors=NULL;
  12.     normals=NULL;
  13.     texCoords1=NULL;
  14.     texCoords2=NULL;
  15.     indices=NULL;
  16.     indIndex=0;
  17.     numVertices=0;
  18.     numColors=0;
  19.     numNormals=0;
  20.     numTexCoords=0;
  21.     numIndices=0;
  22.  
  23.     vectorInit3d(0.0, 0.0, 0.0, normal);
  24. }
  25.  
  26. Face::~Face(){
  27.     clearFace();
  28. }
  29.  
  30. void Face::clearFace(){
  31. //    int i;
  32.  
  33.     if(vertices!=NULL){
  34.         delete[] vertices;
  35.         vertices=NULL;
  36.         numVertices=0;
  37.     }
  38.     if(colors!=NULL){
  39.         delete[] colors;
  40.         colors=NULL;
  41.         numColors=0;
  42.     }
  43.     if(normals!=NULL){
  44.         delete[] normals;
  45.         normals=NULL;
  46.         numNormals=0;
  47.     }
  48.     if(texCoords1!=NULL || texCoords2!=NULL){
  49.         delete[] texCoords1;
  50.         texCoords1=NULL;
  51.         delete[] texCoords2;
  52.         texCoords2=NULL;
  53.         numTexCoords=0;
  54.     }
  55.     if(indices!=NULL){
  56.         delete[] indices;
  57.         indices=NULL;
  58.         numIndices=0;
  59.     }
  60.  
  61. }
  62. void Face::calcNormal(){
  63.     if(numVertices<3)
  64.         return;
  65.  
  66.     int ind1=0;
  67.     int ind2=3;
  68.     int ind3=6;
  69.     vec3_t v1, v2;
  70.     vectorSub3d(&vertices[ind2], &vertices[ind1], v1);
  71.     vectorSub3d(&vertices[ind3], &vertices[ind1], v2);
  72.     vectorCrossP3d(v1, v2, normal);
  73.     vectorNormalize3d(normal, normal);
  74. }
  75.  
  76. void Face::dump(){
  77.     int i;
  78.  
  79.     printf("vertices, normals and texCoords:\n");
  80.     for(i=0;i<numVertices;i++){
  81.         printf("[%f %f %f] [%f %f %f] [%f %f] [%f %f]\n", vertices[i*3+0],vertices[i*3+1],vertices[i*3+2],
  82.                                                     normals[i*3+0],normals[i*3+1],normals[i*3+2],
  83.                                                     texCoords1[i*2+0], texCoords1[i*2+1],
  84.                                                     texCoords2[i*2+0], texCoords2[i*2+1]);
  85.     }
  86. }
  87.  
  88.