Main Page   Class Hierarchy   Compound List   File List   Compound Members  

profile.cpp

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2002 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 // GLOBALS
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 }

Generated on Wed Apr 23 15:58:52 2003 for Freecloth by doxygen1.3-rc3