/* 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 "Create.hh" #include "MeshHistory.h" using SharpConstruct::Create::Plane; Plane::Plane( const unsigned rows, const unsigned cols ) : rows_( rows ), columns_( cols ) {} bool Plane::operator()() const { Mesh& mesh( MeshHistory::Instance().GetCurrentMesh() ); const float half_x = columns_ / 2, half_y = rows_ / 2; //mesh.VertexLocations.clear(); //mes_clear_polys(); //_vertex_normals.resize( rows_ * columns_ ); //_vertex_colors.resize( rows_ * columns_ ); for( unsigned i = 0; i < rows_; ++i ) { for( unsigned j = 0; j < columns_; ++j ) mesh.VertexLocations().push_back( Optimized::Point3D( ( j - half_x ) / ( columns_ - 1 ), ( i - half_y ) / ( rows_ - 1 ), 0 ) ); } //_quad_normals.resize( ( rows_ - 1 ) * ( columns_ - 1 ) ); for( unsigned i = 0, t = 0; i < rows_ - 1; ++i ) { for( unsigned j = 0; j < columns_ - 1; ++j, t++ ) { mesh.Quads().push_back( Quad( i * columns_ + j + 1, ( i + 1 ) * columns_ + j + 1, ( i + 1 ) * columns_ + j, i * columns_ + j ) ); } } return true; }