void init_render(void) { mclip = m4_m4prod(s->view->Vinv, s->view->Cinv); mdpy = m4_m4prod(s->view->Pinv, s->view->Sinv); rc_sset(rc = NEWSTRUCT(RContext), s->view, s->lights, s->img); }
void s4_concmat(Stack4 *s, Matrix4 *md, Matrix4 *im) { *s->mtop = m4_m4prod(*md, *s->mtop ); if ( im == (Matrix4 *)0) *s->itop = m4_m4prod(*s->itop, m4_inverse(*md)); else *s->itop = m4_m4prod(*s->itop, *im); }
void init_render(void) { mclip = m4_m4prod(s->view->C, s->view->V); mdpy = m4_m4prod(s->view->S, s->view->P); z = new_list(); g = NEWSTRUCT(GouraudData); rc_sset(rc = NEWSTRUCT(RContext), s->view, s->lights, s->img); }
void s4_scale(Stack4 *s, Vector3 v) { *s->mtop = m4_m4prod(*s->mtop, m4_scale(v.x, v.y, v.z)); if (REL_EQ(v.x, 0.0) || REL_EQ(v.y,0.0) || REL_EQ(v.z,0.0)) error("(s4_scale) unable to invert scale matrix"); else *s->itop = m4_m4prod(m4_scale(1./v.x,1./v.y,1./v.z), *s->itop); }
void GLWidget::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { m = m4_rotate('x', 0.081); } else if (event->button() == Qt::RightButton) { m = m4_rotate('x', -0.081); } if (scn != NULL) { scn->view->V = m4_m4prod(scn->view->V, m); } update(); }
Matrix4 m4_compxform(int k, char *t, Real **p, int j) { int i; Matrix4 m = m4_ident(); for (i = 0; i < k; i++) { switch (t[i]) { case G_TX: m = m4_m4prod(m4_translate(p[i][j], 0, 0), m); break; case G_TY: m = m4_m4prod(m4_translate(0, p[i][j], 0), m); break; case G_TZ: m = m4_m4prod(m4_translate(0, 0, p[i][j]), m); break; case G_RX: m = m4_m4prod(m4_rotate('x', p[i][j]), m); break; case G_RY: m = m4_m4prod(m4_rotate('y', p[i][j]), m); break; case G_RZ: m = m4_m4prod(m4_rotate('z', p[i][j]), m); break; case G_SX: m = m4_m4prod(m4_scale(p[i][j], 1, 1), m); break; case G_SY: m = m4_m4prod(m4_scale(1, p[i][j], 1), m); break; case G_SZ: m = m4_m4prod(m4_scale(1, 1, p[i][j]), m); break; default: break; } } return m; }
Prim *cylin_transform(Prim *p, Matrix4 md, Matrix4 mi) { p->td = m4_m4prod(md, p->td); p->ti = m4_m4prod(p->ti, mi); return p; }
void display_obj_gl(Object *o, Scene *s, Stack4 *st) { int l = 1; GLint time, dtex, eye, pos, norm, texc, vdu, vdv, mvp; GLsizei vsiz = sh_vb_(o)->nvert*3*sizeof(GLfloat); glUseProgram(o->mat->shd.id); set_material_gl(o->mat); mvp = glGetUniformLocation(o->mat->shd.id, "ModelViewProjectionMatrix"); if (st != NULL) setup_matrix_gl(mvp, m4_m4prod(s->view->V, s4_getmat(st)), m4_m4prod(s->view->P, s->view->C)); dtex = glGetUniformLocation(o->mat->shd.id, "color_tex"); glUniform1i(dtex, 0); time = glGetUniformLocation(o->mat->shd.id, "time"); glUniform1f(time, (float) (time_curr - time_start)); eye = glGetUniformLocation(o->mat->shd.id, "eye"); glUniform3f(eye,(float)(s->view->center.x),(float)(s->view->center.y),(float)(s->view->center.z)); glBindBuffer(GL_ARRAY_BUFFER, sh_vb_(o)->buffer); pos = glGetAttribLocation(o->mat->shd.id, "vertpos"); glEnableVertexAttribArray(pos); glVertexAttribPointer(pos, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); norm = glGetAttribLocation(o->mat->shd.id, "vertnormal"); glEnableVertexAttribArray(norm); glVertexAttribPointer(norm, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(l*vsiz) ); if (sh_vb_(o)->ntex >= 1) { l++; texc = glGetAttribLocation(o->mat->shd.id, "verttexc"); glEnableVertexAttribArray(texc); glVertexAttribPointer(texc, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(l*vsiz) ); } if (sh_vb_(o)->ntex >= 2) { l++; vdu = glGetAttribLocation(o->mat->shd.id, "vertdu"); glEnableVertexAttribArray(vdu); glVertexAttribPointer(vdu, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(l*vsiz) ); } if (sh_vb_(o)->ntex >= 3) { l++; vdv = glGetAttribLocation(o->mat->shd.id, "vertdv"); glEnableVertexAttribArray(vdv); glVertexAttribPointer(vdv, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(l*vsiz) ); } if (o->mat->tinfo != NULL) { TmapInfo *ti = (TmapInfo *) o->mat->tinfo; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, ti->src->gltex); } glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, sh_vb_(o)->indices); glDrawElements( GL_TRIANGLES, sh_vb_(o)->nind, GL_UNSIGNED_INT, BUFFER_OFFSET(0) ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, 0); }
void setup_matrix_gl(GLint m_unif, Matrix4 mview, Matrix4 proj) { GLfloat mat[16]; matrix4_to_glmat(mat, m4_m4prod(proj,mview)); glUniformMatrix4fv(m_unif, 1, 0, mat); }
void s4_rotate(Stack4 *s, char axis, Real angle) { *s->mtop = m4_m4prod(*s->mtop, m4_rotate(axis,angle)); *s->itop = m4_m4prod(m4_rotate(axis,-angle), *s->itop); }
void s4_translate(Stack4 *s, Vector3 t) { *s->mtop = m4_m4prod(*s->mtop, m4_translate( t.x, t.y, t.z)); *s->itop = m4_m4prod(m4_translate(-t.x,-t.y,-t.z), *s->itop); }