void minv(float ** in,float ** out,int m1){ /*inv(A) = inv((U)*inv(L)*I*/ float **eye= new float*[m1]; for(int i=0;i<m1;i++) eye[i] = new float[m1]; for(int i=0;i<m1;i++){ for(int j=0;j<m1;j++){ if (i!=j)eye[i][j]=0; else eye[i][j]=1; } } float **temp= new float*[m1]; for(int i=0;i<m1;i++) temp[i] = new float[m1]; float **L= new float*[m1]; for(int i=0;i<m1;i++) L[i] = new float[m1]; float **U= new float*[m1]; for(int i=0;i<m1;i++) U[i] = new float[m1]; float **inv_U= new float*[m1]; for(int i=0;i<m1;i++) inv_U[i] = new float[m1]; float **inv_L= new float*[m1]; for(int i=0;i<m1;i++) inv_L[i] = new float[m1]; float **inv_res= new float*[m1]; for(int i=0;i<m1;i++) inv_res[i] = new float[m1]; LU(in,temp,L, U,m1); invrsUp(U,m1,inv_U); invrsLw(L,m1,inv_L); mmultiply(inv_U,inv_L,inv_res,m1,m1,m1,m1); mmultiply(inv_res,eye,out,m1,m1,m1,m1); for (int i = 0; i <m1; i++){ delete[] eye[i]; delete[] temp[i]; delete[] L[i]; delete[] U[i]; delete[] inv_U[i]; delete[] inv_L[i]; delete[] inv_res[i]; } delete[] eye; delete[] temp; delete[] L; delete[] U; delete[] inv_U; delete[] inv_L; delete[] inv_res; }
static void state_inverse(double *I, const state *s) { double T[16], A[16], R[16]; mtranslate(T, s->p); meuler (A, s->e); mtranspose(R, A); mmultiply (I, T, R); }
void sph_model::prep(const double *P, const double *V, int w, int h) { double M[16]; mmultiply(M, P, V); for (int i = 0; i < 6; ++i) prep_face(M, w, h, 0, 1, 0, 1, i, 0, i); }
static void state_matrix(double *M, const state *s) { double T[16], R[16], p[3]; vneg(p, s->p); mtranslate(T, p); meuler (R, s->e); mmultiply (M, R, T); }
long double trace_lin(float** a,float ** b,int m1,int n1){ long double c=0; float **temp_mult= new float*[m1]; for(int i=0;i<m1;i++) temp_mult[i] = new float[m1]; float **temp_transp= new float*[n1]; for(int i=0;i<n1;i++) temp_transp[i] = new float[m1]; transp(b,temp_transp,m1,n1); mmultiply(a,temp_transp,temp_mult,m1,n1,n1,m1); c=trace(temp_mult,m1); for(int i=0;i<n1;i++) delete temp_transp[i]; delete[] temp_transp; for(int i=0;i<m1;i++) delete temp_mult[i]; delete[] temp_mult; return c; }
int main(int argc, char *argv[]) { int a[DIM][DIM]; int b[DIM][DIM]; int c[DIM][DIM]; clock_t clock1, clock2; printf("Program will multiply %d x %d matrices\n", DIM, DIM); printf("Method : Standart\n"); fill_random_values(a, DIM); //view_matrice(a, DIM); fill_random_values(b, DIM); //view_matrice(b, DIM); printf("Random Matrices are ready\n"); clock1 = clock(); mmultiply(a,b,c,DIM,DIM,DIM); clock2 = clock(); printf("Multiplication completed, duration = %d\n", clock2 - clock1); //view_matrice(c, DIM); return 0; }
void sph_model::draw(const double *P, const double *V, const int *fv, int fc, const int *pv, int pc, float alpha) { double M[16]; mmultiply(M, P, V); glMatrixMode(GL_PROJECTION); glLoadMatrixd(P); glMatrixMode(GL_MODELVIEW); glLoadMatrixd(V); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindBuffer(GL_ARRAY_BUFFER, vertices); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, 0); for (int i = 15; i >= 0; --i) { glActiveTexture(GL_TEXTURE0 + i); glBindTexture(GL_TEXTURE_2D, cache.get_fill()); } // This is a hack that ensures that the root pages of all files are touched. GLuint o; int tock; for (int i = 0; i < fc; ++i) { o = cache.get_page(fv[i], 0, time, tock); o = cache.get_page(fv[i], 1, time, tock); o = cache.get_page(fv[i], 2, time, tock); o = cache.get_page(fv[i], 3, time, tock); o = cache.get_page(fv[i], 4, time, tock); o = cache.get_page(fv[i], 5, time, tock); } for (int i = 0; i < pc; ++i) { o = cache.get_page(pv[i], 0, time, tock); o = cache.get_page(pv[i], 1, time, tock); o = cache.get_page(pv[i], 2, time, tock); o = cache.get_page(pv[i], 3, time, tock); o = cache.get_page(pv[i], 4, time, tock); o = cache.get_page(pv[i], 5, time, tock); } #if 0 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); #endif glUseProgram(program); { glUniform1f(glGetUniformLocation(program, "zoomk"), zoomk); glUniform1f(glGetUniformLocation(program, "globalAlpha"), alpha); glUniform3f(glGetUniformLocation(program, "zoomv"), zoomv[0], zoomv[1], zoomv[2]); for (int i = 0; i < 6; ++i) { double a[3], b[3], c[3], d[3]; vnormalize(a, cube_v[cube_i[i][0]]); vnormalize(b, cube_v[cube_i[i][1]]); vnormalize(c, cube_v[cube_i[i][2]]); vnormalize(d, cube_v[cube_i[i][3]]); glUniform3f(pos_a, GLfloat(a[0]), GLfloat(a[1]), GLfloat(a[2])); glUniform3f(pos_b, GLfloat(b[0]), GLfloat(b[1]), GLfloat(b[2])); glUniform3f(pos_c, GLfloat(c[0]), GLfloat(c[1]), GLfloat(c[2])); glUniform3f(pos_d, GLfloat(d[0]), GLfloat(d[1]), GLfloat(d[2])); draw_face(fv, fc, pv, pc, 0, 1, 0, 1, 0, i); } } glUseProgram(0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glDisableClientState(GL_VERTEX_ARRAY); glActiveTexture(GL_TEXTURE0); }