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 77 78 79 80 81 82 83 84 85 86 87 88 89
|
glBegin(GL_TRIANGLES);
// mes 3 points de chaque triangle
P1.x = vdata[0] = pMere->m_vol.points[pMere->m_vol.Triangles[i].x].Pt.x;
P1.y = vdata[1] = pMere->m_vol.points[pMere->m_vol.Triangles[i].x].Pt.y;
P1.z = vdata[2] = pMere->m_vol.points[pMere->m_vol.Triangles[i].x].Pt.z;
P2.x = vdata[0] = pMere->m_vol.points[pMere->m_vol.Triangles[i].y].Pt.x;
P2.y = vdata[1] = pMere->m_vol.points[pMere->m_vol.Triangles[i].y].Pt.y;
P2.z = vdata[2] = pMere->m_vol.points[pMere->m_vol.Triangles[i].y].Pt.z;
P3.x = vdata[0] = pMere->m_vol.points[pMere->m_vol.Triangles[i].z].Pt.x;
P3.y = vdata[1] = pMere->m_vol.points[pMere->m_vol.Triangles[i].z].Pt.y;
P3.z = vdata[2] = pMere->m_vol.points[pMere->m_vol.Triangles[i].z].Pt.z;
glColor3f(0.7f,0.7f,0.7f);
// 2 vecteurs du plan partant de P1
V1.x = P2.x-P1.x;
V1.y = P2.y-P1.y;
V1.z = P2.z-P1.z;
V2.x = P3.x-P1.x;
V2.y = P3.y-P1.y;
V2.z = P3.z-P1.z;
// produit scalaire
vdata[0] = (V1.y*V2.z)-(V1.z*V2.y);
vdata[1] = (V1.z*V2.x)-(V1.x*V2.z);
vdata[2] = (V1.x*V2.y)-(V1.y*V2.x);
norm = sqrt(vdata[0]*vdata[0] + vdata[1]*vdata[1] + vdata[2]*vdata[2]);
vdata[0]/=norm;
vdata[1]/=norm;
vdata[2]/=norm;
// normale en P1
glNormal3fv(&vdata[0]);
vdata[0] = P1.x;
vdata[1] = P1.y;
vdata[2] = P1.z;
glVertex3fv(&vdata[0]);
glColor3f(0.7f,0.7f,0.7f);
// 2 vecteurs du plan partant de P2
V1.x = P3.x-P2.x;
V1.y = P3.y-P2.y;
V1.z = P3.z-P2.z;
V2.x = P1.x-P2.x;
V2.y = P1.y-P2.y;
V2.z = P1.z-P2.z;
// produit scalaire
vdata[0] = (V1.y*V2.z)-(V1.z*V2.y);
vdata[1] = (V1.z*V2.x)-(V1.x*V2.z);
vdata[2] = (V1.x*V2.y)-(V1.y*V2.x);
norm = sqrt(vdata[0]*vdata[0] + vdata[1]*vdata[1] + vdata[2]*vdata[2]);
vdata[0]/=norm;
vdata[1]/=norm;
vdata[2]/=norm;
// normale en P2
glNormal3fv(&vdata[0]);
vdata[0] = P2.x;
vdata[1] = P2.y;
vdata[2] = P2.z;
glVertex3fv(&vdata[0]);
glColor3f(0.7f,0.7f,0.7f);
// 2 vecteurs du plan partant de P3
V1.x = P1.x-P3.x;
V1.y = P1.y-P3.y;
V1.z = P1.z-P3.z;
V2.x = P2.x-P3.x;
V2.y = P2.y-P3.y;
V2.z = P2.z-P3.z;
// produit scalaire
vdata[0] = (V1.y*V2.z)-(V1.z*V2.y);
vdata[1] = (V1.z*V2.x)-(V1.x*V2.z);
vdata[2] = (V1.x*V2.y)-(V1.y*V2.x);
norm = sqrt(vdata[0]*vdata[0] + vdata[1]*vdata[1] + vdata[2]*vdata[2]);
vdata[0]/=norm;
vdata[1]/=norm;
vdata[2]/=norm;
// normale en P3
glNormal3fv(&vdata[0]);
vdata[0] = P3.x;
vdata[1] = P3.y;
vdata[2] = P3.z;
glVertex3fv(&vdata[0]);
glEnd(); |
Partager