GlDrawWandFunctors.cpp

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile$
00027  * Date modified: $Date: 2006-07-12 17:21:40 -0500 (Wed, 12 Jul 2006) $
00028  * Version:       $Revision: 19032 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #include <vrj/Draw/OGL/Config.h>
00034 
00035 #include <boost/concept_check.hpp>
00036 
00037 #include <vrj/Draw/OGL/GlDrawWandFunctors.h>
00038 
00039 #include <gmtl/Vec.h>
00040 #include <gmtl/Output.h>
00041 #include <gmtl/VecOps.h>
00042 #include <vector>
00043 
00044 namespace vrj
00045 {
00046 
00047 GlDrawConeWandFunctor::GlDrawConeWandFunctor()
00048    : mQuadObj(gluNewQuadric())
00049 {
00050 }
00051 
00052 GlDrawConeWandFunctor::~GlDrawConeWandFunctor()
00053 {
00054    if ( NULL != mQuadObj )
00055    {
00056       gluDeleteQuadric(mQuadObj);
00057       mQuadObj = NULL;
00058    }
00059 }
00060 
00061 void GlDrawConeWandFunctor::draw(vrj::User* user)
00062 {
00063    boost::ignore_unused_variable_warning(user);
00064 
00065    const float base = 0.2f;
00066    const float height = 0.6f;
00067    const int slices = 6;
00068    const int stacks = 1;
00069 
00070    glColor3f(0.0f, 1.0f, 0.0f);
00071    gluQuadricDrawStyle(mQuadObj, (GLenum) GLU_FILL);
00072    gluQuadricNormals(mQuadObj, (GLenum) GLU_SMOOTH);
00073    gluCylinder(mQuadObj, base, 0.0, height, slices, stacks);
00074 }
00075 
00076 void GlDrawRightAngleWandFunctor::draw(vrj::User* user)
00077 {
00078    boost::ignore_unused_variable_warning(user);
00079 
00080    static GLfloat VertexData[] = {
00081       0.0140000f, -0.140000f, 0.0140000f, 0.0140000f, 0.028000f, 0.0140000f, -0.0140000f, 0.028000f, 0.0140000f,
00082       -0.0140000f, -0.140000f, 0.0140000f, 0.0140000f, -0.140000f, -0.0140000f,
00083       0.0140000f, 0.00000f, -0.0140000f, 0.0140000f, 0.028000f, 0.0140000f,
00084       0.0140000f, -0.140000f, 0.0140000f, -0.0140000f, -0.140000f, -0.0140000f,
00085       -0.0140000f, 0.00000f, -0.0140000f, 0.0140000f, 0.00000f, -0.0140000f,
00086       0.0140000f, -0.140000f, -0.0140000f, -0.0140000f, -0.140000f, 0.0140000f,
00087       -0.0140000f, 0.028000f, 0.0140000f, -0.0140000f, 0.00000f, -0.0140000f,
00088       -0.0140000f, -0.140000f, -0.0140000f, -0.0140000f, -0.140000f, -0.0140000f,
00089       0.0140000f, -0.140000f, -0.0140000f, 0.0140000f, -0.140000f, 0.0140000f,
00090       -0.0140000f, -0.140000f, 0.0140000f, -0.0140000f, 0.028000f, 0.0140000f,
00091       0.0140000f, 0.028000f, 0.0140000f, 0.028000f, 0.056000f, -0.042000f,
00092       -0.028000f, 0.056000f, -0.042000f, 0.028000f, 0.042000f, -0.042000f,
00093       -0.028000f, 0.042000f, -0.042000f, -0.028000f, 0.056000f, -0.042000f,
00094       0.028000f, 0.056000f, -0.042000f, 0.0140000f, 0.028000f, 0.0140000f,
00095       0.0140000f, 0.00000f, -0.0140000f, 0.028000f, 0.042000f, -0.042000f,
00096       0.0140000f, 0.028000f, 0.0140000f, 0.028000f, 0.042000f, -0.042000f,
00097       0.028000f, 0.056000f, -0.042000f, -0.0140000f, 0.028000f, 0.0140000f,
00098       -0.028000f, 0.056000f, -0.042000f, -0.028000f, 0.042000f, -0.042000f,
00099       -0.028000f, 0.042000f, -0.042000f, -0.0140000f, 0.00000f, -0.0140000f,
00100       -0.0140000f, 0.028000f, 0.0140000f, 0.028000f, 0.042000f, -0.042000f,
00101       0.0140000f, 0.00000f, -0.0140000f, -0.0140000f, 0.00000f, -0.0140000f,
00102       -0.028000f, 0.042000f, -0.042000f
00103    };
00104    static GLuint Indices[] = {
00105       0, 1, 2,
00106       0, 2, 3,
00107       4, 5, 6,
00108       4, 6, 7,
00109       8, 9, 10,
00110       8, 10, 11,
00111       12, 13, 14,
00112       12, 14, 15,
00113       16, 17, 18,
00114       16, 18, 19,
00115       20, 21, 22,
00116       20, 22, 23,
00117       24, 25, 26,
00118       24, 26, 27,
00119       28, 29, 30,
00120       31, 32, 33,
00121       34, 35, 36,
00122       37, 38, 39,
00123       40, 41, 42,
00124       40, 42, 43
00125    };
00126 
00127    static GLfloat NormData[] = {
00128       0.0f, -0.0f, 0.004704f,
00129       0.0f, 0.0f, 0.004704f,
00130       0.00392f, 0.0f, 0.0f,
00131       0.004704f, 0.0f, 0.0f,
00132       0.0f, 0.0f, -0.00392f,
00133       0.0f, 0.0f, -0.00392f,
00134       0.004704f, 0.0f, 0.0f,
00135       0.00392f, 0.0f, 0.0f,
00136       0.0f, -0.000784f, 0.0f,
00137       0.0f, -0.000784f, 0.0f,
00138       0.0f, 0.001568f, 0.000784f,
00139       3.16352e-11f, 0.003136f, 0.001568f,
00140       0.0f, 0.0f, -0.000784f,
00141       0.0f, 0.0f, -0.000784f,
00142       0.00196f, -0.000392f, 0.000392f,
00143       0.000784f, 1.58176e-11f, 0.000196f,
00144       0.000784f, -1.58176e-11f, 0.000196f,
00145       0.00196f, -0.000392f, 0.000392f,
00146       4.84511e-11f, -0.000784f, -0.001176f,
00147       0.0f, -0.001568f, -0.002352f
00148    };
00149 
00150 #if 0
00151    unsigned num_tris(20);
00152 
00153    // USED to generate normals
00154    static bool first_time(true);
00155 
00156    if(first_time)
00157    {
00158       first_time = false;
00159 
00160       unsigned j;       // vertex offset
00161       std::vector<gmtl::Vec3f> norms;
00162 
00163       // For each triangle
00164       for(unsigned i=0;i<num_tris;i++)
00165       {
00166          j = 3*Indices[(i*3)+0];
00167          gmtl::Vec3f v1(VertexData[j], VertexData[j+1], VertexData[j+2]);
00168          j = 3*Indices[(i*3)+1];
00169          gmtl::Vec3f v2(VertexData[j], VertexData[j+1], VertexData[j+2]);
00170          j = 3*Indices[(i*3)+2];
00171          gmtl::Vec3f v3(VertexData[j], VertexData[j+1], VertexData[j+2]);
00172          gmtl::Vec3f normal;
00173          normal = gmtl::cross(normal, gmtl::Vec3f(v2-v1), gmtl::Vec3f(v3-v1));
00174          norms.push_back(normal);
00175          std::cout << i << ": " << normal << std::endl;
00176       }
00177    }
00178 
00179    glPushAttrib(GL_LIGHTING_BIT);
00180    glDisable(GL_LIGHTING);
00181    glColor3f(1.0,0.0f,0.0f);
00182    glBegin(GL_LINES);
00183       for(unsigned i=0;i<20;i++)
00184       {
00185          gmtl::Vec3f norm;    norm.set(&(NormData[(i*3)]));
00186          //norm = norms[i];
00187          gmtl::Vec3f v0;      v0.set( &(VertexData[3*Indices[(i*3)+0]]));
00188          gmtl::Vec3f v1 = v0+norm;
00189          glVertex3fv(v0.getData());
00190          glVertex3fv(v1.getData());
00191       }
00192    glEnd();
00193    glPopAttrib();
00194 #endif
00195 
00196    glColor3f(0.00000f, 1.00000f, 0.00000f);
00197 
00198    glBegin(GL_TRIANGLES);
00199    for(unsigned i=0;i<20;i++)
00200    {
00201       glNormal3fv(&(NormData[i*3]));
00202       glVertex3fv(&(VertexData[3*Indices[(i*3)+0]]));
00203       glVertex3fv(&(VertexData[3*Indices[(i*3)+1]]));
00204       glVertex3fv(&(VertexData[3*Indices[(i*3)+2]]));
00205    }
00206    glEnd();
00207 }
00208 
00209 }

Generated on Thu Jan 4 10:56:51 2007 for VR Juggler by  doxygen 1.5.1