Modify the coefficiences according to questions x 05 t y 10 t z 1 z 2 z 3

Modify the coefficiences according to questions x 05

This preview shows page 1 - 3 out of 3 pages.

/*Modify the coefficiences according to questions*/x = -0.5 + t;y = -1.0 + t;// z = -1;// z = -2;z = -3;/* Modify these according to the projection */xprime = x; /* this is an example of orth */yprime = y;
Background image
// xprime = x/z; /*for perspective projection f' = 1 */// yprime = y/z;plot_logical_point(xprime, yprime, image);}//_CRT_SECURE_NO_WARNINGS/* Create a header */ header(ROWS, COLS, head);ofile = "hw1ex2-1.ras";// this is the name of your output file, modify thename according to the requirementsif (!(fp = fopen(ofile, "wb")))fprintf(stderr, "error: could not open %s\n", ofile), exit(1);/* Write the header */fwrite(head, 4, 8, fp);for (i = 0; i < ROWS; i++) fwrite(image[i], 1, COLS, fp);fclose(fp);return 0;}void clear(unsigned char image[][COLS]){inti, j;for (i = 0; i < ROWS; i++)for (j = 0; j < COLS; j++) image[i][j] = 0;}int plot_logical_point(float x, float y, unsigned char image[][COLS]){intnx, ny;floatxc, yc;xc = COLS / ((float)LOGICAL_X_MAX - LOGICAL_X_MIN);yc = ROWS / ((float)LOGICAL_Y_MAX - LOGICAL_Y_MIN);nx = (x - LOGICAL_X_MIN) * xc;ny = (y - LOGICAL_Y_MIN) * yc;return plot_physical_point(nx, ny, image);}int plot_physical_point(int x, int y, unsigned char image[][COLS]){if (in_range(x, y)) //return 0;return image[y][x] = 255;}int in_range(int x, int y){return x >= 0 && x < COLS && y >= 0 && y < ROWS;}void header(int row, int col, unsigned char head[32]){int *p = (int *)head;char *ch;int num = row * col;/* Choose little-endian or big-endian header depending on the machine. Don't modify the contents */
Background image
/* Little-endian for PC */*p = 0x956aa659;*(p + 3) = 0x08000000;*(p + 5) = 0x01000000;*(p + 6) = 0x0;*(p + 7) = 0xf8000000;ch = (char*)&col;head[7] = *ch;ch++;head[6] = *ch;ch++;head[5] = *ch;ch++;head[4] = *ch;ch = (char*)&row;head[11] = *ch;ch++;head[10] = *ch;ch++;head[9] = *ch;ch++;head[8] = *ch;ch = (char*)&num;head[19] = *ch;ch++;head[18] = *ch;ch++;head[17] = *ch;ch++;head[16] = *ch;/*// Big-endian for unix*p = 0x59a66a95;*(p + 1) = col;*(p + 2) = row;*(p + 3) = 0x8;*(p + 4) = num;*(p + 5) = 0x1;*(p + 6) = 0x0;*(p + 7) = 0xf8;*/}
Background image

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture