QuadNode.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 QuadNode - IMPLEMENTATION
00049 //
00050 //=============================================================================
00051 
00052 
00053 //== INCLUDES =================================================================
00054 
00055 
00056 #include "QuadNode.hh"
00057 #include "DrawModes.hh"
00058 
00059 
00060 //== NAMESPACES ============================================================== 
00061 
00062 
00063 namespace ACG {
00064 namespace SceneGraph {
00065 
00066 
00067 //== IMPLEMENTATION ========================================================== 
00068 
00069 
00070 QuadNode::QuadNode( BaseNode*   _parent,
00071                             std::string _name  )
00072   : BaseNode(_parent, _name)
00073 {
00074 }
00075   
00076 
00077 //----------------------------------------------------------------------------
00078 
00079 
00080 QuadNode::~QuadNode() 
00081 {
00082 }
00083 
00084 
00085 //----------------------------------------------------------------------------
00086 
00087 
00088 void
00089 QuadNode::boundingBox( Vec3f & _bbMin, Vec3f & _bbMax )
00090 {
00091   PointVector::const_iterator p_it  = point_.begin(),
00092                               p_end = point_.end();
00093 
00094   for ( ; p_it != p_end; ++p_it )
00095   {
00096     _bbMin.minimize( *p_it );
00097     _bbMax.maximize( *p_it );
00098   }
00099 }
00100 
00101 
00102 //----------------------------------------------------------------------------
00103 
00104   
00105 unsigned int 
00106 QuadNode::
00107 availableDrawModes() const
00108 {
00109   unsigned int drawModes(0);
00110   
00111   drawModes |= DrawModes::WIREFRAME;
00112   drawModes |= DrawModes::HIDDENLINE;
00113   drawModes |= DrawModes::SOLID_FLAT_SHADED;
00114   //  drawModes |= DrawModes::SOLID_FACES_COLORED;
00115 
00116   return drawModes;
00117 }
00118 
00119 
00120 //----------------------------------------------------------------------------
00121 
00122 
00123 void
00124 QuadNode::
00125 draw(GLState& /* _state */ , unsigned int _drawMode)
00126 {
00127   glDepthFunc(depthFunc());
00128 
00129   if (_drawMode & DrawModes::WIREFRAME ||
00130       _drawMode & DrawModes::HIDDENLINE )
00131   {
00132     glDisable(GL_LIGHTING);
00133     glShadeModel(GL_FLAT);
00134     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00135     draw_wireframe();
00136     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00137   }
00138 
00139 
00140   if (_drawMode & DrawModes::SOLID_FLAT_SHADED ||
00141       _drawMode & DrawModes::HIDDENLINE )
00142   {
00143     glEnable(GL_LIGHTING);
00144     glShadeModel(GL_FLAT);
00145     glDepthRange(0.01, 1.0);
00146     draw_faces();
00147     glDepthRange(0.0, 1.0);
00148   }
00149 
00150   if (_drawMode & DrawModes::SOLID_FACES_COLORED)
00151   {
00152     glDisable(GL_LIGHTING);
00153     glShadeModel(GL_FLAT);
00154     glDepthRange(0.01, 1.0);
00155     draw_faces();
00156     glDepthRange(0.0, 1.0);
00157   }
00158 }
00159 
00160 
00161 //----------------------------------------------------------------------------
00162 
00163 
00164 void
00165 QuadNode::
00166 draw_vertices()
00167 {
00168   //  glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
00169 }
00170 
00171 
00172 //----------------------------------------------------------------------------
00173 
00174 
00175 void
00176 QuadNode::draw_faces()
00177 {
00178   glBegin(GL_QUADS);
00179 
00180   unsigned int i = 0;
00181   unsigned int j = 0;
00182 
00183   for ( ; i < point_.size(); i += 4, j += 1 )
00184   {
00185     glNormal(  normal_[j] );
00186     
00187     glVertex( point_[i + 0] );
00188     glVertex( point_[i + 1] );
00189     glVertex( point_[i + 2] );
00190     glVertex( point_[i + 3] );
00191   }
00192 
00193   glEnd();
00194 }
00195 
00196 
00197 //----------------------------------------------------------------------------
00198 
00199 
00200 void
00201 QuadNode::draw_wireframe()
00202 {
00203   glBegin(GL_QUADS);
00204   for ( unsigned int i = 0; i < point_.size(); ++i )
00205     glVertex( point_[i] );
00206   glEnd();
00207 }
00208 
00209 
00210 //----------------------------------------------------------------------------
00211 
00212 
00213 void
00214 QuadNode::pick( GLState & _state, PickTarget /* _target */  )
00215 {
00216   _state.pick_set_maximum (1);
00217   _state.pick_set_name (0);
00218   draw_faces();
00219 }
00220 
00221 
00222 //----------------------------------------------------------------------------
00223 
00224 //=============================================================================
00225 } // namespace SceneGraph
00226 } // namespace ACG
00227 //=============================================================================

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