變換,以創建與紋理圖像帆布布料模擬我使用verlet.js插件。畫布上的布料模擬+圖像
的唯一的事情(和最重要的BTW),我還沒到的是,我需要扭曲的drawImage,以使其適合正確的位置。
//Drawing the rectangle
ctx.save();
ctx.beginPath();
ctx.moveTo(cloth.particles[i1].pos.x, cloth.particles[i1].pos.y);
ctx.lineTo(cloth.particles[i1+1].pos.x, cloth.particles[i1+1].pos.y);
ctx.lineTo(cloth.particles[i2].pos.x, cloth.particles[i2].pos.y);
ctx.lineTo(cloth.particles[i2-1].pos.x, cloth.particles[i2-1].pos.y);
ctx.lineTo(cloth.particles[i1].pos.x, cloth.particles[i1].pos.y);
ctx.strokeStyle = "#fff";
ctx.stroke();
ctx.restore();
//Wrapping the image
ctx.save();
var off = cloth.particles[i2].pos.x - cloth.particles[i1].pos.x;
//THIS IS WHAT I TRY TO SOLVE TO FIT TO THE RECTANGLES
//ctx.transform(1,0.5,0,1,0,0);
ctx.drawImage(img, cloth.particles[i1].pos.x,cloth.particles[i1].pos.y, off, off, cloth.particles[i1].pos.x,cloth.particles[i1].pos.y, off ,off);
ctx.restore();
}
我試圖去適應其他布料模擬,但沒有成功。任何線索,我可以找到一些信息來完成?
我認爲你會發現布料模擬工程通過將每個原始矩形分成2個三角形 - 而不是傾斜原始矩形;-) – markE 2015-03-30 18:36:54
是@markE,我也嘗試過,但我是在同一個問題,drawImage設置一個矩形,我會需要傾斜它。 – 2015-03-30 19:14:52