/* Copyright 2005 Nicholas Bishop * * This file is part of SharpConstruct. * * SharpConstruct is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * SharpConstruct is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SharpConstruct; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Brush.h" #include "GrabBrush.hh" #include "Mesh.h" #include using namespace SharpConstruct; GrabBrush::grab_data_ GrabBrush::data_[ 8 ]; float GrabBrush::delta_x_ = 0; float GrabBrush::delta_y_ = 0; GrabBrush::GrabBrush( SculptStart, Mesh& mesh ) : mesh_( mesh ) { for( unsigned i = 0; i < 8; ++i ) data_[ i ].Active.clear(); delta_x_ = delta_y_ = 0; } GrabBrush::GrabBrush( SculptContinue, Mesh& mesh ) : mesh_( mesh ) {} void GrabBrush::operator()( SculptStart, EditData e ) { grab_data_& data( data_[ e.SIndex ] ); data.Drag.Zero(); mesh_.FindActiveVertices( data.Active, e ); //for( unsigned i = 0; i < data.Active.size(); i++ ) // data.Active[ i ].SetDistance( mesh_.CurrentBrush().AlphaStrength( mesh_.Relative2DLocation( e, mesh_.VertexLocations()[ data.Active[ i ].Index() ], // data.Active[ i ].Distance() ) ) ); } void GrabBrush::operator()( SculptContinue, EditData e ) { grab_data_& data( data_[ e.SIndex ] ); data.Drag.Zero(); data.Drag += e.Left * delta_x_; data.Drag += e.Up * delta_y_; for( unsigned i = 0; i < data.Active.size(); ++i ) mesh_.VertexLocations()[ data.Active[ i ].Index() ] += data.Drag * data.Active[ i ].Strength(); } void GrabBrush::Postwork( SculptStart ) {} void GrabBrush::Postwork( SculptContinue ) { mesh_.RecalculateDamaged(); mesh_.RecalculateModifiedNormals(); } void GrabBrush::SetDelta( float x, float y ) { delta_x_ = x; delta_y_ = y; }