Salut a tous, je dois réaliser un modeleur 3D en C.
Mon prof m'a obligé à utliser le C pour le faire et je dois donc utliser xlib.
En fait, c'est l'interface mon problème :
j'arrive pas gérer independamment les unes des autres 4 régions différentes sur mon interface. Vous pouvez m'aidez please?
Voila mon code :
void expose()
{
new=0;
if ((fp = fopen("test.txt","r" )) == NULL) {
printf("Probleme\n" );
}
else {
np=0;
nl=0;
while ((fpc = fgetc(fp)) != EOF ) {
if (fpc == 10 ) {
/* Fin de ligne */
new=0; separator=0;
}
else {
if (new==0) {
if (fpc != 80 && fpc != 76) {
fprintf (stderr, "Ni P ni L\n" );
}
else { /*differentitation d'une ligne point d'une ligne arete*/
fprintf (stderr, " \n" );
if(fpc == 80) {
ltype='P'; np=np+1;
if (np>npm) {
fprintf (stderr, "Trop de points \n" ); /*Trop de points rentrés*/
exit(0);
}
npa=np;
}
else {
ltype='L';nl=nl+1;
if (np>nlm) {
fprintf (stderr, "Trop de lignes \n" ); /*Trop de lignes rentrees*/
exit(0);
}
nla=nl;
}
new=1;separator=0;
}
}
else {
if (ltype=='P') {
if (fpc==';') {separator=separator+1;
}
else {
if (fpc<'0'|| fpc>'9') {
fprintf(stderr, "Error point %d\n",np);
}
else { /*Analyse des points*/
fpn=fpc-48;
switch (separator) {
case 0: px[np]=px[np]*10+fpn;break;
case 1: py[np]=py[np]*10+fpn;break;
case 2: pz[np]=pz[np]*10+fpn;break;}
}
}
}
else {
if (fpc==';') {separator=separator+1;
}
else {
if (fpc<'0' || fpc>'9' && fpc==76){
fprintf(stderr, "Error ligne \n" );
}
else { /*Analyse des aretes*/
fpn=fpc-48;
switch (separator){
case 0: A[nl]= A[nl]*10+fpn;break;
case 1: B[nl]= B[nl]*10+fpn;break;}
}
}
}
}
}
}
}
np=1;
while (np<=npa) {
printf("Point %d x=%d y=%d z=%d\n", np, px[np], py[np], pz[np]);np=np+1;}
np=1;
while(np<=npa){
//coordonnees en cm dans le repere de l'ecran//
x2d[np]=px[np]*d/pz[np];
y2d[np]=py[np]*d/pz[np];
//coordonnes en pixel dans le repere de l'ecran//
xe[np]=x2d*DisplayWidth(display,screen)/DisplayWidthMM(display,screen);
ye[np]=y2d*DisplayHeight(display,screen)/DisplayHeightMM(display,screen);
Xe[np]=xe[np];
Ye[np]=ye[np];
printf("Nouvelles coordonnees: Xe=%d Ye=%d\n",Xe[np],Ye[np]);
np=np+1;}
nl=1;
for (nl=1;nl<=nla;nl++){
printf("Ligne %d A=%d B=%d\n",nl,A[nl],B[nl]);
if (A[nl]>npa || B[nl]>npa) {
printf("les points %d et %d n'existent pas\n",A[nl],B[nl]);
}
else {
np1= A[nl]; np2= B[nl];
int line_width=0;
XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style);
XDrawLine(display, mother, gc, px[np1],py[np1], px[np2],py[np2]);
XDrawLine(display, mother, gc, px[np1]+ DisplayWidth(display,screen)/2,pz[np1], px[np2]+ DisplayWidth(display,screen)/2,pz[np2]); /*fenetre 2, vue de dessus*/
XDrawLine(display, mother, gc, py[np1],pz[np1]+DisplayHeight(display,screen)/2, py[np2],pz[np2]+DisplayHeight(display,screen)/2);/*fenetre vue de cote*/
XDrawLine(display, mother, gc, x2d[np1],y2d[np1],x2d[np2],y2d[np2]);}}
/***Creation de qà 3ã@e regions de la fenetre******************/
int line_width=3;
XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style);
XDrawLine(display, mother,gc,DisplayWidth(display,screen)/2 ,0, DisplayWidth(display,screen)/2,DisplayHeight(display, screen));
XDrawLine(display, mother,gc,0,DisplayHeight(display,screen)/2, DisplayWidth(display,screen),DisplayHeight(display, screen)/2);
/*****************creation titres des fenetres*************************/
line_width=0;
XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style);
/*XDrawRectangle(display, mother, gc,DisplayWidth(display,screen)/8,0,DisplayHeight(display, screen)/4,15);
XDrawRectangle(display, mother, gc,5*DisplayWidth(display,screen)/8,0,DisplayHeight(display, screen)/4,15);
XDrawRectangle(display, mother, gc,DisplayWidth(display,screen)/8,DisplayHeight(display, screen)/2, DisplayHeight(display, screen)/4,15);
XDrawRectangle(display, mother, gc,5*DisplayWidth(display,screen)/8,DisplayHeight(display, screen)/2,DisplayHeight(display, screen)/4,15);*/
XDrawString(display, mother, gc, DisplayWidth(display,screen)/8,14,"vue de face",11);
XDrawString(display, mother, gc, 5*DisplayWidth(display,screen)/8,14,"vue de dessus",13);
XDrawString(display, mother, gc, DisplayWidth(display,screen)/8,DisplayHeight(display, screen)/2+14,"vue de cote",11);
XDrawString(display, mother, gc, 5*DisplayWidth(display,screen)/8,DisplayHeight(display, screen)/2+14,"vue perspective",15);
fclose(fp);
}