Blender V2.61 - r43446
|
00001 00028 #ifndef NAN_INCLUDED_GlutMeshDrawer_h 00029 #define NAN_INCLUDED_GlutMeshDrawer_h 00030 00031 #include "common/GlutDrawer.h" 00032 #include "LOD_decimation.h" 00033 #include "MyGlutMouseHandler.h" 00034 #include <math.h> 00035 #include <iostream> 00036 #include <iterator> 00037 #if defined(WIN32) || defined(__APPLE__) 00038 #ifdef WIN32 00039 #include <windows.h> 00040 #include <GL/gl.h> 00041 #include <GL/glu.h> 00042 #else // WIN32 00043 // __APPLE__ is defined 00044 #include <AGL/gl.h> 00045 #endif // WIN32 00046 #else // defined(WIN32) || defined(__APPLE__) 00047 #include <GL/gl.h> 00048 #include <GL/glu.h> 00049 #endif // defined(WIN32) || defined(__APPLE__) 00050 #include <vector> 00051 // a concrete mesh drawer 00052 00053 class GlutMeshDrawer : public GlutDrawer 00054 { 00055 public : 00056 static 00057 GlutMeshDrawer * 00058 New( 00059 ) { 00060 return new GlutMeshDrawer(); 00061 } 00062 00063 // set the mesh to draw 00064 00065 void 00066 SetLODInfo( 00067 LOD_Decimation_InfoPtr info 00068 ){ 00069 m_info = info; 00070 } 00071 00072 void 00073 SetMouseHandler( 00074 MyGlutMouseHandler *mouse_handler 00075 ) { 00076 m_mouse_handler = mouse_handler; 00077 } 00078 00079 00080 // inherited from GlutDrawer 00081 void 00082 Draw( 00083 ) { 00084 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00085 glPopMatrix(); 00086 glPushMatrix(); 00087 glRotatef(m_mouse_handler->AngleX(), 0.0, 1.0, 0.0); 00088 glRotatef(m_mouse_handler->AngleY(), 1.0, 0.0, 0.0); 00089 00090 DrawScene(); 00091 } 00092 00093 ~GlutMeshDrawer( 00094 ){ 00095 // nothing to do 00096 }; 00097 00098 private : 00099 00100 void 00101 DrawScene( 00102 ){ 00103 00104 float * verts = m_info->vertex_buffer; 00105 const int num_verts = m_info->vertex_num; 00106 00107 float * vertex_normals = m_info->vertex_normal_buffer; 00108 00109 00110 int * index = m_info->triangle_index_buffer; 00111 const int num_faces = m_info->face_num; 00112 00113 glBegin(GL_TRIANGLES); 00114 00115 float mat_spec1[] = {1.0,1.0,1.0,1.0}; 00116 float mat_spec2[] = {1.0,0.0,1.0,1.0}; 00117 float mat_spec3[] = {1.0,1.0,0.0,1.0}; 00118 float mat_spec4[] = {0.0,0.0,1.0,1.0}; 00119 00120 00121 00122 int i; 00123 for (i= 0; i < num_faces; i++) { 00124 #if 0 00125 int col = i%4; 00126 if (col == 0) { 00127 glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_spec1); 00128 } else 00129 if (col == 1) { 00130 glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_spec2); 00131 } else 00132 if (col == 2) { 00133 glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_spec3); 00134 } else 00135 if (col == 3) { 00136 glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_spec4); 00137 } 00138 #endif 00139 glNormal3fv(vertex_normals + 3*index[3*i]); 00140 glVertex3fv(verts + 3*index[3*i]); 00141 00142 glNormal3fv(vertex_normals + 3*index[3*i + 1]); 00143 glVertex3fv(verts + 3*index[3*i + 1]); 00144 00145 glNormal3fv(vertex_normals + 3*index[3*i + 2]); 00146 glVertex3fv(verts + 3*index[3*i + 2]); 00147 00148 } 00149 glEnd(); 00150 00151 00152 }; 00153 00154 00155 00156 private : 00157 00158 LOD_Decimation_InfoPtr m_info; 00159 00160 MyGlutMouseHandler * m_mouse_handler; 00161 00162 GlutMeshDrawer ( 00163 ) : m_info (NULL) { 00164 }; 00165 00166 }; 00167 00168 00169 #endif 00170