00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <freecloth/clothApp/package.h>
00020 #include <freecloth/simulator/simSimulator.h>
00021 #include <freecloth/geom/geMatrix3.h>
00022 #include <freecloth/geom/geMesh.h>
00023 #include <freecloth/geom/geMeshBuilder.h>
00024
00025 namespace {
00026
00027
00028
00029 RCShdPtr<GeMesh> createRectMesh(
00030 Float size,
00031 UInt32 nbRows,
00032 UInt32 nbCols
00033 ) {
00034 GeMeshBuilder builder;
00035 UInt32 r, c;
00036 builder.preallocVertices( (nbRows + 1) * (nbCols + 1 ) );
00037 builder.preallocTextureVertices( (nbRows + 1) * (nbCols + 1 ) );
00038 builder.preallocFaces( nbRows * nbCols );
00039 for ( r = 0; r <= nbRows; ++r ) {
00040 for ( c = 0; c <= nbCols; ++c ) {
00041 builder.addVertex(
00042 GePoint( c * size / nbCols, r * size / nbRows, 0 )
00043 );
00044 builder.addTextureVertex(
00045 GePoint( c * size / nbCols, r * size / nbRows, 0 )
00046 );
00047 }
00048 }
00049 const UInt32 rstride=nbCols+1;
00050 for( r = 0; r < nbRows; ++r ) {
00051 for ( c = 0; c < nbCols; ++c ) {
00052 GeMesh::FaceId fid = builder.addFace(
00053 r*rstride + c, r*rstride + c+1, (r+1)*rstride + c,
00054 r*rstride + c, r*rstride + c+1, (r+1)*rstride + c
00055 );
00056 fid = builder.addFace(
00057 (r+1)*rstride + c, r*rstride + c+1, (r+1)*rstride + c+1,
00058 (r+1)*rstride + c, r*rstride + c+1, (r+1)*rstride + c+1
00059 );
00060 }
00061 }
00062 return builder.createMesh();
00063 }
00064
00065 }
00066
00067
00068
00069
00070
00071
00072 int main()
00073 {
00074 const UInt32 NB_ITER = 10;
00075 const UInt32 NB_PATCHES = 31;
00076
00077 RCShdPtr< GeMesh > mesh( createRectMesh( 1, NB_PATCHES, NB_PATCHES ) );
00078 SimSimulator simulator( *mesh );
00079 simulator.setTimestep( .02f );
00080 simulator.setDensity( .1f );
00081 {
00082 const UInt32 N = NB_PATCHES;
00083 #if 1
00084 simulator.setPosConstraintFull( 0 );
00085 simulator.setPosConstraintFull( N );
00086 simulator.setPosConstraintFull( N*(N+1) );
00087 simulator.setPosConstraintFull( N*(N+1) + N );
00088 #else
00089 const UInt32 C = BaMath::roundUInt32( std::max( 1.f, N*5/11.f ) );
00090 const UInt32 x = (N-C)/2;
00091 for (UInt32 i = 0; i <= C; ++i ) for ( UInt32 j = 0; j <= C; ++j ) {
00092 simulator.setPosConstraintFull( (x + i)*(N+1) + x + j );
00093 }
00094 #endif
00095 }
00096
00097 for ( UInt32 i = 0; i < NB_ITER; ++i ) {
00098 std::cout << "Iteration " << i << std::endl;
00099 simulator.step();
00100 }
00101 return 0;
00102 }