void SrRasterizer::_set_tri(SrTriangle* tri, std::vector<SrFragment*>& _triangles_fragments) { //!!!!!! //切出来的新顶点在ceil了之后不一定在同一条线上,所以导致计算出来的数据差距很大。 //float new_x = tri->v[2].normal.x + (tri->v[2].position.y - tri->v[1].position.y) / (tri->v[2].position.y - tri->v[0].position.y)*(tri->v[0].position.x - tri->v[2].position.x); VertexP3N3T2 new_v; float t = (tri->v[1].position.y - tri->v[0].position.y) / (tri->v[2].position.y - tri->v[0].position.y); new_v.position = _lerp_position(tri->v[0].position, tri->v[2].position,t); new_v.normal = _lerp_normal(tri->v[0].normal, tri->v[2].normal, t); new_v.text_coord = _lerp_uv(tri->v[0].text_coord, tri->v[0].position.w, tri->v[2].text_coord, tri->v[2].position.w, t); SrTriangle up_tri(VertexP3N3T2(tri->v[0]), VertexP3N3T2(tri->v[1]), new_v); //左右排序< if (up_tri.v[1].position.x > up_tri.v[2].position.x) { VertexP3N3T2 temp = up_tri.v[1]; up_tri.v[1] = up_tri.v[2]; up_tri.v[2] = temp; } SrTriangle down_tri(new_v,VertexP3N3T2(tri->v[1]), VertexP3N3T2(tri->v[2])); //左右排序< if (down_tri.v[0].position.x > down_tri.v[1].position.x) { VertexP3N3T2 temp = down_tri.v[1]; down_tri.v[1] = down_tri.v[0]; down_tri.v[0] = temp; } _set_bottom_tri(&down_tri,_triangles_fragments); _set_top_tri(&up_tri,_triangles_fragments); }
int main() { unsigned r1, c1, r2, c2, ch; mat m1, m2, t; puts("Enter row and column numbers of matrices 1 and 2:"); scanf(" %u %u %u %u%*c", &r1, &c1, &r2, &c2); putchar('\n'); m1=mat_alloc(r1, c1); m2=mat_alloc(r2, c2); printf("Enter value of Matrix 1 (%ux%u):\n", r1, c1); mat_read(m1); putchar('\n'); printf("Enter value of Matrix 2 (%ux%u):\n", r2, c2); mat_read(m2); putchar('\n'); do{ puts("What would you like to do?"); puts(" ( 0) Exit"); puts(" ( 1) Display"); puts(" ( 2) Transpose"); puts(" ( 3) Sum"); puts(" ( 4) Difference"); puts(" ( 5) Product"); puts(" ( 6) Greatest Element of Rows"); puts(" ( 7) Sum of Major Diagonal"); puts(" ( 8) Sum of Minor Diagonal"); puts(" ( 9) Check Symmetricity"); puts(" (10) Upper-Triangular Matrix"); puts(" (11) Lower-Triangular Matrix"); scanf(" %u%*c", &ch); switch(ch){ case 0: puts("Bye!"); break; case 1: puts("Matrix 1:"); mat_write(m1); putchar('\n'); puts("Matrix 2:"); mat_write(m2); break; case 2: t=mat_trn(m1); mat_write(t); mat_free(t); break; case 3: if((t=mat_add(m1, m2)).r){ mat_write(t); mat_free(t); } else puts("Not Possible"); break; case 4: if((t=mat_sub(m1, m2)).r){ mat_write(t); mat_free(t); } else puts("Not Possible"); break; case 5: if((t=mat_mul(m1, m2)).r){ mat_write(t); mat_free(t); } else puts("Not Possible"); break; case 6: row_great(m1); break; case 7: add_major(m1); break; case 8: add_minor(m1); break; case 9: if(issymm(m1)) puts("Symmetric"); else puts("Unsymmetric"); break; case 10: up_tri(m1); break; case 11: lo_tri(m1); break; default: puts("Incorrect Choice!"); break; } putchar('\n'); } while(ch); mat_free(m1); mat_free(m2); return 0; }