GlDrawHeadFunctors.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 <gmtl/Vec.h>
00036 
00037 #include <vrj/Kernel/User.h>
00038 #include <vrj/Draw/OGL/GlDrawHeadFunctors.h>
00039 
00040 
00041 namespace vrj
00042 {
00043 
00044 GlDrawEllipsoidHeadFunctor::GlDrawEllipsoidHeadFunctor()
00045    : mQuadObj(gluNewQuadric())
00046 {
00047 }
00048 
00049 GlDrawEllipsoidHeadFunctor::~GlDrawEllipsoidHeadFunctor()
00050 {
00051    gluDeleteQuadric(mQuadObj);
00052 }
00053 
00054 void GlDrawEllipsoidHeadFunctor::draw(vrj::User* user)
00055 {
00056    // All units are in meters.
00057    const float head_height(0.254f);      // 10 inches
00058    const float head_width_scale(0.7f);
00059    const float head_depth_scale(0.8f);
00060    //const float eye_vertical(0.067f);
00061    //const float eye_horizontal(0.21f);
00062    const float interocular(user->getInterocularDistance());
00063    const float eye_radius(0.0254f * 0.5f);      // 0.5 in
00064 
00065    glPushMatrix();
00066       // Head pos is the center of the eyes, so we need to move the head offset
00067       // a bit to get it positioned correctly.  We will do this by measuring
00068       // the distance from center of head to forehead and then translate by
00069       // the negative of that.
00070       gmtl::Vec3f forehead_offset(0.0f, head_height*0.17f,
00071                                   -(head_depth_scale*head_height)*0.45f);
00072       glTranslatef(-forehead_offset[0], -forehead_offset[1],
00073                    -forehead_offset[2]);
00074 
00075       // Scale to get an ellipsoid head.
00076       glScalef(head_width_scale, 1.0f, head_depth_scale);
00077       //glEnable(GL_BLEND);
00078       //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00079       glColor4f(0.5f, 0.75f, 0.90f, 0.67f);
00080       drawSphere(head_height/2.0f, 10, 10);             // Head
00081       //glDisable(GL_BLEND);
00082    glPopMatrix();
00083 
00084    // --- Draw the eyes --- //
00085    glPushMatrix();
00086       glColor3f(0.8f, 0.4f, 0.2f);
00087       //glTranslatef(0.0f, eye_vertical, -eye_horizontal);
00088       glPushMatrix();                     // Right eye
00089          glTranslatef((interocular/2.0f), 0.0f, 0.0f);
00090          drawSphere(eye_radius, 5, 5);
00091       glPopMatrix();
00092       glPushMatrix();                     // Left eye
00093          glTranslatef(-(interocular/2.0f), 0.0f, 0.0f);
00094          drawSphere(eye_radius, 5, 5);
00095       glPopMatrix();
00096    glPopMatrix();
00097 }
00098 
00099 void GlDrawEllipsoidHeadFunctor::drawSphere(const float radius,
00100                                             const int slices, const int stacks)
00101 {
00102   gluQuadricDrawStyle(mQuadObj, (GLenum) GLU_FILL);
00103   gluQuadricNormals(mQuadObj, (GLenum) GLU_SMOOTH);
00104   gluSphere(mQuadObj, radius, slices, stacks);
00105 }
00106 
00107 }

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