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

Box.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: Box.cpp,v 1.5 2002/02/16 12:41:39 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "Teddy/Models/Box.h"
00026 #include "Teddy/Models/QuadStrip.h"
00027 #include "Teddy/Models/Vertex.h"
00028 
00029 
00030 namespace Teddy  {
00031 namespace Models {
00032 
00033 
00044 Box::Box(
00045     const std::string &name,
00046     const float        x_size,
00047     const float        y_size,
00048     const float        z_size,
00049     const int          x_div,
00050     const int          y_div,
00051     const int          z_div
00052 )
00053 :
00054 Model( name )
00055 {
00056     int x;
00057     int y;
00058     int z;
00059 
00060     //  Top and bottom
00061     for( x = -x_div; x < x_div; x++ ){
00062         float x1 =    x  * (x_size / x_div);
00063         float x2 = (1+x) * (x_size / x_div);
00064         QuadStrip *top = new QuadStrip();
00065         QuadStrip *bot = new QuadStrip();
00066         for( z = -z_div; z <= z_div; z++ ){
00067             float z1 = z * (z_size / z_div);
00068             top->add( new Vertex(x1, y_size,z1) );
00069             top->add( new Vertex(x2, y_size,z1) );
00070             bot->add( new Vertex(x2,-y_size,z1) );
00071             bot->add( new Vertex(x1,-y_size,z1) );
00072         }
00073         top->setNormal( 0.0f, 1.0f, 0.0f );
00074         bot->setNormal( 0.0f,-1.0f, 0.0f );
00075         top->enable( Element::EL_USE_ELEMENT_NORMAL );
00076         bot->enable( Element::EL_USE_ELEMENT_NORMAL );
00077         add( top );
00078         add( bot );
00079         QuadStrip *fro = new QuadStrip();
00080         QuadStrip *bac = new QuadStrip();
00081         for( y = -y_div; y <= y_div; y++ ){
00082             float y1 = y * (y_size / y_div);
00083 
00084             fro->add( new Vertex(x2,y1, z_size) );
00085             fro->add( new Vertex(x1,y1, z_size) );
00086             bac->add( new Vertex(x1,y1,-z_size) );
00087             bac->add( new Vertex(x2,y1,-z_size) );
00088         }
00089         fro->setNormal( 0.0f, 0.0f,  1.0f );
00090         bac->setNormal( 0.0f, 0.0f, -1.0f );
00091         fro->enable( Element::EL_USE_ELEMENT_NORMAL );
00092         bac->enable( Element::EL_USE_ELEMENT_NORMAL );
00093         add( fro );
00094         add( bac );
00095     }
00096 
00097     //  Left and right
00098     for( z = -z_div; z < z_div; z++ ){
00099         float z1 =    z  * (z_size / z_div);
00100         float z2 = (1+z) * (z_size / z_div);
00101         QuadStrip *lef = new QuadStrip();
00102         QuadStrip *rig = new QuadStrip();
00103         for( y = -y_div; y <= y_div; y++ ){
00104             float y1 = y * (y_size / y_div);
00105             lef->add( new Vertex(-x_size,y1,z2) );
00106             lef->add( new Vertex(-x_size,y1,z1) );
00107             rig->add( new Vertex( x_size,y1,z1) );
00108             rig->add( new Vertex( x_size,y1,z2) );
00109         }
00110         lef->setNormal( -1.0f, 0.0f, 0.0f );
00111         rig->setNormal(  1.0f, 0.0f, 0.0f );
00112         lef->enable( Element::EL_USE_ELEMENT_NORMAL );
00113         rig->enable( Element::EL_USE_ELEMENT_NORMAL );
00114         add( lef );
00115         add( rig );
00116     }
00117 
00118     setupClipRadius();
00119 }
00120 
00121 
00122 };  //  namespace Models
00123 };  //  namespace Teddy
00124