scm_render::scm_render(int w, int h) : width(w), height(h), blur(0), wire(false), frame0(0), frame1(0) { init_ogl(); init_matrices(); for (int i = 0; i < 16; i++) midentity(previous_T[i]); }
void vface( triple* v, f32 xrot, f32 yrot ){ static const triple xr = { 0.0f, 1.0f, 0.0f }; static const triple yr = { 1.0f, 0.0f, 0.0f }; static mat m; midentity( &m ); mrotate( &m, &xr, xrot * torad ); mrotate( &m, &yr, yrot * torad ); v->x = v->y = 0.0f; v->z = 1.0f; vmult( v, &m ); }
void Tunnel::setSound(PosRender* posRender) { MPI_Status status; float matrix[4][4]; // matrix for multipli operations midentity(matrix); // creating the identity matrix float m2[4][4]; // temporary matrix to hold the homogeneus operations // This is in oposite order, because the matrix operates like this, the other multiplications is in oposite order rotzmatrix(m2,-posRender->render.head_rotat[2]); multipleMatrix(m2,matrix); // rotation in x and multiply rotymatrix(m2,-posRender->render.head_rotat[1]); multipleMatrix(m2,matrix); // rotation in y and multiply rotxmatrix(m2,-posRender->render.head_rotat[0]); multipleMatrix(m2,matrix); // rotation in z and multiply float vec[4]; posView2->view.pos[0] = posRender->render.pos[0]; posView2->view.pos[1] = posRender->render.pos[1]; posView2->view.pos[2] = posRender->render.pos[2]; vec[0] = posRender->render.dir[0]; vec[1] = posRender->render.dir[1]; vec[2] = posRender->render.dir[2]; #ifdef DEBUG cout << " Dir bef : " << vec[0] << " " << vec[1] << " " << vec[2]; #endif multipleMatrix(matrix,vec); #ifdef DEBUG cout << " aft : " << vec[0] << " " << vec[1] << " " << vec[2] << endl; #endif posView2->view.dir[0] = vec[0]; posView2->view.dir[1] = vec[1]; posView2->view.dir[2] = vec[2]; vec[0] = posRender->render.up[0]; vec[1] = posRender->render.up[1]; vec[2] = posRender->render.up[2]; multipleMatrix(matrix,vec); posView2->view.up[0] = vec[0]; posView2->view.up[1] = vec[1]; posView2->view.up[2] = vec[2]; MPI_Wait(&request, &status); MPI_Isend(&posView2->view, 1, posView2->viewDatatype, SOUND, RENDER_MOVEMENT, MPI_COMM_WORLD, &request); }
// run test case void runit(TestCase &test, double *data) { // test case that we are running cout << endl << ">>>>> STARTING TEST CASE ... "; cout << test.testno << endl << endl; // get options for test int dflag = 0; int sflag = 0; int iflag = 0; int vflag = 0; int Sflag = 0; int Aflag = 0; for (char *popt = test.options; *popt != 0; ) { // skip if not an option if (*popt++ != '-') continue; // get option switch (*popt++) { case 'A': Aflag = 1; Sflag = 0; break; case 'S': Sflag = 1; Aflag = 0; break; case 'v': vflag = 1; break; case 'd': dflag = 1; break; case 's': sflag = 1; break; case 'i': iflag = 1; break; } } // get number of rows and columns int nrows = test.nrows; int ncols = test.ncols; // output precision cout.precision(6); cout.setf(ios::showpoint); // define matrix and initialize elements int idata = 0; Matrix<double> m(nrows, ncols); if (Sflag || Aflag) { double sign = 1; if (Aflag) sign = -sign; for (int ir = 0 ; ir < nrows; ir++) { for (int ic = 0; ic <= ir; ic++) { m(ir, ic) = data[idata++]; m(ic, ir) = sign*m(ir, ic); } } } else { for (int ir = 0 ; ir < nrows; ir++) { for (int ic = 0; ic < ncols; ic++) { m(ir, ic) = data[idata++]; } } } cout << "TEST MATRIX IS ... " << endl; cout << m << endl; // generate identity matrix Matrix<double> midentity(m.getRows(), m.getCols()); initident(midentity); cout << "IDENTITY MATRIX IS ..." << endl; cout << midentity << endl; // save a copy of matrix for sanity checks Matrix<double> savem(m); MustBeTrue(m == savem); // initialize inhomogeneous part. Vector<double> y(nrows); if (sflag) { for (int ir = 0; ir < nrows; ir++) { y[ir] = data[idata++]; } cout << "TEST Y-VECTOR IS ... " << endl; cout << y << endl << endl; } MustBeTrue(m == savem); // get LUP decomposition Matrix<double> m2(m); Vector<int> pv2(nrows); double determinant; #ifdef DEBUG cout << "(Before GaussianLUP_Pivot) TEST MATRIX IS ... " << endl; cout << m << endl; #endif if (GaussianLUP_Pivot(m2, pv2, 0.0, determinant) != OK) { cerr << "GaussianLUP_Pivot failed" << endl; return; } #ifdef DEBUG cout << "(After GaussianLUP_Pivot) TEST MATRIX IS ... " << endl; cout << m << endl; #endif MustBeTrue(m == savem); // get solution using LUP results if (sflag) { cout << ">>>>> RUNNING SOLUTION TEST ..." << endl; cout << ">>>>> GIVEN M*X = Y, SOLVE FOR X ..." << endl; Vector<double> x2(nrows); Vector<double> y2(y); #ifdef DEBUG cout << "(Before SolveUsingGaussianLUP_Pivot) TEST MATRIX IS ... " << endl; cout << m << endl; #endif if (SolveUsingGaussianLUP_Pivot(m2, x2, y2, pv2, 0.0) != OK) { cerr << "SolveUsingGaussianLUP_Pivot failed" << endl; return; } #ifdef DEBUG cout << "(After SolveUsingGaussianLUP_Pivot) TEST MATRIX IS ... " << endl; cout << m << endl; #endif cout << "SOLUTION X IS ... " << endl << x2 << endl; if (vflag) { cout << "VERIFICATION: THE M*X AND Y SHOULD BE THE SAME" << endl; cout << "SOLUTION: M*X IS ... " << endl; cout << m*x2 << endl; cout << "SOLUTION: Y IS ... " << endl; cout << y << endl; cout << "SOLUTION: RMS FOR Y IS ... "; cout << sqrt(dot(y-m*x2, y-m*x2)) << endl; } } MustBeTrue(m == savem); // get inverse using LUP results if (iflag) { cout << ">>>>> RUNNING MATRIX INVERSE TEST ..." << endl; cout << ">>>>> GIVEN M, SOLVE FOR INVERSE OF M ..." << endl; Matrix<double> minv2(nrows, ncols); #ifdef DEBUG cout << "(Before GetInverseUsingGaussianLUP_Pivot) TEST MATRIX IS ... " << endl; cout << m << endl; #endif if (GetInverseUsingGaussianLUP_Pivot(m2, minv2, pv2, 0.0) != OK) { cerr << "GetInverseUsingGaussianLUP_Pivot failed" << endl; return; } #ifdef DEBUG cout << "(After GetInverseUsingGaussianLUP_Pivot) TEST MATRIX IS ... " << endl; cout << m << endl; #endif cout << "INVERSE OF M IS ... " << endl; cout << minv2 << endl; if (vflag) { Matrix<double> mresults(nrows, ncols); cout << "VERIFICATION: M*MINV AND MINV*M SHOULD GIVE THE IDENTITY MATRIX" << endl; cout << "INVERSE: M*MINV IS ... " << endl; cout << m*minv2 << endl; mresults = midentity - m*minv2; cout << "INVERSE: RESIDUALS FOR M*MINV IS ... " << endl; cout << mresults << endl; cout << "INVERSE: RMS FOR M*MINV IS ... "; cout << rms(mresults) << endl; cout << "INVERSE: MINV*M IS ... " << endl; cout << minv2*m << endl; mresults = midentity - minv2*m; cout << "INVERSE: RESIDUALS FOR MINV*M IS ... " << endl; cout << mresults << endl; cout << "INVERSE: RMS FOR MINV*M IS ... "; cout << rms(mresults) << endl; } } MustBeTrue(m == savem); // get deteminant using LUP results if (dflag) { cout << ">>>>> RUNNING DETERMINANT TEST ..." << endl; cout << ">>>>> GIVEN M, GET DETERMINANT OF M ..." << endl; #ifdef DEBUG cout << "(Before GetDeterminantUsingGaussianLUP_Pivot) TEST MATRIX IS ... " << endl; cout << m << endl; #endif if (GetDeterminantUsingGaussianLUP_Pivot(m2, determinant) != OK) { cerr << "GetDeterminantUsingGaussianLUP_Pivot failed" << endl; return; } #ifdef DEBUG cout << "(After GetDeterminantUsingGaussianLUP_Pivot) TEST MATRIX IS ... " << endl; cout << m << endl; #endif cout << "DETERMINANT IS ... " << determinant << endl; } MustBeTrue(m == savem); cout << ">>>>> ENDING TEST CASE ... " << test.testno << endl; return; }
int main(int argc, char *argv[]) { (void)argc; (void)argv; #ifdef __SSE__ printf("SSE "); #endif #ifdef __SSE2__ printf("SSE2 "); #endif #ifdef __SSE3__ printf("SSE3 "); #endif #ifdef __SSE4__ printf("SSE4 "); #endif #ifdef __SSE4_1__ printf("SSE4.1 "); #endif #ifdef __SSE4_2__ printf("SSE4.2 "); #endif #ifdef __AVX__ printf("AVX "); #endif #ifdef __FMA4__ printf("FMA4 "); #endif printf("\n"); printv(vec(1, 2, 3, 4)); printv(vzero()); printm(mzero()); printm(midentity()); vec4 a = { 1, 2, 3, 4 }, b = { 5, 6, 7, 8 }; printv(a); printv(b); printf("\nshuffles:\n"); printv(vshuffle(a, a, 0, 1, 2, 3)); printv(vshuffle(a, a, 3, 2, 1, 0)); printv(vshuffle(a, b, 0, 1, 0, 1)); printv(vshuffle(a, b, 2, 3, 2, 3)); printf("\ndot products:\n"); printv(vdot(a, b)); printv(vdot(b, a)); printv(vdot3(a, b)); printv(vdot3(b, a)); //vec4 blendmask = { 1, -1, 1, -1 }; //printv(vblend(x, y, blendmask)); vec4 x = { 1, 0, 0, 0 }, y = { 0, 1, 0, 0 }, z = { 0, 0, 1, 0 }, w = { 0, 0, 0, 1 }; printf("\ncross products:\n"); printv(vcross(x, y)); printv(vcross(y, x)); printv(vcross_scalar(x, y)); printv(vcross_scalar(y, x)); printf("\nquaternion products:\n"); printv(qprod(x, y)); printv(qprod(y, x)); printv(qprod_mad(x, y)); printv(qprod_mad(y, x)); printv(qprod_scalar(x, y)); printv(qprod_scalar(y, x)); printf("\nquaternion conjugates:\n"); printv(qconj(x)); printv(qconj(y)); printv(qconj(z)); printv(qconj(w)); printf("\nmat from quat:\n"); printm(quat_to_mat(w)); printm(quat_to_mat_mmul(w)); printm(quat_to_mat_scalar(w)); vec4 angles = { 0.0, 0.0, 0.0, 0.0 }; printf("\neuler to quaternion:\n"); printv(quat_euler(angles)); printv(quat_euler_scalar(angles)); printv(quat_euler_gems(angles)); printf("\neuler to matrix:\n"); printm(mat_euler(angles)); printm(mat_euler_scalar(angles)); printm(quat_to_mat(quat_euler(angles))); printf("\nperspective matrix:\n"); printm(mat_perspective_fovy(M_PI/4.0, 16.0/9.0, 0.1, 100.0)); printm(mat_perspective_fovy_inf_z(M_PI/4.0, 16.0/9.0, 0.1)); printm(mat_perspective_fovy_scalar(M_PI/4.0, 16.0/9.0, 0.1, 100.0)); printf("\northogonal matrix:\n"); printm(mat_ortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0)); printm(mat_ortho(-1.0, 2.0, -1.0, 2.0, -1.0, 2.0)); printf("\ntranslate matrix:\n"); printm(mtranslate(a)); printf("\nscale matrix:\n"); printm(mscale(a)); return 0; }