//// // This class stores a beggining and end state of a Quad Mesh, and then interps the points over time // There are a few things that are important that must be considered: // Problem One) Each different QuadMesh must have the same number of edited constraints // Solution One) When you pin a point on one mesh, the other point is automatically // //// class FaceWarp{ private QuadMesh mesh; // the mesh we're actaully messing around with private Point[][] initVertex; // the initial constraint positions private Point[][] finalVertex; // the final constraint position private float playhead; // somewhere in [0, 1] private float alphaLevel; // the draw of the alpha channel private boolean bAnimating; // true if the play head should be doing its thang! //// // Constructor //// public FaceWarp(QuadMesh mesh){ this.mesh = mesh; this.initVertex = new Point[this.mesh.meshSize + 1][this.mesh.meshSize + 1]; this.finalVertex = new Point[this.mesh.meshSize + 1][this.mesh.meshSize + 1]; this.playhead = 0.0; this.alphaLevel = 1.0; this.bAnimating = false; this.buildTables(); } //// // ticky! //// public void tick(float delta){ if(this.bAnimating){ this.playhead += delta; this.interpolateFrames(); if(this.playhead >= 1.0){ this.playhead = 0; this.stop(); } } else { //um, cry } } //// // drawy! //// public void draw(){ this.mesh.draw(); } //// // Lets interpolate some frames //// public void interpolateFrames(){ Point[][] meshPoints = this.mesh.getMesh(); boolean[][] isPinned = this.mesh.getIsPinned(); for(int i = 0; i <= this.mesh.meshSize; i ++){ for(int j = 0; j <= this.mesh.meshSize; j ++){ if(isPinned[i][j]){ meshPoints[i][j].setTo(this.initVertex[i][j].interp(this.playhead, this.finalVertex[i][j])); } } } } //// // copies the init constraints onto the mesh //// public void showInitialConstraints(){ Point[][] meshPoints = this.mesh.getMesh(); boolean[][] isPinned = this.mesh.getIsPinned(); for(int i = 0; i <= this.mesh.meshSize; i ++){ for(int j = 0; j <= this.mesh.meshSize; j ++){ //if(isPinned[i][j]){ meshPoints[i][j].setTo(this.initVertex[i][j].x, this.initVertex[i][j].y, 0); //} } } } //// // copies the final constraints onto the mesh //// public void showFinalConstraints(){ Point[][] meshPoints = this.mesh.getMesh(); boolean[][] isPinned = this.mesh.getIsPinned(); for(int i = 0; i <= this.mesh.meshSize; i ++){ for(int j = 0; j <= this.mesh.meshSize; j ++){ //if(isPinned[i][j]){ meshPoints[i][j].setTo(this.finalVertex[i][j].x, this.finalVertex[i][j].y, 0); //} } } } //// // copys the mesh's current state over to init table //// public void markInitialConstraints(){ Point[][] meshPoints = this.mesh.getMesh(); boolean[][] isPinned = this.mesh.getIsPinned(); for(int i = 0; i <= this.mesh.meshSize; i ++){ for(int j = 0; j <= this.mesh.meshSize; j ++){ //if(isPinned[i][j]){ this.initVertex[i][j].setTo(meshPoints[i][j].x, meshPoints[i][j].y, 0); //} } } } //// // copies the mesh's current state into the final table //// public void markFinalConstraints(){ Point[][] meshPoints = this.mesh.getMesh(); boolean[][] isPinned = this.mesh.getIsPinned(); for(int i = 0; i <= this.mesh.meshSize; i ++){ for(int j = 0; j <= this.mesh.meshSize; j ++){ //if(isPinned[i][j]){ this.finalVertex[i][j].setTo(meshPoints[i][j].x, meshPoints[i][j].y, 0); //} } } } //// // Initializes all the things, and stuff, yep //// private void buildTables(){ Point[][] meshPoints = this.mesh.getMesh(); for(int i = 0; i <= this.mesh.meshSize; i ++){ for(int j = 0; j <= this.mesh.meshSize; j ++){ this.initVertex[i][j] = new Point(meshPoints[i][j].x, meshPoints[i][j].y); this.finalVertex[i][j] = new Point(meshPoints[i][j].x, meshPoints[i][j].y); } } } ///////////////////////// // GETTERS AND SETTERS // ///////////////////////// public void setPlayhead(float playhead){ this.playhead = playhead; } public void start(){ this.showInitialConstraints(); this.bAnimating = true; } public void stop(){ this.bAnimating = false; } public boolean isAnimating(){ return this.bAnimating; } public QuadMesh getMesh(){ return this.mesh; } public Point[][] getInitVertex(){ return this.initVertex; } public void setInitVertex(Point[][] initVertex){ this.initVertex = initVertex; } public Point[][] getFinalVertex(){ return this.finalVertex; } public void setFinalVertex(Point[][] finalVertex){ this.finalVertex = finalVertex; } }