//3D viewing pipeline. VTM is complete view matrix. none of the values of the View structure should be edited. void matrix_setView3D(Matrix *vtm, View3D *view){ Vector u, vup, vpn; double b, d; matrix_identity(vtm); matrix_translate(vtm, -view->vrp.val[0], -view->vrp.val[1], -view->vrp.val[2]); vpn = view->vpn; vector_cross(&view->vup, &vpn, &u); vector_cross(&vpn, &u, &vup); vector_normalize(&u); vector_normalize(&vup); vector_normalize(&vpn); matrix_rotateXYZ(vtm, &u, &vup, &vpn); matrix_translate(vtm, 0.0, 0.0, view->d); // in lecture notes here (6 and 7) it says to shear but as we only have d to define the COP I don't think we have to b = view->d + view->b; matrix_scale(vtm, ((2.0*view->d) / (b*view->du)), ((2.0*view->d) / (b*view->dv)), (1/b)); d = view->d / b; matrix_perspective(vtm, d); matrix_scale2D(vtm, (-view->screenx / (2.0*d)), (-view->screeny / (2.0*d))); matrix_translate2D(vtm, (view->screenx / 2.0), (view->screeny / 2.0)); }
void matrix_setView3D(Matrix *vtm, View3D *view){ if(NULL != vtm && NULL != view){ Vector u; Vector vup = view->vup; Vector vpn = view->vpn; Matrix project; double bPrime = view->d +view->b; double dPrime = view->d/bPrime; matrix_identity(vtm); printf("before everything:\n"); matrix_print(vtm, stdout); vector_cross(&vup,&vpn,&u); vector_cross(&vpn,&u,&vup); printf("vrp:\n"); vector_print(&view->vrp,stdout); matrix_translate(vtm, -view->vrp.val[0], -view->vrp.val[1],-view->vrp.val[2]); printf("After VRP translation:\n"); matrix_print(vtm, stdout); vector_normalize(&u); vector_normalize(&vpn); vector_normalize(&vup); matrix_rotateXYZ(vtm, &u, &vup, &vpn ); printf("After Rxyz :\n"); matrix_print(vtm, stdout); matrix_translate(vtm, 0, 0,view->d); printf("After translating COP to origin:\n"); matrix_print(vtm, stdout); matrix_scale(vtm, (2*view->d)/(bPrime*view->du), (2*view->d)/(bPrime*view->dv), 1/bPrime); printf("After scaling to CVV:\n"); matrix_print(vtm, stdout); matrix_identity(&project); project.m[3][3]=0; project.m[3][2]=1/dPrime; printf("projection:\n"); matrix_print(&project, stdout); matrix_multiply(&project,vtm,vtm); printf("After perspective:\n"); matrix_print(vtm, stdout); matrix_scale2D(vtm, -view->screenx/(2*dPrime), -view->screeny/(2*dPrime)); printf("After scale to image coords:\n"); matrix_print(vtm, stdout); matrix_translate2D(vtm, view->screenx/2, view->screeny/2); printf("After final translation to image coords:\n"); matrix_print(vtm, stdout); } }
/* * Matrix operand to add a rotation that orients to the orthonormal axes u,v,w */ void module_rotateXYZ(Module *md, Vector *u, Vector *v, Vector *w){ if(!md){ printf("Null md passed to module_rotateXYZ\n"); return; } Element *e; Matrix m; matrix_identity(&m); matrix_rotateXYZ(&m, u, v, w); e = element_init(ObjMatrix, &m); module_insert(md, e); }