1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| void Silhouette3DS( lib3ds_obj *obj, float *lp, GLuint * g_lst )
{
SetConnectivity3DS(obj);
*g_lst = glGenLists (2);
glNewList (*g_lst, GL_COMPILE);
int i , j;
vertex_type A, An, B, Bn, C, Cn, N;
for (i=0; i<obj->polygons_qty; i++)
{
if( obj->polygon[i].normal[0]* -lp[0]
+obj->polygon[i].normal[1]* -lp[1]
+obj->polygon[i].normal[2]* -lp[2] <0)
obj->polygon[i].visible = GL_TRUE ;
else
obj->polygon[i].visible = GL_FALSE ;
}
glPushMatrix ();
glRotatef (90, 1, 0, 0);
for (i = 0; i < obj->polygons_qty; i++)
{
if ( (obj->polygon[i].visible ) )
{
for (j=0;j<3;j++)
{
int k = obj->polygon[i].neigh[j];
if ( (obj->polygon[k].visible == GL_FALSE))
{
//si mon voisin n'est pas visible, c'est que j'ai un edge
// je doit le dessiner
// get the three vertices of the triangle
A = obj->vertex[obj->polygon[i].a];
B = obj->vertex[obj->polygon[i].b];
C = obj->vertex[obj->polygon[i].c];
An = obj->vertex[obj->polygon[k].a];
Bn = obj->vertex[obj->polygon[k].b];
Cn = obj->vertex[obj->polygon[k].c];
;
// Compute normal
N.x = (B.y - A.y) * (C.z - A.z) - (C.y - A.y) * (B.z - A.z);
N.y = -(B.x - A.x) * (C.z - A.z) + (C.x - A.x) * (B.z - A.z);
N.z = (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y);
/*je test chaque point pour trouver la face commune aux 2 polygones*/
FaceCommune (A, B, C, An, Bn, Cn, N);
FaceCommune (B, A, C, An, Bn, Cn, N);
FaceCommune (C, A, B, An, Bn, Cn, N);
}
}
}
}
glPopMatrix ();
glEndList ();
} |
Partager