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