- Home
- Tutorials
- Flash
- Intermediate
- cloth simulation in 9 steps

cloth simulation in 9 steps: final result
HariBabu Suraneni
While I am working in www.onemg.in as a Flash Developer, I have really entered into Flash Script writing even though I started my career with AS2 in 2007. From that humble begening, now I have grown up to a successfull AS3 programmer. In my process of learning, actionscript org has a major role as I Learnt so much from the published tutorials and forums.
Now, I think I have learnt some new techniques that are rarely finding their place in these articles, I want to share my knowledge through some of the educative tutorials.
View all articles by HariBabu Suraneni
Now the updateVertices function will look like this:
private function updateVertices(){
// vertices=new Vector.<number>();
// for (var r:int = 0; r < ROWS; r++) {
// for (var c:int = 0; c < COLS; c++) {
// if(c!=(COLS-1)){
// if(r!=(ROWS-1)){
// vertices.push(points[r * COLS + c].x,points[r * COLS + c].y,points[r * COLS + c].x+COLW,points[r * COLS + c].y,points[r * COLS + c].x+COLW,points[r * COLS + c].y+ROWH,points[r * COLS + c].x,points[r * COLS + c].y+ROWH);
// }
// }
// }
// }
vertices=new Vector.<number>();
// uvtData=new Vector.<number>();
//trace("--------UPDATE VERTEX DATA========\n");
for(var r:int=1;r<=(ROWS-1);r++){
for(var c:int=1;c<=(COLS-1);c++){
//trace("\n--------VERTEX SEQUENCE========\n");
//trace(" ("+r+","+c+")")
//trace(" ("+(r*COLS+c)+")")
//trace("value1 : ("+(sticks[(((r-1)==0)?((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+c):((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+COLS))].pointa.x)+")");
//trace("value2 : ("+(sticks[(((r-1)==0)?((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+c):((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+COLS))].pointa.y)+")");
//trace("value3 : ("+(sticks[(((r-1)==0)?((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+c):((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+COLS))].pointb.x)+")");
//trace("value4 : ("+(sticks[(((r-1)==0)?((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+c):((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+COLS))].pointb.y)+")");
//trace("value5 : ("+(sticks[((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)].pointb.x)+")");
//trace("value6 : ("+(sticks[((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)].pointb.y)+")");
//trace("value7 : ("+(sticks[((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)].pointa.x)+")");
//trace("value8 : ("+(sticks[((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)].pointa.y)+")");
//trace("\n--------VERTEX SEQUENCE========\n");
//.0 .1
//.3 .2
// 1 2 3 4 5 6 7 8
// vertices.push(c*COLW,r*ROWH,(c+1)*COLW,r*ROWH,(c+1)*COLW,(r+1)*ROWH,c*COLW,(r+1)*ROWH);
vertices.push((sticks[(((r-1)==0)?((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+c):((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+COLS))].pointa.x),(sticks[(((r-1)==0)?((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+c):((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+COLS))].pointa.y),(sticks[(((r-1)==0)?((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+c):((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+COLS))].pointb.x),(sticks[(((r-1)==0)?((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+c):((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)-((COLS-1)+COLS))].pointb.y),(sticks[((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)].pointb.x),(sticks[((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)].pointb.y),(sticks[((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)].pointa.x),(sticks[((((r * (COLS - 1))+c)+(((r - 1) * COLS)+(c+1)))-2)].pointa.y));
}
}
//trace("--------UPDATE VERTEX DATA========\n");
}
I kept all the commented trace messages to show you how tedious the work is. At this juncture I want to tell you that I learnt a lot about that double for loop and their interelationships - a lot enough to make another tutorial. Now, I need to test the new Logic. I fought with so much tension, even though I am confident about the result. If I try to enter into a new room with the tension I felt then, I definitely will be collapsed before entering the room. After all the quotable quotes about courage ran into my mind, I gained courage and published the file. This is the result:
I still wonder how could I achieve it, even though I myself wrote the code. It is not a staright forward solution jumped out spontaneously. A lot of trial and error sequences were gone past before I reached this solution.
Now, I am happy about what I have achieved. In fact, I tried for the next thing:to fix the cloth to a top handle bar, But I am not that much experienced in verlet integration. I understood the basic concept, but unable to manipulate it to create a working code. Mr. ALEX, as the creator of oroginal verlet Grid, or some other scriptor who si smart enough and eager to continue this may get all the samples from here.
THE LEGAY OF ACTION SCRIPT MUST CONTINUE
Spread The Word
5 Responses to "cloth simulation in 9 steps" 
|
said this on 03 Feb 2011 4:32:47 PM CDT
u have done a excellent j
|
|
said this on 07 Mar 2011 8:30:36 PM CDT
wow!!!! im only just gett
|
|
said this on 31 Mar 2011 9:21:21 PM CDT
I have just started to le
|
|
said this on 13 Feb 2013 4:58:42 AM CDT
hi i have been really int
please e mail me if y |


Author/Admin)
