home *** CD-ROM | disk | FTP | other *** search
- #include "Face.h"
-
- #include "vectormath.h"
- #include "stdio.h"
-
- Face::Face(){
- mesh=NULL;
- material=NULL;
-
- vertices=NULL;
- colors=NULL;
- normals=NULL;
- texCoords1=NULL;
- texCoords2=NULL;
- indices=NULL;
- indIndex=0;
- numVertices=0;
- numColors=0;
- numNormals=0;
- numTexCoords=0;
- numIndices=0;
-
- vectorInit3d(0.0, 0.0, 0.0, normal);
- }
-
- Face::~Face(){
- clearFace();
- }
-
- void Face::clearFace(){
- // int i;
-
- if(vertices!=NULL){
- delete[] vertices;
- vertices=NULL;
- numVertices=0;
- }
- if(colors!=NULL){
- delete[] colors;
- colors=NULL;
- numColors=0;
- }
- if(normals!=NULL){
- delete[] normals;
- normals=NULL;
- numNormals=0;
- }
- if(texCoords1!=NULL || texCoords2!=NULL){
- delete[] texCoords1;
- texCoords1=NULL;
- delete[] texCoords2;
- texCoords2=NULL;
- numTexCoords=0;
- }
- if(indices!=NULL){
- delete[] indices;
- indices=NULL;
- numIndices=0;
- }
-
- }
- void Face::calcNormal(){
- if(numVertices<3)
- return;
-
- int ind1=0;
- int ind2=3;
- int ind3=6;
- vec3_t v1, v2;
- vectorSub3d(&vertices[ind2], &vertices[ind1], v1);
- vectorSub3d(&vertices[ind3], &vertices[ind1], v2);
- vectorCrossP3d(v1, v2, normal);
- vectorNormalize3d(normal, normal);
- }
-
- void Face::dump(){
- int i;
-
- printf("vertices, normals and texCoords:\n");
- for(i=0;i<numVertices;i++){
- printf("[%f %f %f] [%f %f %f] [%f %f] [%f %f]\n", vertices[i*3+0],vertices[i*3+1],vertices[i*3+2],
- normals[i*3+0],normals[i*3+1],normals[i*3+2],
- texCoords1[i*2+0], texCoords1[i*2+1],
- texCoords2[i*2+0], texCoords2[i*2+1]);
- }
- }
-
-