Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

mesh3.cpp

00001 //FILE:         mesh3.cpp
00002 //AUTHOR:       Nathan Cournia <nathan@cournia.com>
00003 
00004 #include <GL/gl.h>
00005 #include "mesh3.h"
00006 
00008 mesh3::surface::~surface( void )
00009 {
00010         //delete all triangles in surface
00011         for( iterator i = begin( ); i != end( ); ++i ) {
00012                 delete *i;
00013         }
00014 }
00015 
00017 mesh3::mesh3( void )
00018 { }
00019 
00021 mesh3::~mesh3( void )
00022 {
00023         //delete vertexes
00024         for( point_list::iterator i = m_vertexes.begin( ); 
00025                 i != m_vertexes.end( ); ++i ) {
00026                 delete *i;
00027         }
00028 
00029         //delete normals
00030         for( normal_list::iterator i = m_normals.begin( ); 
00031                 i != m_normals.end( ); ++i ) {
00032                 delete *i;
00033         }
00034 
00035         //delete uvs
00036         for( uv_list::iterator i = m_uvs.begin( ); 
00037                 i != m_uvs.end( ); ++i ) {
00038                 delete *i;
00039         }
00040         
00041         //delete surfaces
00042         for( surface_list::iterator i = m_surfaces.begin( ); 
00043                 i != m_surfaces.end( ); ++i ) {
00044                 delete *i;
00045         }
00046 }
00047 
00049 void
00050 mesh3::render_triangle( const mesh3::triangle& face ) const
00051 {
00052         //is there a texture
00053         if( face.texture ) {
00054                 //render triangle with texture
00055                 face.texture.bind( );
00056                 glBegin( GL_TRIANGLES );
00057                 if( face.vertex[ 0 ].normal_index > 0 ) {
00058                         //render with normals
00059                         for( unsigned int i = 0; i < MESH3_VERTS; ++i ) {
00060                                 glNormal3fv( *(m_normals[ face.vertex[ i ].normal_index ]) );
00061                                 glTexCoord2fv( m_uvs[ face.vertex[ i ].uv_index ]->uv );
00062                                 glVertex3fv( *(m_vertexes[ face.vertex[ i ].vertex_index ]) );
00063                         } 
00064                 } else {
00065                         //render without normals
00066                         for( unsigned int i = 0; i < MESH3_VERTS; ++i ) {
00067                                 glNormal3fv( *(m_normals[ face.vertex[ i ].normal_index ]) );
00068                                 glTexCoord2fv( m_uvs[ face.vertex[ i ].uv_index ]->uv );
00069                                 glVertex3fv( *(m_vertexes[ face.vertex[ i ].vertex_index ]) );
00070                         }
00071                 }
00072                 glEnd( );
00073         } else {
00074                 //render without texture
00075                 glBegin( GL_TRIANGLES );
00076                 if( face.vertex[ 0 ].normal_index > 0 ) {
00077                         //render with normals
00078                         for( unsigned int i = 0; i < MESH3_VERTS; ++i ) {
00079                                 glNormal3fv( *(m_normals[ face.vertex[ i ].normal_index ]) );
00080                                 glVertex3fv( *(m_vertexes[ face.vertex[ i ].vertex_index ]) );
00081                         } 
00082                 } else {
00083                         //render without normals
00084                         for( unsigned int i = 0; i < MESH3_VERTS; ++i ) {
00085                                 glNormal3fv( *(m_normals[ face.vertex[ i ].normal_index ]) );
00086                                 glVertex3fv( *(m_vertexes[ face.vertex[ i ].vertex_index ]) );
00087                         }
00088                 }
00089                 glEnd( );
00090         }
00091 }
00092 
00094 void
00095 mesh3::render_surface( const mesh3::surface& surf ) const
00096 {
00097         //for each triangle in the surface
00098         for( mesh3::surface::const_iterator i = surf.begin( ); 
00099                 i != surf.end( ); ++i ) {
00100                 //render the triangle
00101                 render_triangle( **i );
00102         }
00103 }
00104 
00106 void
00107 mesh3::render( void ) const
00108 {
00109         //for each surface in the mesh
00110         for( surface_list::const_iterator i = m_surfaces.begin( ); 
00111                 i != m_surfaces.end( ); ++i ) {
00112                 //render the surface
00113                 render_surface( **i );
00114         }
00115 }

Generated on Tue Feb 11 18:49:41 2003 for uber by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002