예제 #1
0
파일: Main.c 프로젝트: tonivi/CIS27
void creationMenu(PolyListTonivi* poly1, PolyListTonivi* poly2) {
	int option;

	do {
		printf("\n\n  ********************************\n"
			"  * POLYNOMIALS CREATING MENU    *\n"
			"  * 1. Creating left polynomial  *\n"
			"  * 2. Creating right polynomial *\n"
			"  * 3. Back to main menu         *\n"
			"  ********************************\n"
			"   Select an option (1 through 3): ");
		scanf_s("%d", &option);
		switch (option) {
		case 1:
			if (*poly1 != NULL) {
				freePolyList(poly1);
			}
			printf("\n\tCreating Polynomial 1\n");
			createPolyList(poly1);
			break;
		case 2:
			if (*poly2 != NULL) {
				freePolyList(poly2);
			}
			printf("\n\tCreating Polynomial 2\n");
			createPolyList(poly2);
			break;
		case 3:
			printf("\n\tReturn to Main Memu.\n");
			break;
		default:
			printf("\nYou should not be in this class!");
		}
	} while (option != 3);
}
예제 #2
0
파일: Main.c 프로젝트: tonivi/CIS27
void clearingMenu(PolyListTonivi* poly1, PolyListTonivi* poly2,
	PolyListTonivi* result) {
	int option;

	do {
		printf("\n  **********************************\n"
			"  *    CLEARING MENU                *\n"
			"  * 1. Clear Left Polynomial        *\n"
			"  * 2. CLear Right Polynomial       *\n"
			"  * 3. Clear ResultPolynomial       *\n"
			"  * 4. Return to previous menu      *\n"
			"  ***********************************\n"
			"  Select the option(1 through 4): ");
		scanf_s("%d", &option);

		switch (option) {
		case 1:
			if (*poly1 != NULL) {
				printf("\n    Releasing Left Polynomial -\n");
				freePolyList(poly1);
				printf("      Left Polynomial released.\n");
			} else {
				printf("\n    There are no Polynomials to release!\n");
			}
			break;
		case 2:
			if (*poly2 != NULL) {
				printf("\n    Releasing Right Polynomial -\n");
				freePolyList(poly2);
				printf("      Right Polynomial released\n");
			} else {
				printf("\n    There are no Polynomials to release!\n");
			}
			break;
		case 3:
			if (*result != NULL) {
				printf("\n    Releasing Resulting Polynomial -\n");
				freePolyList(result);
				printf("      Resulting Polynomial released.\n");
			} else {
				printf("\n    There are no Polynomials to release!\n");
			}
			break;
		case 4:
			printf("\n\tReturn to Main Menu.\n");
			break;
		default:
			printf("\n    You should not be in this class!\n");
		}
	} while (option != 4);

	return;
}
예제 #3
0
파일: Main.c 프로젝트: tonivi/CIS27
void menu() {
	int option;
	PolyListTonivi poly1 = NULL;
	PolyListTonivi poly2 = NULL;
	PolyListTonivi* result = (PolyListTonivi*)calloc(1, sizeof(PolyListTonivi));

	do {
		printf("\n*************************************"
			"\n*    POLYNOMIAL OPERATIONS          *"
			"\n*   1. Creating polynomials         *"
			"\n*   2. Adding polynomials           *"
			"\n*   3. Multiplying polynomials      *"
			"\n*   4. Displaying polynomials       *"
			"\n*   5. Clearing polynomials         *"
			"\n*   6. Quit                         *"
			"\n*************************************"
			"\nSelect an option (1, 2, 3, 4 ,5 or 6): ");
		scanf_s("%d", &option);
		switch (option) {
		case 1:
			printf("\nCreate Menu \n");
			creationMenu(&poly1, &poly2);
			break;
		case 2:
			if (poly1 && poly2 != NULL) {
				if (result != NULL)
					freePolyList(result);
				printf("\n\tCalling addPoly()\n");
				result = addPoly(poly1, poly2);
			} else if (poly1 != NULL) {
				printf("\n\tRight Polynomial is Missing!");
			} else if (poly2 != NULL) {
				printf("\n\tLeft Polynomial is Missing!");
			} else {
				printf("\n\tBoth Polynomials are Missing!");
			}
			break;
		case 3:
			if (poly1 && poly2 != NULL) {
				if (result != NULL)
					freePolyList(result);
				printf("\n\tCalling MultiplyPoly()\n");
				result = multiplyPoly(poly1, poly2);
			} else if (poly1 != NULL) {
				printf("\n\tRight Polynomial is Missing!");
			} else if (poly2 != NULL) {
				printf("\n\tLeft Polynomial is Missing!");
			} else {
				printf("\n\tBoth Polynomials are Missing!");
			}
			break;
		case 4:
			printf("\nDisplaying all polynomials");
			displayAllPoly(poly1, poly2, *result);
			break;
		case 5:
			printf("\nClearing Menu \n");
			clearingMenu(&poly1, &poly2, result);
			break;
		case 6:
			printf("\nHaving Fun! \n");
			break;
		default:
			printf("\nYou should not be in this class!");
		}
	} while (option != 6);

	freePolyList(&poly1);
	freePolyList(&poly2);
	freePolyList(result);
}
예제 #4
0
void
drawPhong(int dFlag)
{

    poly          *p, *head;
    polyList      *s;
    int           i,j,hue;
    int           *anIndex, redo;
    viewTriple    *aPoint, *polyPt;

    redo = (recalc || redoSmooth);
    if (redo || redoColor || redoDither) {
      rotated = no;  zoomed = no;  translated = no;
      switchedPerspective = no;  changedEyeDistance = no;
      redoSmooth = no;  movingLight = no;

      /* If only a color change don't recalculate polygon info. */
      if (!redo) {
        /* glossy shading if a single hue is indicated */
        changeColorMap();
        scanLines(dFlag);
        /* if axes are on then show axes labels */
        if (viewport->axesOn) showAxesLabels(dFlag);

        /* show pixmap of image */
        XCopyArea(dsply,viewmap,viewport->viewWindow,trashGC,0,0,
                  vwInfo.width,vwInfo.height,0,0);
      } else {
        if (keepDrawingViewport()) {
          if (!firstTime && !(scanline > 0)) {
            strcpy(control->message,"          Freeing Polygons          ");
            writeControlMessage();
            freeListOfPolygons(quickList);
            freePointResevoir();
          }
          if (keepDrawingViewport()) {
            strcpy(control->message,"         Collecting Polygons        ");
            writeControlMessage();
            quickList = copyPolygons(viewData.polygons);

            if (keepDrawingViewport()) {
              strcpy(control->message,"         Projecting Polygons        ");
              writeControlMessage();
              projectAllPolys(quickList);
              if (keepDrawingViewport()) {
                strcpy(control->message,
                       "       Setting Polygon Extremes      ");
                writeControlMessage();
                minMaxPolygons(quickList);
                if (keepDrawingViewport()) {
                  strcpy(control->message,
                         "          Sorting Polygons          ");
                  writeControlMessage();
                  quickList = msort(quickList,0,viewData.numPolygons,
                                    polyCompare);
                  calcEyePoint();
                  head = p = quickList;

                  /* glossy shading if a single hue is indicated */
                  changeColorMap();

                  for (i=0, aPoint=viewData.points;
                       i<viewData.numOfPoints; i++,aPoint++) {
                    aPoint->norm[0]= 0.0;
                    aPoint->norm[1]= 0.0;
                    aPoint->norm[2]= 0.0;
                  }
                  freePolyList();
                  for (i = 0; i < ARRAY_HEIGHT; i++)
                    scanList[i] = NIL(polyList);
                  /* for each polygon  */
                  /* calculate average normal for each vertex  */
                  strcpy(control->message,
                         "         Build Polygon Lists        ");
                  writeControlMessage();
                  p = head;
                  while ((p != NIL(poly)) && keepDrawingViewport()) {

                    for (j = 0, anIndex = p->indexPtr;
                         j < p->numpts; j++, anIndex++) {
                      polyPt = refPt3D(viewData,*(anIndex));
                      polyPt->norm[0] += p->N[0];
                      polyPt->norm[1] += p->N[1];
                      polyPt->norm[2] += p->N[2];
                      normalizeVector(polyPt->norm);
                      /* get hue for each point if multi-dithering is used */
                      if ((viewport->hueOffset != viewport->hueTop ||
                           smoothError) && !mono) {
                        if (absolute(p->color) > 1.0) {
                          hue = floor(absolute(p->color));
                        } else {
                          hue = floor(absolute(p->color) *
                                      viewport->numberOfHues) +
                                      viewport->hueOffset;
                        }
                        polyPt->sc = (float)hue;
                      } /* multi-color dither */
                    } /* for each point in polygon */

                    if ( ! ( p->partialClipPz ||
                             p->totalClipPz   ||
                             (viewData.clipStuff && (p->partialClip  || p->totalClip ) ) ) ) {
                      /* put polygon in each scanline list it intersects */
                      for (i=(int)p->pymin; i<= (int)p->pymax; i++) {
                        if ( (i>=0) && (i<ARRAY_HEIGHT ) ){
                           s = (polyList *)saymem("smoothShade.c",1,sizeof(polyList));
                           s->polyIndx = p;
                           s->next = scanList[i];
                           scanList[i] = s;
                        }
                      } /* put polygon in each scanline it intersects */
                    } /* if polygon not clipped */
                    p = p->next;
                  } /* while still polygons */

                  scanLines(dFlag);

                  /* if axes are on then show axes labels */
                  if (viewport->axesOn) showAxesLabels(dFlag);

                  /* show pixmap of image */
                  XCopyArea(dsply,viewmap,viewport->viewWindow,trashGC,0,0,
                          vwInfo.width,vwInfo.height,0,0);
                  /* freePolyList(scanList);   */

                } /* keepDrawingViewport() after setting extreme values */
              } /* keepDrawingViewport() after projecting all polygons */
            } /* keepDrawingViewport() after collecting polygons */
          } /* keepDrawingViewport() after freeing polygons */
        } /* keepDrawingViewport() after recalc */
        finishedList = !(scanline>0);
        if (firstTime) firstTime = no;
      } /* not only a color change */

    } else { /* else just redisplay current pixmap of image */
      XCopyArea(dsply,viewmap,viewport->viewWindow,trashGC,0,0,
                vwInfo.width,vwInfo.height,0,0);
    }
    clearControlMessage();
    strcpy(control->message,viewport->title);
    writeControlMessage();

} /* drawPhong */