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

Ring.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: Ring.cpp,v 1.4 2002/01/11 14:35:03 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "Teddy/Maths/Vector.h"
00026 #include "Teddy/Models/Ring.h"
00027 #include "Teddy/Models/QuadStrip.h"
00028 #include "Teddy/Models/Vertex.h"
00029 #include "Teddy/SysSupport/StdMaths.h"
00030 using namespace Teddy::SysSupport;
00031 
00032 
00033 namespace Teddy  {
00034 namespace Models {
00035 
00036 
00044 Ring::Ring(
00045     const std::string &name,
00046     const double       inner_radius,
00047     const double       outer_radius,
00048     const int          slices )
00049 :
00050 Model( name )
00051 {
00052     QuadStrip *qs = new QuadStrip();
00053     for( int i=0; i<=slices; i++ ){
00054         double theta = i*M_2_PI/slices;
00055         double slice = 1.0 - (double)(i)/(double)(slices);
00056         Vertex *v1 = new Vertex( inner_radius * cos(theta), 0, inner_radius * sin(theta) );
00057         v1->setNormal (  0.0f, 1.0f, 0.0f );
00058         v1->setTexture( slice, 0.0f, 0.0f );
00059         Vertex *v2 = new Vertex( outer_radius * cos(theta), 0, outer_radius * sin(theta) );
00060         v1->setNormal (  0.0f, 1.0f, 0.0f );
00061         v1->setTexture( slice, 1.0f, 0.0f );
00062         qs->add( v1 );
00063         qs->add( v2 );
00064     }
00065     add( qs );
00066     setClipRadius( outer_radius );
00067 }
00068 
00069 
00070 };  //  namespace Models
00071 };  //  namespace Teddy
00072