arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

planarQuad.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////
00002 // 6/7/02       Aaron Lefohn    Scientific Computing and Imaging Institute
00003 // School of Computing          University of Utah
00004 //
00005 //  This library is free software; you can redistribute it and/or
00006 //  modify it under the terms of the GNU Lesser General Public
00007 //  License as published by the Free Software Foundation; either
00008 //  version 2.1 of the License, or (at your option) any later version.
00009 //
00010 //  This library is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 //  Lesser General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU Lesser General Public
00016 //  License along with this library; if not, write to the Free Software
00017 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 ////////////////////////////////////////////////////////////////////////
00019 //
00020 // PlanarQuad.cpp: implementation of the PlanarQuad class.
00021 //
00022 /////////////////////////////////////////////////////////////////////
00023 
00024 #include <drawable/planarQuad.h>
00025 #include <iostream>
00026 
00027 using namespace std;
00028 using namespace gutz;
00029 
00030 using namespace glift;
00031 
00032 PlanarQuad::PlanarQuad( const vec2f& lowerLeft, const vec2f& upperRight, 
00033                        bool genTexCoords, bool genNorms, TexCoordGen* texGen )
00034 {
00035    init( lowerLeft, upperRight, 0.0f, genTexCoords, genNorms, texGen );
00036 }
00037 
00038 
00039 PlanarQuad::PlanarQuad( const vec2f& lowerLeft, const vec2f& upperRight, float z,  
00040                        bool genTexCoords, bool genNorms, TexCoordGen* texGen )
00041 {
00042    init( lowerLeft, upperRight, z, genTexCoords, genNorms, texGen );
00043 }
00044 
00045 void PlanarQuad::init( const vec2f lowerLeft, const vec2f upperRight, float z,
00046                       bool genTexCoords, bool genNorms, TexCoordGen* texGen )
00047 {
00048    m_lowerLeft = lowerLeft;
00049    m_upperRight = upperRight;
00050    m_z = z;
00051 
00052    bool createdTexGen = false;
00053    if( genTexCoords && texGen==NULL )  {
00054       texGen = new QuadTexGen();
00055       createdTexGen = true;
00056    }
00057    else if( genTexCoords==false && texGen ) {
00058       err() << "PlanarQuad(...) Error:\n"
00059          << "\tIllegal to disable texCoordGeneration and pass\n"
00060          << "\tin alternate texCoordGenerator.\n";
00061       exit(1);
00062    }
00063 
00064    arrayo2f     vert = setQuadVertPos( lowerLeft, upperRight, z);
00065    arrayo2f     texCoord = genTexCoords ? texGen->genTexCoords(vert, vec3f()) : arrayo2f();
00066    vec3f                scale( upperRight.x, upperRight.y, 1.0 );
00067    arrayo2f     norms = genNorms ? setNorm() : arrayo2f();
00068 
00069    WrappedPrim::init( new QuadsGL( vert, texCoord, scale, norms, arrayo1ui(), arrayo2f(), arrayo1ub(), GLIFT_DRAW_ARR ) );
00070 
00071    if( createdTexGen ) { delete texGen; }
00072 }
00073 
00074 arrayo2f PlanarQuad::setQuadVertPos( const vec2f& lowerLeft, const vec2f& upperRight, float z )
00075 {
00076    GLfloat data[12] = { lowerLeft.x,  lowerLeft.y,  z,
00077       upperRight.x, lowerLeft.y,  z,
00078       upperRight.x, upperRight.y, z,
00079       lowerLeft.x,  upperRight.y, z };
00080 
00081    return arrayo2f(4, 3, data);         /// 4 vertices, 3 dimensions per vertex
00082 }
00083 
00084 arrayo2f PlanarQuad::setNorm()
00085 {
00086    GLfloat data[12] = { 0.0f, 0.0f, 1.0f,
00087       0.0f, 0.0f, 1.0f,
00088       0.0f, 0.0f, 1.0f,
00089       0.0f, 0.0f, 1.0f };
00090 
00091    return arrayo2f(4, 3, data); /// 4 vertices, 3 dimensions per vertex
00092 }
00093 
00094 

Send questions, comments, and bug reports to:
jmk