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