basic/opengl/GL_Mesh.cpp

Go to the documentation of this file.
00001 //## begin module%37434FEC021C.cm preserve=no
00002 //        %X% %Q% %Z% %W%
00003 //## end module%37434FEC021C.cm
00004 
00005 //## begin module%37434FEC021C.cp preserve=no
00006 //## end module%37434FEC021C.cp
00007 
00008 //## Module: GL_Mesh%37434FEC021C; Pseudo Package body
00009 //## Source file: C:\project\mpk\code\OpenGL\GL_Mesh.cpp
00010 
00011 //## begin module%37434FEC021C.additionalIncludes preserve=no
00012 //## end module%37434FEC021C.additionalIncludes
00013 
00014 //## begin module%37434FEC021C.includes preserve=yes
00015 #include "../geometry/Facet.h"
00016 #ifndef NOGL
00017 #include "glos.h"
00018 #include < gl\gl.h >
00019 #endif
00020 //## end module%37434FEC021C.includes
00021 
00022 // Vector4
00023 #include "math\Vector4.h"
00024 // GL_Mesh
00025 #include "OpenGL\GL_Mesh.h"
00026 //## begin module%37434FEC021C.additionalDeclarations preserve=yes
00027 //## end module%37434FEC021C.additionalDeclarations
00028 
00029 
00030 // Class GL_Mesh 
00031 
00032 
00033 GL_Mesh::GL_Mesh (FrameManager* frameManager)
00034   :Mesh( frameManager )
00035 {
00036 }
00037 
00038 GL_Mesh::GL_Mesh (const GL_Mesh& right)
00039   :Mesh( right )
00040 {
00041 }
00042 
00043 //=============================================================================
00044 // Constructor
00045 //
00046 // Description: constructs a GL_Mesh
00047 //=============================================================================
00048 GL_Mesh::GL_Mesh( const IGS_MeshTri& right )
00049 :
00050         Mesh( right )
00051 {
00052         //nothing here intentionally
00053         this->ComputeNormals(); //just for debugging
00054 }
00055 
00056 GL_Mesh::~GL_Mesh()
00057 {
00058   //## begin GL_Mesh::~GL_Mesh%.body preserve=yes
00059 #ifndef NOGL
00060         if( displayListNumber != -1 )
00061         {
00062                 glDeleteLists( displayListNumber, 1 ) ;
00063         }
00064 #endif
00065   //## end GL_Mesh::~GL_Mesh%.body
00066 }
00067 
00068 
00069 
00070 //## Other Operations (implementation)
00071 Entity* GL_Mesh::Clone () const
00072 {
00073   //## begin GL_Mesh::Clone%927157753.body preserve=yes
00074         return new GL_Mesh( *this ) ;
00075   //## end GL_Mesh::Clone%927157753.body
00076 }
00077 
00078 void GL_Mesh::ComputeNormals () const
00079 {
00080   //## begin GL_Mesh::ComputeNormals%927936641.body preserve=yes
00081 
00082         //clear all the old normal vectors
00083         normals.clear() ;
00084 
00085         //for each of the facets, compute the normal vector
00086         int fsize = facets.size();
00087         for( int i = 0; i < fsize; i++ )
00088         {
00089                 const Facet& facet = facets[ i ];
00090 
00091                 int vnsize = facet.vertexNumbers.size();
00092                 int i0 = facet.vertexNumbers[ 0 ];
00093                 int i1 = facet.vertexNumbers[ 1 ];
00094                 int i2 = facet.vertexNumbers[ 2 ];
00095                 int vsize = vertexes.size();
00096         
00097 
00098                 Vector4 v1 = vertexes[ i0 ];            //IMPROVE: this is slower than necessary
00099                 Vector4 v2 = vertexes[ i1 ];
00100                 Vector4 v3 = vertexes[ i2 ];
00101                 
00102                 Vector4 normal = ( v2 - v1 ).Cross( v3 - v1 );
00103                 normal.Normalize();
00104                 
00105                 normals.push_back( normal );
00106         }
00107   //## end GL_Mesh::ComputeNormals%927936641.body
00108 }
00109 
00110 bool GL_Mesh::DrawExplicit () const
00111 {
00112 #ifndef NOGL
00113   //## begin GL_Mesh::DrawExplicit%950474929.body preserve=yes
00114         this->Validate();
00115 
00116         if( normals.size() != facets.size() )
00117         {
00118                 ComputeNormals() ;
00119         }
00120 
00121         //draw all of the facets
00122         int size = facets.size() ;
00123         for( int i = 0; i < size; i++ )
00124         {
00125                 //draw an individual facet
00126                 Facet facet = facets[ i ] ;
00127 
00128                 glBegin( GL_POLYGON ) ;
00129 
00130                 Vector4 normal = normals[ i ] ;
00131                 glNormal3d( normal[ 0 ], normal[ 1 ], normal[ 2 ] ) ;
00132                 for( int j = 0; j < facet.vertexNumbers.size(); j++ )
00133                 {
00134                         double x = ( vertexes[ facet.vertexNumbers[ j ] ] )[ 0 ] ;
00135                         double y = ( vertexes[ facet.vertexNumbers[ j ] ] )[ 1 ] ;
00136                         double z = ( vertexes[ facet.vertexNumbers[ j ] ] )[ 2 ] ;
00137 
00138                         glVertex3d( x,  y,      z ) ;
00139                 }
00140                 glEnd() ;
00141         }
00142 #endif
00143         return true ;
00144   //## end GL_Mesh::DrawExplicit%950474929.body
00145 }
00146 
00147 // Additional Declarations
00148   //## begin GL_Mesh%37434FEC021C.declarations preserve=yes
00149   //## end GL_Mesh%37434FEC021C.declarations
00150 
00151 //## begin module%37434FEC021C.epilog preserve=yes
00152 //## end module%37434FEC021C.epilog
00153 
00154 
00155 // Detached code regions:
00156 // WARNING: this code will be lost if code is regenerated.

Generated on Sat Apr 1 21:30:35 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO