/* * draws the swarm using the given view etc into the given image */ void swarm_draw(Swarm *s, Matrix *VTM, Matrix *GTM, DrawState *ds, Lighting *lighting, Image *src){ int i, verbose = 0; if(verbose) printf("drawing swarm\n"); Matrix m, transGTM; if (!s){ printf("no swarm to draw!\n"); } // draw actors for (i = 0; i < s->numActors; i++){ matrix_identity(&m); matrix_translate(&m,s->actors[i].location.val[0], s->actors[i].location.val[1], s->actors[i].location.val[2]); matrix_multiply(&m, GTM, &transGTM); module_draw(s->actors[i].shape, VTM, &transGTM, ds, lighting, src); } // draw leaders for (i = 0; i < s->numLeaders; i++){ matrix_identity(&m); matrix_translate(&m,s->leaders[i].location.val[0], s->leaders[i].location.val[1], s->leaders[i].location.val[2]); matrix_multiply(&m, GTM, &transGTM); module_draw(s->leaders[i].shape, VTM, &transGTM, ds, lighting, src); } if(verbose) printf("swarm drawn\n"); }
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); } }
DECLARE_TEST(matrix, vec) { vector_t vec; VECTOR_ALIGN float32_t aligned_rotm[] = { 0, 2, 0, 11, 0, 0, 3, 12, 1, 0, 0, 13, 7, 8, 9, 10 }; VECTOR_ALIGN float32_t aligned_tformm[] = { 0, 2, 0, 0, 0, 0, 3, 0, 1, 0, 0, 0, -1, 2, 5, 1 }; vec = matrix_rotate(matrix_zero(), vector_zero()); EXPECT_VECTOREQ(vec, vector_zero()); vec = matrix_rotate(matrix_zero(), vector_one()); EXPECT_VECTOREQ(vec, vector(0, 0, 0, 1)); vec = matrix_rotate(matrix_identity(), vector_one()); EXPECT_VECTOREQ(vec, vector_one()); vec = matrix_rotate(matrix_aligned(aligned_rotm), vector_xaxis()); EXPECT_VECTOREQ(vec, vector(0, 2, 0, 1)); vec = matrix_rotate(matrix_aligned(aligned_rotm), vector_yaxis()); EXPECT_VECTOREQ(vec, vector(0, 0, 3, 1)); vec = matrix_rotate(matrix_aligned(aligned_rotm), vector_zaxis()); EXPECT_VECTOREQ(vec, vector(1, 0, 0, 1)); vec = matrix_transform(matrix_zero(), vector_zero()); EXPECT_VECTOREQ(vec, vector_zero()); vec = matrix_transform(matrix_zero(), vector_one()); EXPECT_VECTOREQ(vec, vector(0, 0, 0, 0)); vec = matrix_transform(matrix_identity(), vector_one()); EXPECT_VECTOREQ(vec, vector_one()); vec = matrix_transform(matrix_aligned(aligned_tformm), vector_xaxis()); EXPECT_VECTOREQ(vec, vector(-1, 4, 5, 1)); vec = matrix_transform(matrix_aligned(aligned_tformm), vector_yaxis()); EXPECT_VECTOREQ(vec, vector(-1, 2, 8, 1)); vec = matrix_transform(matrix_aligned(aligned_tformm), vector_zaxis()); EXPECT_VECTOREQ(vec, vector(0, 2, 5, 1)); return 0; }
void sprite_drawquad(struct pack_picture *picture, const struct srt *srt, const struct sprite_trans *arg) { struct matrix tmp; struct vertex_pack vb[4]; int i,j; if (arg->mat == NULL) { matrix_identity(&tmp); } else { tmp = *arg->mat; } matrix_srt(&tmp, srt); int *m = tmp.m; for (i=0;i<picture->n;i++) { struct pack_quad *q = &picture->rect[i]; int glid = texture_glid(q->texid); if (glid == 0) continue; shader_texture(glid, 0); for (j=0;j<4;j++) { int xx = q->screen_coord[j*2+0]; int yy = q->screen_coord[j*2+1]; float vx = (xx * m[0] + yy * m[2]) / 1024 + m[4]; float vy = (xx * m[1] + yy * m[3]) / 1024 + m[5]; float tx = q->texture_coord[j*2+0]; float ty = q->texture_coord[j*2+1]; screen_trans(&vx,&vy); vb[j].vx = vx; vb[j].vy = vy; vb[j].tx = tx; vb[j].ty = ty; } shader_draw(vb, arg->color, arg->additive); } }
//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)); }
static int drawquad(struct render_buffer *rb, struct pack_picture *picture, const struct sprite_trans *arg) { struct matrix tmp; struct vertex_pack vb[4]; int i,j; if (arg->mat == NULL) { matrix_identity(&tmp); } else { tmp = *arg->mat; } int *m = tmp.m; int object = rb->object; for (i=0;i<picture->n;i++) { struct pack_quad *q = &picture->rect[i]; if (update_tex(rb, q->texid)) { rb->object = object; return -1; } for (j=0;j<4;j++) { int xx = q->screen_coord[j*2+0]; int yy = q->screen_coord[j*2+1]; vb[j].vx = (xx * m[0] + yy * m[2]) / 1024 + m[4]; vb[j].vy = (xx * m[1] + yy * m[3]) / 1024 + m[5]; vb[j].tx = q->texture_coord[j*2+0]; vb[j].ty = q->texture_coord[j*2+1]; } if (renderbuffer_add(rb, vb, arg->color, arg->additive)) { return 1; } } return 0; }
static void poly_aabb(int n, const int32_t * point, struct srt *srt, struct matrix *ts, int aabb[4]) { struct matrix mat; if (ts == NULL) { matrix_identity(&mat); } else { mat = *ts; } matrix_srt(&mat, srt); int *m = mat.m; int i; for (i=0;i<n;i++) { int x = point[i*2]; int y = point[i*2+1]; int xx = (x * m[0] + y * m[2]) / 1024 + m[4]; int yy = (x * m[1] + y * m[3]) / 1024 + m[5]; if (xx < aabb[0]) aabb[0] = xx; if (xx > aabb[2]) aabb[2] = xx; if (yy < aabb[1]) aabb[1] = yy; if (yy > aabb[3]) aabb[3] = yy; } }
static int lsr(lua_State *L) { struct sprite *s = self(L); struct matrix *m = &s->mat; if (s->t.mat == NULL) { matrix_identity(m); s->t.mat = m; } int sx=1024,sy=1024,r=0; int n = lua_gettop(L); switch (n) { case 4: // sx,sy,rot r = luaL_checknumber(L,4) * (1024.0 / 360.0); // go through case 3: // sx, sy sx = luaL_checknumber(L,2) * 1024; sy = luaL_checknumber(L,3) * 1024; break; case 2: // rot r = luaL_checknumber(L,2) * (1024.0 / 360.0); break; } matrix_sr(m, sx, sy, r); return 0; }
void init_defaultstate(IDirect3DDevice9 *device){ int i; matrix projection_matrix, view_matrix; IDirect3DDevice9_SetVertexShader(device, NULL); IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_CCW); IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, TRUE); IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE); IDirect3DDevice9_SetRenderState(device, D3DRS_SPECULARENABLE, TRUE); IDirect3DDevice9_SetRenderState(device, D3DRS_NORMALIZENORMALS, TRUE); for(i=0;i<8;i++){ IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_COLOROP, D3DTOP_DISABLE); IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_COLORARG1, D3DTA_TEXTURE); IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_COLORARG2, D3DTA_CURRENT); IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_ALPHAOP, D3DTOP_DISABLE); IDirect3DDevice9_SetTextureStageState(device, i, D3DTSS_ALPHAARG1, D3DTA_CURRENT); IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MIPFILTER, D3DTEXF_POINT); // IDirect3DDevice9_SetSamplerState(device, i, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); } matrix_project( projection_matrix, 45.f, 4.f/3.f, 1.f, 1000.f ); IDirect3DDevice9_SetTransform( device, D3DTS_PROJECTION, (D3DMATRIX*)&projection_matrix ); matrix_identity( view_matrix ); IDirect3DDevice9_SetTransform( device, D3DTS_VIEW, (D3DMATRIX*)&view_matrix ); }
//sets the vtm to be the virw transfermation defined by the 2D View structure void matrix_setView2D(Matrix *vtm, View2D *view){ matrix_identity(vtm); matrix_translate2D(vtm, -view->vrp.val[0], -view->vrp.val[1]); matrix_rotateZ(vtm, view->x.val[0], -view->x.val[1]); matrix_scale2D(vtm, (view->screenx / view->dx), (-view->screenx / view->dx)); // S(C/ du, R/ dv) where dv = du*R/ C matrix_translate2D(vtm, (view->screenx / 2.0), (view->screeny / 2.0)); }
static int lmulti_draw(lua_State *L) { struct sprite *s = self(L); int cnt = (int)luaL_checkinteger(L,3); if (cnt == 0) return 0; int n = lua_gettop(L); luaL_checktype(L,4,LUA_TTABLE); luaL_checktype(L,5,LUA_TTABLE); if (lua_rawlen(L, 4) < cnt) { return luaL_error(L, "matrix length less then particle count"); } if (n == 6) { luaL_checktype(L,6,LUA_TTABLE); if (lua_rawlen(L, 6) < cnt) { return luaL_error(L, "additive length less then particle count"); } } struct srt srt; fill_srt(L, &srt, 2); if (s->t.mat == NULL) { s->t.mat = &s->mat; matrix_identity(&s->mat); } struct matrix *parent_mat = s->t.mat; uint32_t parent_color = s->t.color; int i; if (n == 5) { for (i = 0; i < cnt; i++) { lua_rawgeti(L, 4, i+1); lua_rawgeti(L, 5, i+1); s->t.mat = (struct matrix *)lua_touserdata(L, -2); s->t.color = (uint32_t)lua_tounsigned(L, -1); lua_pop(L, 2); sprite_draw_as_child(s, &srt, parent_mat, parent_color); } }else { for (i = 0; i < cnt; i++) { lua_rawgeti(L, 4, i+1); lua_rawgeti(L, 5, i+1); lua_rawgeti(L, 6, i+1); s->t.mat = (struct matrix *)lua_touserdata(L, -3); s->t.color = (uint32_t)lua_tounsigned(L, -2); s->t.additive = (uint32_t)lua_tounsigned(L, -1); lua_pop(L, 3); sprite_draw_as_child(s, &srt, parent_mat, parent_color); } } s->t.mat = parent_mat; s->t.color = parent_color; return 0; }
static void anchor_update(struct sprite *s, struct sprite_trans *arg) { struct matrix *r = s->s.mat; if (arg->mat == NULL) { matrix_identity(r); } else { *r = *arg->mat; } }
void matrix_stack_reset(MatrixStack* ms) { mstack *m = (mstack*)ms; while (m->depth > 1) matrix_stack_pop(ms); matrix_identity(m->top->mat); }
static int lmatrix_multi_draw(lua_State *L) { struct sprite *s = self(L); int cnt = (int)luaL_checkinteger(L,3); if (cnt == 0) return 0; luaL_checktype(L,4,LUA_TTABLE); luaL_checktype(L,5,LUA_TTABLE); if (lua_rawlen(L, 4) < cnt) { return luaL_error(L, "matrix length must less then particle count"); } if (lua_rawlen(L, 5) < cnt) { return luaL_error(L, "color length must less then particle count"); } struct matrix *mat = (struct matrix *)lua_touserdata(L, 2); if (s->t.mat == NULL) { s->t.mat = &s->mat; matrix_identity(&s->mat); } struct matrix *parent_mat = s->t.mat; uint32_t parent_color = s->t.color; int i; if (mat) { struct matrix tmp; for (i = 0; i < cnt; i++) { lua_rawgeti(L, 4, i+1); lua_rawgeti(L, 5, i+1); struct matrix *m = (struct matrix *)lua_touserdata(L, -2); matrix_mul(&tmp, m, mat); s->t.mat = &tmp; s->t.color = (uint32_t)lua_tounsigned(L, -1); lua_pop(L, 2); sprite_draw(s, NULL); } } else { for (i = 0; i < cnt; i++) { lua_rawgeti(L, 4, i+1); lua_rawgeti(L, 5, i+1); struct matrix *m = (struct matrix *)lua_touserdata(L, -2); s->t.mat = m; s->t.color = (uint32_t)lua_tounsigned(L, -1); lua_pop(L, 2); sprite_draw(s, NULL); } } s->t.mat = parent_mat; s->t.color = parent_color; return 0; }
float *new_matrix(void) { float *matrix; matrix = (float*)malloc(sizeof(float) * 16); if (matrix == NULL) return (NULL); matrix_identity(matrix); return (matrix); }
static int lgetmat(lua_State *L) { struct sprite *s = self(L); if (s->t.mat == NULL) { s->t.mat = &s->mat; matrix_identity(&s->mat); } lua_pushlightuserdata(L, s->t.mat); return 1; }
MatrixStack *matrix_stack_create() { mstack *m = (mstack*)malloc(sizeof(mstack)); m->top = mstackelem_create(); matrix_identity(m->top->mat); m->depth = 1; return (MatrixStack*)m; }
static PyObject *matrix_mul(Matrix *self, PyObject *arg) { if (PyObject_IsInstance(arg, (PyObject *)&MatrixType)) { Matrix *result = (Matrix *)matrix_identity(NULL); double *m = result->data; double *a = self->data; double *b = ((Matrix *)arg)->data; mat_mat_multiply(m, a, b); return (PyObject *)result; } return NULL; }
void matrix_setView2D(Matrix *vtm, View2D *view){ if(NULL != vtm && NULL != view){ float dv = (view->dx*view->screeny)/view->screenx; matrix_identity(vtm); matrix_print(vtm, stdout); matrix_translate2D(vtm, -view->vrp.val[0], -view->vrp.val[1]); matrix_rotateZ(vtm, view->x.val[0], -view->x.val[1]); matrix_scale2D(vtm, view->screenx/view->dx, -view->screeny/dv); matrix_translate2D(vtm, view->screenx/2, view->screeny/2); } }
static int child_pos(struct sprite *s, struct srt *srt, struct sprite_trans *ts, struct sprite *t, int pos[2]) { struct sprite_trans temp; struct matrix temp_matrix; struct sprite_trans *st = trans_mul(&s->t, ts, &temp, &temp_matrix); if (s == t) { struct matrix tmp; if (st->mat == NULL) { matrix_identity(&tmp); } else { tmp = *st->mat; } matrix_srt(&tmp, srt); switch (s->type) { case TYPE_PICTURE: picture_pos(tmp.m, s->s.pic, srt, st, pos); return 0; case TYPE_LABEL: label_pos(tmp.m, s->s.label, srt, st, pos); return 0; case TYPE_ANIMATION: case TYPE_PANNEL: pos[0] = tmp.m[4] / SCREEN_SCALE; pos[1] = tmp.m[5] / SCREEN_SCALE; return 0; default: return 1; } } if (s->type != TYPE_ANIMATION){ return 1; } struct pack_animation *ani = s->s.ani; int frame = real_frame(s) + s->start_frame; struct pack_frame * pf = &ani->frame[frame]; int i; for (i=0;i<pf->n;i++) { struct pack_part *pp = &pf->part[i]; int index = pp->component_id; struct sprite * child = s->data.children[index]; if (child == NULL) { continue; } struct sprite_trans temp2; struct matrix temp_matrix2; struct sprite_trans *ct = trans_mul(&pp->t, st, &temp2, &temp_matrix2); if (child_pos(child, srt, ct, t, pos) == 0) { return 0; } } return 1; }
/* * Matrix operand to add a rotation about the Y-axis to the Module. */ void module_rotateY(Module *md, double cth, double sth){ if(!md){ printf("Null md passed to module_rotateY\n"); return; } Element *e; Matrix m; matrix_identity(&m); matrix_rotateY(&m, cth, sth); e = element_init(ObjMatrix, &m); module_insert(md, e); }
/* * Matrix operand to add a Z shear matrix to the tail of the module’s list */ void module_shearZ(Module *md, double shx, double shy){ if(!md){ printf("Null md passed to module_shearZ\n"); return; } Element *e; Matrix m; matrix_identity(&m); matrix_shearZ(&m, shx, shy); e = element_init(ObjMatrix, &m); module_insert(md, e); }
/* * Matrix operand to add a 3D scale to the Module. */ void module_scale(Module *md, double sx, double sy, double sz){ if(!md){ printf("Null md passed to module_scale\n"); return; } Element *e; Matrix m; matrix_identity(&m); matrix_scale(&m, sx, sy, sz); e = element_init(ObjMatrix, &m); module_insert(md, e); }
/* * 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); }
/* * Matrix operand to add a 3D translation to the Module. */ void module_translate(Module *md, double tx, double ty, double tz){ if(!md){ printf("Null md passed to module_translate\n"); return; } Element *e; Matrix m; matrix_identity(&m); matrix_translate(&m, tx, ty, tz); e = element_init(ObjMatrix, &m); module_insert(md, e); }
void matrix_test(void) { Matrix* pMatrix = matrix_identity(3); matrix_print(pMatrix); printf("Inicio: \n"); for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { printf("pMatrix(%d,%d) = %f\n", x, y, matrix_get_elem(pMatrix, x, y)); } } printf("\nModificado: \n"); int i = 0; for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { matrix_set_elem(pMatrix, x, y, i++); } } for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { printf("pMatrix(%d,%d) = %f\n", x, y, matrix_get_elem(pMatrix, x, y)); } } matrix_free(pMatrix); printf("\nMultiplicacion: \n"); Matrix* pA = matrix_new(2, 3); Matrix* pB = matrix_new(3, 2); Matrix* pC = matrix_new(2, 2); matrix_set_elem(pA, 0, 0, 2.0f); matrix_set_elem(pA, 0, 1, 2.0f); matrix_set_elem(pA, 1, 1, 2.0f); matrix_set_elem(pA, 1, 0, 2.0f); matrix_set_elem(pB, 0, 0, 1.0f); matrix_set_elem(pB, 0, 1, 2.0f); matrix_set_elem(pB, 1, 1, 3.0f); matrix_set_elem(pB, 1, 0, 4.0f); matrix_print(pA); matrix_print(pB); matrix_mult(pA, pB, pC); matrix_print(pC); matrix_free(pA); matrix_free(pB); matrix_free(pC); }
void calc_particle_system_mat(struct particle * p, struct matrix *m, int edge) { matrix_identity(m); struct srt srt; srt.rot = p->rotation * 1024 / 360; srt.scalex = p->size * 1024 / edge; srt.scaley = srt.scalex; srt.offx = (p->pos.x + p->startPos.x) * SCREEN_SCALE; srt.offy = (p->pos.y + p->startPos.y) * SCREEN_SCALE; matrix_srt(m, &srt); matrix_mul(m, m, &p->emitMatrix); }
void calc_particle_system_mat(struct particle * p, struct matrix *m, int edge) { struct srt srt; struct matrix tmp; matrix_identity(m); srt.rot = (int)(p->rotation * 1024 / 360); srt.scalex = (int)(p->size * 1024 / edge); srt.scaley = srt.scalex; srt.offx = (int)((p->pos.x + p->startPos.x) * SCREEN_SCALE); srt.offy = (int)((p->pos.y + p->startPos.y) * SCREEN_SCALE); matrix_srt(m, &srt); memcpy(tmp.m, m, sizeof(int) * 6); matrix_mul(m, &tmp, &p->emitMatrix); }
void matrix_inverse(Matrix *X, Matrix *X_inverse, Matrix *Xsamedims) { int n=numrows(X), e_code, ipiv[n]; // Need to set X_inverse to the identity matrix on input: matrix_identity(X_inverse); // Copy X to Xsamedims (error check for dims inside matrix_copy): matrix_copy(X, Xsamedims); // Compute: Solution to a real system of linear equations: A * X = B // Where A is an N-by-N matrix and X and B are N-by-NRHS matrices. // The LU decomposition with partial pivoting and row interchanges is // used to factor A as A = P * L * U, // where P is a permutation matrix, L is unit lower triangular, and U is // upper triangular. The factored form of A is then used to solve the // system of equations A * X = B. // // N = The number of linear equations, i.e., numrows(A) // NRHS = The number of right hand sides, i.e., numcols(B) // // A = LDA-by-N matrix, the leading N-by-N matrix of A is the // coefficient matrix A. On exit, the factors L and U from the // factorization. A = P*L*U // LDA = The leading dimension of the array A (LDA >= max(1,N)) // // IPIV = N-vector containing the pivot indices that define P; // row i of the matrix was interchanged with row IPIV(i) // // B = LDB-by-NRHS matrix, the leading N-by-NRHS matrix of B is the // right hand side matrix. On exit, the N-by-NRHS solution X. // // LDB = The leading dimension of the array B (LDB >= max(1,N)) // INFO =0 => Successful exit // <0 => If INFO = -i, the i-th argument had an illegal value // >0 => If INFO = i, U(i,i) is exactly zero. The factorization // has been completed, but the factor U is exactly // singular, so the solution could not be computed. //dgesv(n,n,Xsamedims,n,ipiv,X_inverse,n,&e_code); // C version F77_CALL(dgesv)(&n,&n,Xsamedims,&n,ipiv,X_inverse,&n,&e_code); // R version if (!e_code) return; if (e_code<0) error("Singular value in mat_inverse.\n"); else error("Illegal value in mat_inverse.\n"); return; }
void render(void) { static float mvp[16] = { 0 }; if (g_scop.auto_rotate) auto_rotate_object(); update_texture_transition(); matrix_identity(mvp); matrix_mult_m(mvp, 3, g_scop.model_matrix, g_scop.view_matrix, g_scop.proj_matrix); glUniformMatrix4fv(g_scop.gfx.model_matrix_uni, 1, GL_FALSE, g_scop.model_matrix); glUniformMatrix4fv(g_scop.gfx.mvp_uni, 1, GL_FALSE, mvp); glUniform1f(g_scop.gfx.texture_level_uni, g_scop.texture_level); glDrawArrays(GL_TRIANGLES, 0, g_scop.vertex_count); }