00001
00002
00003
00004 #include <GL/gl.h>
00005 #include "mesh3.h"
00006
00008 mesh3::surface::~surface( void )
00009 {
00010
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
00024 for( point_list::iterator i = m_vertexes.begin( );
00025 i != m_vertexes.end( ); ++i ) {
00026 delete *i;
00027 }
00028
00029
00030 for( normal_list::iterator i = m_normals.begin( );
00031 i != m_normals.end( ); ++i ) {
00032 delete *i;
00033 }
00034
00035
00036 for( uv_list::iterator i = m_uvs.begin( );
00037 i != m_uvs.end( ); ++i ) {
00038 delete *i;
00039 }
00040
00041
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
00053 if( face.texture ) {
00054
00055 face.texture.bind( );
00056 glBegin( GL_TRIANGLES );
00057 if( face.vertex[ 0 ].normal_index > 0 ) {
00058
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
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
00075 glBegin( GL_TRIANGLES );
00076 if( face.vertex[ 0 ].normal_index > 0 ) {
00077
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
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
00098 for( mesh3::surface::const_iterator i = surf.begin( );
00099 i != surf.end( ); ++i ) {
00100
00101 render_triangle( **i );
00102 }
00103 }
00104
00106 void
00107 mesh3::render( void ) const
00108 {
00109
00110 for( surface_list::const_iterator i = m_surfaces.begin( );
00111 i != m_surfaces.end( ); ++i ) {
00112
00113 render_surface( **i );
00114 }
00115 }