GlutPrimitiveNode.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS GlutPrimitiveNode - IMPLEMENTATION
00049 //
00050 //=============================================================================
00051 
00052 
00053 //== INCLUDES =================================================================
00054 
00055 #include "GlutPrimitiveNode.hh"
00056 #include "../GL/gl.hh"
00057 
00058 
00059 //== NAMESPACES ===============================================================
00060 
00061 namespace ACG {
00062 namespace SceneGraph {
00063 
00064 
00065 //== IMPLEMENTATION ========================================================== 
00066 
00067 
00068 void
00069 GlutPrimitiveNode::
00070 boundingBox(Vec3f& _bbMin, Vec3f& _bbMax)
00071 {
00072   if (_bbMin[0] > -size_)  _bbMin[0] = -size_;
00073   if (_bbMin[1] > -size_)  _bbMin[1] = -size_;
00074   if (_bbMin[2] > -size_)  _bbMin[2] = -size_;
00075   if (_bbMax[0] <  size_)  _bbMax[0] =  size_;
00076   if (_bbMax[1] <  size_)  _bbMax[1] =  size_;
00077   if (_bbMax[2] <  size_)  _bbMax[2] =  size_;
00078 }
00079 
00080 
00081 //----------------------------------------------------------------------------
00082 
00083   
00084 unsigned int 
00085 GlutPrimitiveNode::
00086 availableDrawModes() const
00087 {
00088   return ( DrawModes::POINTS              |
00089            DrawModes::WIREFRAME           |
00090            DrawModes::HIDDENLINE          |
00091            DrawModes::SOLID_FLAT_SHADED   |
00092            DrawModes::SOLID_SMOOTH_SHADED );
00093 }
00094 
00095 
00096 //----------------------------------------------------------------------------
00097 
00098 
00099 void
00100 GlutPrimitiveNode::
00101 draw(GLState& _state, unsigned int _drawMode)
00102 {
00103   glDepthFunc(depthFunc());
00104   glPushMatrix();
00105   glTranslatef(position_[0], position_[1], position_[2]);
00106 
00107 
00108   if (_drawMode & DrawModes::POINTS)
00109   {
00110     glDisable(GL_LIGHTING);
00111     glShadeModel(GL_FLAT);
00112     glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
00113     draw_obj();
00114     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00115   }
00116 
00117 
00118   if (_drawMode & DrawModes::WIREFRAME)
00119   {
00120     glDisable(GL_LIGHTING);
00121     glShadeModel(GL_FLAT);
00122     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00123     draw_obj();
00124     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00125   }
00126 
00127 
00128   if (_drawMode & DrawModes::HIDDENLINE)
00129   {
00130     Vec4f base_color_backup = _state.base_color();
00131 
00132     glDisable(GL_LIGHTING);
00133     glShadeModel(GL_FLAT);
00134 
00135     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00136     glColor(_state.clear_color());
00137     glDepthRange(0.01, 1.0);
00138     draw_obj();
00139 
00140     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00141     glColor(base_color_backup);
00142     glDepthRange(0.0, 1.0);
00143     draw_obj();
00144 
00145     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00146   }
00147 
00148 
00149   if (_drawMode & DrawModes::SOLID_FLAT_SHADED)
00150   {
00151     glEnable(GL_LIGHTING);
00152     glShadeModel(GL_FLAT);
00153     draw_obj();
00154   }
00155 
00156 
00157   if (_drawMode & DrawModes::SOLID_SMOOTH_SHADED)
00158   {
00159     glEnable(GL_LIGHTING);
00160     glShadeModel(GL_SMOOTH);
00161     draw_obj();
00162   }
00163 
00164 
00165   glPopMatrix();
00166   glDepthFunc(GL_LESS);
00167 }
00168 
00169 
00170 //----------------------------------------------------------------------------
00171 
00172 
00173 void
00174 GlutPrimitiveNode::draw_obj() const
00175 {
00176   switch (type_)
00177   {
00178     case CONE: 
00179       glutSolidCone(size_, innersize_, slices_, stacks_);
00180       break;
00181  
00182     case CUBE: 
00183       glutSolidCube(size_);
00184       break;
00185     
00186     case DODECAHEDRON: 
00187       glutSolidDodecahedron();
00188       break;
00189     
00190     case ICOSAHEDRON: 
00191       glutSolidIcosahedron();
00192       break;
00193 
00194     case OCTAHEDRON:
00195       glutSolidOctahedron();
00196       break;
00197 
00198     case  SPHERE: 
00199       glutSolidSphere(size_, slices_, stacks_);
00200       break;
00201        
00202     case TEAPOT: 
00203       glutSolidTeapot(size_);
00204       break;
00205 
00206     case TETRAHEDRON: 
00207       glutSolidTetrahedron();
00208       break;
00209  
00210     case TORUS: 
00211       glutSolidTorus(innersize_, size_, slices_, stacks_);
00212       break;
00213   };
00214 }
00215 
00216 
00217 //----------------------------------------------------------------------------
00218 
00219 
00220 void
00221 GlutPrimitiveNode::
00222 pick(GLState& _state , PickTarget _target)
00223 {
00224   // initialize picking stack
00225   if (!_state.pick_set_maximum (1))
00226   {
00227     std::cerr << "Strange pickSetMaximum failed for index 1 in GlutPrimitiveNode\n";
00228     return;
00229   }
00230   _state.pick_set_name(0);
00231 
00232 
00233   switch (_target)
00234   {
00235     case PICK_ANYTHING:
00236     case PICK_FACE: 
00237     { 
00238       glDisable(GL_LIGHTING);
00239       glShadeModel(GL_FLAT);
00240       glPushMatrix();
00241       glTranslatef(position_[0], position_[1], position_[2]);
00242       draw_obj();
00243       glPopMatrix();
00244       break; 
00245     }
00246 
00247     default:
00248       break;
00249   }      
00250 }
00251 
00252 
00253 //=============================================================================
00254 } // namespace SceneGraph
00255 } // namespace ACG
00256 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .