enum VertexLabel{ NotPicked, PickedCandidate, MovedCandidate, OnAxis, Fixed, Moved }; enum VertexLabels{ AllMoved, AllFixed, MovedAndFixed }; class Vertex{ public: int birthStage; Vector position; Vector2D texcoord; VertexLabel label; Vertex *parent; Vertex *child; Vertex( Vector &position, Vector2D &texcoord ){ this->birthStage = 0; this->position = position; this->texcoord = texcoord; parent = child = NULL; } void labelPickedCandidate( Vector &position, double margin=0.01){ label = position.distance( this->position ) < margin ? PickedCandidate : NotPicked; } VertexLabel setLabel( Fold &fold, double margin=0.01 ){ return label = fold.vertexLabel( position, margin ); } Vertex( Vertex &vertex1, Vertex &vertex2, int birthStage, Fold &fold ){ this->birthStage = birthStage; position = fold.newVertexPosition( vertex1.position, vertex2.position ); double m = vertex1.position.distance( position ); double n = vertex2.position.distance( position ); texcoord.divide( vertex1.texcoord, vertex2.texcoord, m, n ); parent = child = NULL; } Vertex( Vertex &parentVertex, int birthStage, Fold &fold ){ this->birthStage = birthStage; position = fold.rotateVertexPosition( parentVertex.position ); texcoord = parentVertex.texcoord; parent = &parentVertex; child = NULL; } void renew( int birthStage, Fold &fold ){ if( label == MovedCandidate ){ label = Moved; child = new Vertex( *this, birthStage, fold ); } } void glTexCoord(){ texcoord.glTexCoord(); } void glVertex(){ position.glVertex(); } void glTranslate(){ position.glTranslate(); } }; // ------------------------- other classes member functions ----------------------------------------- Vector Fold::pickedVertexPosition(){ return vertex->position; } enum VertexLabel Fold::vertexLabel( Vector &position, double margin ){ Vector v = position - boundary.passage; double distance = boundary.normal * v; if( fabs( distance ) < margin ) return OnAxis; else if( distance < 0 ) return MovedCandidate; else return Fixed; } void Fold::modify( double position ){ destination = destination2; type = type2; boundary = boundary2; axis = axis2; angle = angle2; if( position < 1.0 ){ if( type == TuckIn ){ destination.divide( vertex->position, destination, position, 1.0-position ); }else{ if( type == FoldUp ) type = BendUp; else if( type == FoldDown ) type = BendDown; angle *= position; destination = this->rotateVertexPosition( vertex->position ); } } }