Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Grid.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: Grid.cpp,v 1.4 2002/01/11 14:35:02 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "Teddy/Models/Grid.h"
00026 #include "Teddy/Models/Vertex.h"
00027 #include "Teddy/Models/Line.h"
00028 #include "Teddy/Models/LineGeometry.h"
00029 
00030 
00031 namespace Teddy  {
00032 namespace Models {
00033 
00034 
00039 Grid::Grid( const int xCount, const int zCount, const float xSize, const float zSize )
00040 :
00041 Model( "Grid" )
00042 {
00043     Vertex *v1;
00044     Vertex *v2;
00045     Line   *l;
00046 
00047     setGeometry( new LineGeometry() );
00048 
00049     //  Boundaries
00050     fore   =  zCount/2*zSize;
00051     back   = -zCount/2*zSize;
00052     right  =  xCount/2*xSize;
00053     left   = -xCount/2*xSize;
00054 
00055     float r1 = xCount/2*xSize;
00056     float r2 = zCount/2*zSize;
00057     float r  = sqrt(r1*r1 + r2*r2);
00058 
00059     setClipRadius( r );
00060 
00061     //  Horizontal lines
00062     for( int x=-xCount/2; x<=xCount/2; x++ ){
00063         v1 = new Vertex( x*xSize, 0, fore   );
00064         v2 = new Vertex( x*xSize, 0, back   );
00065         l  = new Line( v1, v2 );
00066         add( l );
00067     }
00068 
00069     //  Vertical lines
00070     for( int z=-zCount/2; z<=zCount/2; z++ ){
00071         v1 = new Vertex( left,  0, z*zSize );
00072         v2 = new Vertex( right, 0, z*zSize );
00073         l  = new Line( v1, v2 );
00074         add( l );
00075     }
00076 }
00077 
00078 
00079 };  //  namespace Models
00080 };  //  namespace Teddy
00081