libanim
diff example/test.c @ 57:2da758956e50
added the option of lightweight pre-pass top-down recursive calculation of
matrices instead of going through the existing lazy thread-specific caching
algorithm.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 09 Dec 2013 04:06:30 +0200 |
parents | b408f3f655e9 |
children | 5993f405a1cb |
line diff
1.1 --- a/example/test.c Sat Nov 16 12:31:03 2013 +0200 1.2 +++ b/example/test.c Mon Dec 09 04:06:30 2013 +0200 1.3 @@ -184,6 +184,10 @@ 1.4 glRotatef(cam_phi, 1, 0, 0); 1.5 glRotatef(cam_theta, 0, 1, 0); 1.6 1.7 + /* first render a character with bottom-up lazy matrix calculation */ 1.8 + glPushMatrix(); 1.9 + glTranslatef(-2.5, 0, 0); 1.10 + 1.11 for(i=0; i<NUM_NODES; i++) { 1.12 float color[4] = {0, 0, 0, 1}; 1.13 mat4_t xform, xform_transp; 1.14 @@ -203,10 +207,39 @@ 1.15 1.16 glScalef(parts[i].sz.x, parts[i].sz.y, parts[i].sz.z); 1.17 glutSolidCube(1.0); 1.18 - /*glutWireSphere(0.6, 16, 8);*/ 1.19 1.20 glPopMatrix(); 1.21 } 1.22 + glPopMatrix(); 1.23 + 1.24 + /* then render another one using simple top-down recursive evaluation */ 1.25 + glPushMatrix(); 1.26 + glTranslatef(2.5, 0, 0); 1.27 + 1.28 + anm_eval(nodes[NODE_TORSO], msec); /* calculate all matrices recursively */ 1.29 + 1.30 + for(i=0; i<NUM_NODES; i++) { 1.31 + float color[4] = {0, 0, 0, 1}; 1.32 + mat4_t xform_transp; 1.33 + 1.34 + color[0] = parts[i].color.x; 1.35 + color[1] = parts[i].color.y; 1.36 + color[2] = parts[i].color.z; 1.37 + 1.38 + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); 1.39 + glColor4fv(color); 1.40 + 1.41 + m4_transpose(xform_transp, nodes[i]->matrix); 1.42 + 1.43 + glPushMatrix(); 1.44 + glMultMatrixf((float*)xform_transp); 1.45 + 1.46 + glScalef(parts[i].sz.x, parts[i].sz.y, parts[i].sz.z); 1.47 + glutSolidCube(1.0); 1.48 + 1.49 + glPopMatrix(); 1.50 + } 1.51 + glPopMatrix(); 1.52 1.53 glutSwapBuffers(); 1.54 assert(glGetError() == GL_NO_ERROR);