//splits the current line into triangles. //returns the number of triangles this line creates int split_polygon(FILE *fp, jmesh *jm){ int nVerts; static int which_tri=0; int temp=fscanf(fp, "%d", &nVerts); //how many vertices do we have for this face? if(temp != 1){ return -1; } //get the vertices int verts[nVerts]; for(int i=0; i < nVerts; i++){ temp=fscanf(fp, "%d", &verts[i]); if(temp != 1){ return -1; } } //put these into triangles for(int i=1; i < nVerts-1; i++, which_tri++){ *getV1(jm, which_tri) = verts[0]; *getV2(jm, which_tri) = verts[i]; *getV3(jm, which_tri) = verts[i+1]; } return nVerts - 2; }
bool Triangle::operator!=(const Triangle &t) const { if (t.getVector() == normal && t.getV1() == getV1() && t.getV2() == getV2() && t.getV3() == getV3()) return false; return true; }
//fills edges with two displacement vectors //from face i void get_edges(jmesh *jm, int i, float *edges){ float v1[3], v2[3], v3[3]; //get the xyz of each vertex of the triangle v1[0] = *getX(jm, *getV1(jm, i)); v2[0] = *getX(jm, *getV2(jm, i)); v3[0] = *getX(jm, *getV3(jm, i)); v1[1] = *getY(jm, *getV1(jm, i)); v2[1] = *getY(jm, *getV2(jm, i)); v3[1] = *getY(jm, *getV3(jm, i)); v1[2] = *getZ(jm, *getV1(jm, i)); v2[2] = *getZ(jm, *getV2(jm, i)); v3[2] = *getZ(jm, *getV3(jm, i)); //compute V2-V1, V3-V1 edges[0] = v2[0]-v1[0]; edges[1] = v2[1]-v1[1]; edges[2] = v2[2]-v1[2]; edges[3] = v3[0]-v1[0]; edges[4] = v3[1]-v1[1]; edges[5] = v3[2]-v1[2]; }