void Cube(double time){ float tm[16], rm[16], mm[16]; GLuint loc; static double prev_time = 0.0; translate(tm, 0.5, 0.5, -3.0 - time*1.5); rotate(rm, sin(time) / M_PI, cos(time) / M_PI, M_PI); matrixMultiply4x4(rm, tm, mm); if(time - prev_time > 0.03){ getNextFrame(matat); updateBigCube(matat.buffer, &bigcube); matatpos++; } glUseProgram(bigcube_shader); loc = glGetUniformLocation(bigcube_shader, "camera"); glUniformMatrix4fv(loc, 1, GL_FALSE, mm); loc = glGetUniformLocation(bigcube_shader, "pmatrix"); glUniformMatrix4fv(loc, 1, GL_FALSE, pmatrix); drawBigCube(bigcube); if(matatpos > 55){ rewindDepthVideo(matat); matatpos = 1; } }
void Matatas(double time){ static double prev_time = 0.0; GLuint loc; float tmatrix[16]; float rmatrix[16]; float mmatrix[16]; translate(tmatrix, -0.4, 3.0, -7.0); rotate(rmatrix, 0.0, 0.0, 4.1); matrixMultiply4x4(rmatrix, tmatrix, mmatrix); /* 30fps video playback */ if(time - prev_time > 0.03){ getNextFrame(matat); updateFace(matat.buffer, armface); prev_time = time; matatpos++; } glUseProgram(armface->shader); loc = glGetUniformLocation(armface->shader, "pmatrix"); glUniformMatrix4fv(loc, 1, GL_FALSE, pmatrix); loc = glGetUniformLocation(armface->shader, "mmatrix"); glUniformMatrix4fv(loc, 1, GL_FALSE, mmatrix); drawFace(armface); if(matatpos > 55){ rewindDepthVideo(matat); matatpos = 1; } }
/* The last scene. I have made it first. :-)*/ void Headbreak(double time){ static int i = 0; static float rot = 0.0; static double prev_time; GLuint loc; float tmatrix[16]; float rmatrix[16]; float mmatrix[16]; translate(tmatrix, -0.4, 3.0, -7.0); rotate(rmatrix, 0.0, 0.0, 4.1); matrixMultiply4x4(rmatrix, tmatrix, mmatrix); /* 30fps video playback */ if(time - prev_time > 0.03){ getNextFrame(head); updateFace(head.buffer, face); prev_time = time; i++; } glUseProgram(face->shader); loc = glGetUniformLocation(face->shader, "pmatrix"); glUniformMatrix4fv(loc, 1, GL_FALSE, pmatrix); loc = glGetUniformLocation(face->shader, "mmatrix"); glUniformMatrix4fv(loc, 1, GL_FALSE, mmatrix); drawFace(face); rot += 0.05; if(i > 87){ rewindDepthVideo(head); i = 1; } }
void projectStuff(float x,float y,float z,int *px,int *py,float *Pz) { float tempx,tempy,tempz,temps,V[4],V1[4],stuffScale=100.0; tempx = viewport->scaleX; tempy = viewport->scaleY; tempz = viewport->scaleZ; temps = viewScale; if (viewport->scaleX > 5.0) viewport->scaleX = 5.0; if (viewport->scaleY > 5.0) viewport->scaleY = 5.0; if (viewport->scaleZ > 3.0) viewport->scaleZ = 3.0; if (viewScale > 5.0) viewScale = 5.0; V[0] = x; V[1] = y; V[2] = z; V[3] = 1.0; V[0] -= viewport->transX*stuffScale; V[1] -= viewport->transY*stuffScale; V[2] -= viewport->transZ*stuffScale; matrixMultiply4x4(S,R,transform); vectorMatrix4(V,transform,V1); *Pz = V1[2]; if (viewData.perspective) { V1[0] *= projPersp(V1[2]); V1[1] *= projPersp(V1[2]); } matrixMultiply4x4(I,T,transform); vectorMatrix4(V1,transform,V); V[0] = V[0]*viewScale + xCenter; V[1] = vwInfo.height - (V[1]*viewScale + yCenter); *px = V[0]; *py = V[1]; viewport->scaleX = tempx; viewport->scaleY = tempy; viewport->scaleZ = tempz; viewScale = temps; }
void project(viewTriple * aViewTriple,XPoint *someXpoints,int i) { float Vtmp[4], V[4], V1[4]; V[0] = aViewTriple->x; V[1] = aViewTriple->y; V[2] = aViewTriple->z; V[3] = 1.0; if (isNaNPoint(V[0], V[1], V[2])) { (someXpoints+i)->x = aViewTriple->px = NotPoint; (someXpoints+i)->y = aViewTriple->py = NotPoint; return; } V[0] -= viewport->transX; V[1] -= viewport->transY; V[2] -= viewport->transZ; vectorMatrix4(V,R1,Vtmp); matrixMultiply4x4(S,R,transform); vectorMatrix4(Vtmp,transform,V1); aViewTriple->wx = V1[0]; aViewTriple->wy = V1[1]; aViewTriple->wz = V1[2]; V1[0] *= reScale; V1[1] *= reScale; V1[2] *= reScale; aViewTriple->pz = V1[2]; if (viewData.perspective) { V1[0] *= projPersp(aViewTriple->pz); V1[1] *= projPersp(aViewTriple->pz); } matrixMultiply4x4(I,T,transform); vectorMatrix4(V1,transform,V); V[0] = V[0]*viewScale + xCenter; V[1] = vwInfo.height - (V[1]*viewScale + yCenter); (someXpoints+i)->x = aViewTriple->px = V[0]; (someXpoints+i)->y = aViewTriple->py = V[1]; }
void drawLetters(double time){ GLuint loc; int i; int text[33] = {1,9,0,2,6,5,2,8,4,1,3,2,5,2,8,4,1,7, 2,6,1,5,3,6,4,0,3,8,3,5,7,2,1}; float offset[33] = {-65.0, -57.0, -49.0, -41.0, -33.0, -25.0, -17.0, -9.0, -4.0, 1.0, 15.0, 23.0, 31.0, 39.0, 47.0, 52.0, 57.0, 65.0, -4.0, 1.0, -4.0, 1.0, -47.0, -23.0, -8.0, 15.0, 20.0, 30.0, 40.0, 45.0, -47.0, -52.0, -60.0}; float start[33] = {5.21,7.21,7.63,6.52,8.21,8.56,4.0758,4.5221,4.7203,2.4149,9.2415,7.8153,8.84,5.67,7.47,5.34,9.00,6.23, 10.3739, 12.076, 13.666,16.851, 11.24, 12.73, 14.32, 15.42, 16.21, 12.97, 14.89, 16.11, 11.64, 16.43, 16.65}; float tmatrix[16]; float rmatrix[16]; float camera[16]; float ypos, basey; glUseProgram(letter_shader); loc = glGetUniformLocation(letter_shader, "pmatrix"); glUniformMatrix4fv(loc, 1, GL_FALSE, pmatrix); for(i = 0; i < 33; i++){ if(i < 18){ basey = 40.0; } else{ basey = 60.0; } if(time > start[i]){ ypos = basey - 9.822 * (time - start[i]) * (time - start[i]); } else{ ypos = basey; } translate(tmatrix, offset[i], ypos, -170.0); ypos -= basey; rotate(rmatrix, M_PI / -2.0 + (ypos / 40.0), 0.0 + (ypos / 40.0), 0.0); matrixMultiply4x4(rmatrix, tmatrix, camera); loc = glGetUniformLocation(letter_shader, "camera"); glUniformMatrix4fv(loc, 1, GL_FALSE, camera); drawMesh3D(letters[text[i]]); } }
void projectAPoly (poly *p) { int i,clipped,clippedPz; float Vtmp[4],V[4],V1[4]; float x0=0.0; float y0=0.0; float xA=0.0; float yA=0.0; float xB=0.0; float yB=0.0; int *anIndex; viewTriple *aPt; /* totalClip==yes => partialClip==yes */ p->totalClipPz = yes; /* start with 1, AND all points with Pz<0 */ p->partialClipPz = no; /* start with 0, OR any points with Pz<0 */ p->totalClip = yes; /* same idea, only with respect to clip volume */ p->partialClip = no; for (i=0,anIndex=p->indexPtr; i<p->numpts; i++,anIndex++) { aPt = refPt3D(viewData,*anIndex); V[0] = aPt->x; V[1] = aPt->y; V[2] = aPt->z; V[3] = 1.0; V[0] -= viewport->transX; V[1] -= viewport->transY; V[2] -= viewport->transZ; vectorMatrix4(V,R1,Vtmp); matrixMultiply4x4(S,R,transform); vectorMatrix4(Vtmp,transform,V1); aPt->wx = V1[0]; aPt->wy = V1[1]; aPt->wz = V1[2]; V1[0] *= reScale; V1[1] *= reScale; V1[2] *= reScale; aPt->pz = V1[2]; if (viewData.perspective) { V1[0] *= projPersp(V1[2]); V1[1] *= projPersp(V1[2]); } matrixMultiply4x4(I,T,transform); vectorMatrix4(V1,transform,V); V[0] = V[0]*viewScale + xCenter; V[1] = vwInfo.height - (V[1]*viewScale + yCenter); aPt->px = V[0]; aPt->py = V[1]; clipped = outsideClippedBoundary(aPt->x, aPt->y, aPt->z); p->totalClip = p->totalClip && clipped; p->partialClip = p->partialClip || clipped; clippedPz = behindClipPlane(aPt->pz); p->totalClipPz = p->totalClipPz && clippedPz; p->partialClipPz = p->partialClipPz || clippedPz; /* stuff for figuring out normalFacingOut, after the loop */ if (!i) { x0 = aPt->px; y0 = aPt->py; } else if (i==1) { xA = x0 - aPt->px; yA = y0 - aPt->py; x0 = aPt->px; y0 = aPt->py; } else if (i==2) { xB = aPt->px - x0; yB = aPt->py - y0; } } if ((x0 = xA*yB - yA*xB) > machine0) p->normalFacingOut = 1; else if (x0 < machine0) p->normalFacingOut = -1; else p->normalFacingOut = 0; } /* projectAPoly */