$search
00001 //== INCLUDES ================================================================== 00002 #define GL_GLEXT_PROTOTYPES 00003 00004 #include "rtc/rtcGraphicsHelper.h" 00005 00006 //== NAMESPACES =============================================================== 00007 namespace rtc { 00008 00009 GraphicsHelper::GraphicsHelper(void) 00010 { 00011 arrow_initialized = false; 00012 arrow_triangle_vertices_vbo = 0; 00013 arrow_triangle_normals_vbo = 0; 00014 arrow_quad_vertices_vbo = 0; 00015 arrow_quad_normals_vbo = 0; 00016 sphere_display_initialized=false; 00017 } 00018 00019 GraphicsHelper::~GraphicsHelper(void) 00020 { 00021 } 00022 00023 00024 // Triangle vertices: 00025 const int num_arrow_triangle_faces = 8; 00026 const int num_arrow_triangle_vertices = num_arrow_triangle_faces*3; 00027 const GLfloat arrow_triangle_vertices[num_arrow_triangle_vertices*3] = { 00028 0.000000f,0.040000f,-0.800000f,0.028284f,0.028284f,-0.800000f, 00029 0.000000f,0.000000f,-1.000000f,0.028284f,0.028284f,-0.800000f, 00030 0.040000f,0.000000f,-0.800000f,0.000000f,0.000000f,-1.000000f, 00031 0.040000f,0.000000f,-0.800000f,0.028284f,-0.028284f,-0.800000f, 00032 0.000000f,0.000000f,-1.000000f,0.028284f,-0.028284f,-0.800000f, 00033 0.000000f,-0.040000f,-0.800000f,0.000000f,0.000000f,-1.000000f, 00034 0.000000f,-0.040000f,-0.800000f,-0.028284f,-0.028284f,-0.800000f, 00035 0.000000f,0.000000f,-1.000000f,-0.028284f,-0.028284f,-0.800000f, 00036 -0.040000f,0.000000f,-0.800000f,0.000000f,0.000000f,-1.000000f, 00037 -0.040000f,0.000000f,-0.800000f,-0.028284f,0.028284f,-0.800000f, 00038 0.000000f,0.000000f,-1.000000f,-0.028284f,0.028284f,-0.800000f, 00039 0.000000f,0.040000f,-0.800000f,0.000000f,0.000000f,-1.000000f 00040 }; 00041 const GLfloat arrow_triangle_normals[num_arrow_triangle_vertices*3] = { 00042 0.000000f,0.980581f,-0.196116f,0.693375f,0.693375f,-0.196116f, 00043 0.357407f,0.862856f,-0.357407f,0.693375f,0.693375f,-0.196116f, 00044 0.980581f,0.000000f,-0.196116f,0.862856f,0.357407f,-0.357407f, 00045 0.980581f,0.000000f,-0.196116f,0.693375f,-0.693375f,-0.196116f, 00046 0.862856f,-0.357407f,-0.357407f,0.693375f,-0.693375f,-0.196116f, 00047 0.000000f,-0.980581f,-0.196116f,0.357407f,-0.862856f,-0.357407f, 00048 0.000000f,-0.980581f,-0.196116f,-0.693375f,-0.693375f,-0.196116f, 00049 -0.357407f,-0.862856f,-0.357407f,-0.693375f,-0.693375f,-0.196116f, 00050 -0.980581f,0.000000f,-0.196116f,-0.862856f,-0.357407f,-0.357407f, 00051 -0.980581f,0.000000f,-0.196116f,-0.693375f,0.693375f,-0.196116f, 00052 -0.862856f,0.357407f,-0.357407f,-0.693375f,0.693375f,-0.196116f, 00053 0.000000f,0.980581f,-0.196116f,-0.357407f,0.862856f,-0.357407f 00054 }; 00055 00056 const int num_arrow_quad_faces = 16; 00057 const int num_arrow_quad_vertices = num_arrow_quad_faces*4; 00058 const GLfloat arrow_quad_vertices[num_arrow_quad_vertices*3] = { 00059 0.000000f,0.010000f,0.000000f,0.007000f,0.007000f,0.000000f, 00060 0.007000f,0.007000f,-0.800000f,0.000000f,0.010000f,-0.800000f, 00061 0.000000f,-0.010000f,0.000000f,-0.007000f,-0.007000f,0.000000f, 00062 -0.007000f,-0.007000f,-0.800000f,0.000000f,-0.010000f,-0.800000f, 00063 -0.007000f,-0.007000f,0.000000f,-0.010000f,0.000000f,0.000000f, 00064 -0.010000f,0.000000f,-0.800000f,-0.007000f,-0.007000f,-0.800000f, 00065 -0.010000f,0.000000f,0.000000f,-0.007000f,0.007000f,0.000000f, 00066 -0.007000f,0.007000f,-0.800000f,-0.010000f,0.000000f,-0.800000f, 00067 -0.007000f,0.007000f,0.000000f,0.000000f,0.010000f,0.000000f, 00068 0.000000f,0.010000f,-0.800000f,-0.007000f,0.007000f,-0.800000f, 00069 0.007000f,0.007000f,0.000000f,0.010000f,0.000000f,0.000000f, 00070 0.010000f,0.000000f,-0.800000f,0.007000f,0.007000f,-0.800000f, 00071 0.010000f,0.000000f,0.000000f,0.007000f,-0.007000f,0.000000f, 00072 0.007000f,-0.007000f,-0.800000f,0.010000f,0.000000f,-0.800000f, 00073 0.007000f,-0.007000f,0.000000f,0.000000f,-0.010000f,0.000000f, 00074 0.000000f,-0.010000f,-0.800000f,0.007000f,-0.007000f,-0.800000f, 00075 -0.007000f,0.007000f,-0.800000f,-0.028284f,0.028284f,-0.800000f, 00076 -0.040000f,0.000000f,-0.800000f,-0.010000f,0.000000f,-0.800000f, 00077 -0.010000f,0.000000f,-0.800000f,-0.040000f,0.000000f,-0.800000f, 00078 -0.028284f,-0.028284f,-0.800000f,-0.007000f,-0.007000f,-0.800000f, 00079 -0.007000f,-0.007000f,-0.800000f,-0.028284f,-0.028284f,-0.800000f, 00080 0.000000f,-0.040000f,-0.800000f,0.000000f,-0.010000f,-0.800000f, 00081 0.000000f,-0.010000f,-0.800000f,0.000000f,-0.040000f,-0.800000f, 00082 0.028284f,-0.028284f,-0.800000f,0.007000f,-0.007000f,-0.800000f, 00083 0.028284f,-0.028284f,-0.800000f,0.040000f,0.000000f,-0.800000f, 00084 0.010000f,0.000000f,-0.800000f,0.007000f,-0.007000f,-0.800000f, 00085 0.040000f,0.000000f,-0.800000f,0.028284f,0.028284f,-0.800000f, 00086 0.007000f,0.007000f,-0.800000f,0.010000f,0.000000f,-0.800000f, 00087 0.007000f,0.007000f,-0.800000f,0.028284f,0.028284f,-0.800000f, 00088 0.000000f,0.040000f,-0.800000f,0.000000f,0.010000f,-0.800000f, 00089 0.000000f,0.010000f,-0.800000f,0.000000f,0.040000f,-0.800000f, 00090 -0.028284f,0.028284f,-0.800000f,-0.007000f,0.007000f,-0.800000f 00091 }; 00092 const GLfloat arrow_quad_normals[num_arrow_quad_vertices*3] = { 00093 0.000000f,1.000000f,0.000000f,0.707107f,0.707107f,0.000000f, 00094 0.707107f,0.707107f,0.000000f,0.000000f,1.000000f,0.000000f, 00095 0.000000f,-1.000000f,0.000000f,-0.707107f,-0.707107f,0.000000f, 00096 -0.707107f,-0.707107f,0.000000f,0.000000f,-1.000000f,0.000000f, 00097 -0.707107f,-0.707107f,0.000000f,-1.000000f,0.000000f,0.000000f, 00098 -1.000000f,0.000000f,0.000000f,-0.707107f,-0.707107f,0.000000f, 00099 -1.000000f,0.000000f,0.000000f,-0.707107f,0.707107f,0.000000f, 00100 -0.707107f,0.707107f,0.000000f,-1.000000f,0.000000f,0.000000f, 00101 -0.707107f,0.707107f,0.000000f,0.000000f,1.000000f,0.000000f, 00102 0.000000f,1.000000f,0.000000f,-0.707107f,0.707107f,0.000000f, 00103 0.707107f,0.707107f,0.000000f,1.000000f,0.000000f,0.000000f, 00104 1.000000f,0.000000f,0.000000f,0.707107f,0.707107f,0.000000f, 00105 1.000000f,0.000000f,0.000000f,0.707107f,-0.707107f,0.000000f, 00106 0.707107f,-0.707107f,0.000000f,1.000000f,0.000000f,0.000000f, 00107 0.707107f,-0.707107f,0.000000f,0.000000f,-1.000000f,0.000000f, 00108 0.000000f,-1.000000f,0.000000f,0.707107f,-0.707107f,0.000000f, 00109 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00110 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00111 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00112 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00113 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00114 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00115 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00116 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00117 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00118 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00119 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00120 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00121 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00122 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00123 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00124 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f 00125 }; 00126 00127 void GraphicsHelper::initializeArrow() 00128 { 00129 if (!GLEW_ARB_vertex_buffer_object) 00130 { 00131 arrow_initialized = true; 00132 return; 00133 } 00134 00135 glGenBuffersARB(1, &arrow_triangle_vertices_vbo); 00136 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_triangle_vertices_vbo); 00137 glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_arrow_triangle_vertices*3*sizeof(GLfloat), arrow_triangle_vertices, GL_STATIC_DRAW_ARB); 00138 00139 glGenBuffersARB(1, &arrow_triangle_normals_vbo); 00140 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_triangle_normals_vbo); 00141 glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_arrow_triangle_vertices*3*sizeof(GLfloat), arrow_triangle_normals, GL_STATIC_DRAW_ARB); 00142 00143 glGenBuffersARB(1, &arrow_quad_vertices_vbo); 00144 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_quad_vertices_vbo); 00145 glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_arrow_quad_vertices*3*sizeof(GLfloat), arrow_quad_vertices, GL_STATIC_DRAW_ARB); 00146 00147 glGenBuffersARB(1, &arrow_quad_normals_vbo); 00148 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_quad_normals_vbo); 00149 glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_arrow_quad_vertices*3*sizeof(GLfloat), arrow_quad_normals, GL_STATIC_DRAW_ARB); 00150 00151 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 00152 arrow_initialized = true; 00153 }; 00154 00155 const GLbyte GraphicsHelper::sphere_face_indicies[180][6] = { 00156 // object 00157 {9,10,8 ,0,1,2 }, {8,11,7 ,2,3,4 }, {8,10,11 ,2,1,3 }, {7,12,6 ,4,5,6 }, 00158 {7,11,12 ,4,3,5 }, {6,13,5 ,6,7,8 }, {6,12,13 ,6,5,7 }, {5,14,4 ,8,9,10 }, 00159 {5,13,14 ,8,7,9 }, {4,15,3 ,10,11,12 }, {4,14,15 ,10,9,11 }, 00160 {3,16,2 ,12,13,14 }, {3,15,16 ,12,11,13 }, {2,17,1 ,14,15,16 }, 00161 {2,16,17 ,14,13,15 }, {18,1,17 ,17,16,15 }, {18,0,1 ,17,18,16 }, 00162 {0,18,37 ,18,17,19 }, {18,19,37 ,17,20,19 }, {17,19,18 ,15,20,17 }, 00163 {17,20,19 ,15,21,20 }, {16,20,17 ,13,21,15 }, {16,21,20 ,13,22,21 }, 00164 {15,21,16 ,11,22,13 }, {15,22,21 ,11,23,22 }, {14,22,15 ,24,23,11 }, 00165 {14,23,22 ,24,25,23 }, {13,23,14 ,7,25,24 }, {13,24,23 ,7,26,25 }, 00166 {12,24,13 ,5,26,7 }, {12,25,24 ,5,27,26 }, {11,25,12 ,3,27,5 }, 00167 {11,26,25 ,3,28,27 }, {10,26,11 ,1,28,3 }, {10,27,26 ,1,29,28 }, 00168 {9,27,10 ,0,29,1 }, {9,28,27 ,0,30,29 }, {27,29,26 ,29,31,28 }, 00169 {27,28,29 ,29,30,31 }, {26,30,25 ,28,32,27 }, {26,29,30 ,28,31,32 }, 00170 {25,31,24 ,27,33,26 }, {25,30,31 ,27,32,33 }, {24,32,23 ,26,34,35 }, 00171 {24,31,32 ,26,33,34 }, {23,33,22 ,35,36,23 }, {23,32,33 ,35,34,36 }, 00172 {22,34,21 ,23,37,22 }, {22,33,34 ,23,36,37 }, {21,35,20 ,22,38,21 }, 00173 {21,34,35 ,22,37,38 }, {20,36,19 ,21,39,20 }, {20,35,36 ,21,38,39 }, 00174 {19,36,37 ,20,39,19 }, {36,38,37 ,39,40,19 }, {35,38,36 ,38,40,39 }, 00175 {35,39,38 ,38,41,40 }, {34,39,35 ,37,41,38 }, {34,40,39 ,37,42,41 }, 00176 {33,40,34 ,36,42,37 }, {33,41,40 ,36,43,42 }, {32,41,33 ,44,43,36 }, 00177 {32,42,41 ,44,45,43 }, {31,42,32 ,33,45,44 }, {31,43,42 ,33,46,45 }, 00178 {30,43,31 ,32,46,33 }, {30,44,43 ,32,47,46 }, {29,44,30 ,31,47,32 }, 00179 {29,45,44 ,31,48,47 }, {28,45,29 ,30,48,31 }, {28,46,45 ,30,49,48 }, 00180 {9,46,28 ,0,49,30 }, {9,47,46 ,0,50,49 }, {46,48,45 ,49,51,48 }, 00181 {46,47,48 ,49,50,51 }, {45,49,44 ,48,52,47 }, {45,48,49 ,48,51,52 }, 00182 {44,50,43 ,47,53,46 }, {44,49,50 ,47,52,53 }, {43,51,42 ,46,54,55 }, 00183 {43,50,51 ,46,53,54 }, {42,52,41 ,55,56,43 }, {42,51,52 ,55,54,56 }, 00184 {41,53,40 ,43,57,42 }, {41,52,53 ,43,56,57 }, {40,54,39 ,42,58,41 }, 00185 {40,53,54 ,42,57,58 }, {39,55,38 ,41,59,40 }, {39,54,55 ,41,58,59 }, 00186 {38,55,37 ,40,59,19 }, {55,56,37 ,59,60,19 }, {54,56,55 ,58,60,59 }, 00187 {54,57,56 ,58,61,60 }, {53,57,54 ,57,61,58 }, {53,58,57 ,57,62,61 }, 00188 {52,58,53 ,56,62,57 }, {52,59,58 ,56,63,62 }, {51,59,52 ,64,63,56 }, 00189 {51,60,59 ,64,65,63 }, {50,60,51 ,53,65,64 }, {50,61,60 ,53,66,65 }, 00190 {49,61,50 ,52,66,53 }, {49,62,61 ,52,67,66 }, {48,62,49 ,51,67,52 }, 00191 {48,63,62 ,51,68,67 }, {47,63,48 ,50,68,51 }, {47,64,63 ,50,69,68 }, 00192 {9,64,47 ,0,69,50 }, {9,65,64 ,0,70,69 }, {64,66,63 ,69,71,68 }, 00193 {64,65,66 ,69,70,71 }, {63,67,62 ,68,72,67 }, {63,66,67 ,68,71,72 }, 00194 {62,68,61 ,67,73,66 }, {62,67,68 ,67,72,73 }, {61,69,60 ,66,74,75 }, 00195 {61,68,69 ,66,73,74 }, {60,70,59 ,75,76,63 }, {60,69,70 ,75,74,76 }, 00196 {59,71,58 ,63,77,62 }, {59,70,71 ,63,76,77 }, {58,72,57 ,62,78,61 }, 00197 {58,71,72 ,62,77,78 }, {57,73,56 ,61,79,60 }, {57,72,73 ,61,78,79 }, 00198 {56,73,37 ,60,79,19 }, {73,74,37 ,79,80,19 }, {72,74,73 ,78,80,79 }, 00199 {72,75,74 ,78,81,80 }, {71,75,72 ,77,81,78 }, {71,76,75 ,77,82,81 }, 00200 {70,76,71 ,76,82,77 }, {70,77,76 ,76,83,82 }, {69,77,70 ,84,83,76 }, 00201 {69,78,77 ,84,85,83 }, {68,78,69 ,73,85,84 }, {68,79,78 ,73,86,85 }, 00202 {67,79,68 ,72,86,73 }, {67,80,79 ,72,87,86 }, {66,80,67 ,71,87,72 }, 00203 {66,81,80 ,71,88,87 }, {65,81,66 ,70,88,71 }, {65,82,81 ,70,89,88 }, 00204 {9,82,65 ,0,89,70 }, {9,83,82 ,0,90,89 }, {82,84,81 ,89,91,88 }, 00205 {82,83,84 ,89,90,91 }, {81,85,80 ,88,92,87 }, {81,84,85 ,88,91,92 }, 00206 {80,86,79 ,87,93,86 }, {80,85,86 ,87,92,93 }, {79,87,78 ,86,94,95 }, 00207 {79,86,87 ,86,93,94 }, {78,88,77 ,95,96,83 }, {78,87,88 ,95,94,96 }, 00208 {77,89,76 ,83,97,82 }, {77,88,89 ,83,96,97 }, {76,90,75 ,82,98,81 }, 00209 {76,89,90 ,82,97,98 }, {75,91,74 ,81,99,80 }, {75,90,91 ,81,98,99 }, 00210 {74,91,37 ,80,99,19 }, {91,0,37 ,99,18,19 }, {0,90,1 ,18,98,16 }, 00211 {0,91,90 ,18,99,98 }, {89,1,90 ,97,16,98 }, {89,2,1 ,97,14,16 }, 00212 {88,2,89 ,96,14,97 }, {88,3,2 ,96,12,14 }, {87,3,88 ,100,12,96 }, 00213 {87,4,3 ,100,101,12 }, {86,4,87 ,93,101,100 }, {86,5,4 ,93,8,101 }, 00214 {85,5,86 ,92,8,93 }, {85,6,5 ,92,6,8 }, {84,6,85 ,91,6,92 }, 00215 {84,7,6 ,91,4,6 }, {83,7,84 ,90,4,91 }, {83,8,7 ,90,2,4 }, {9,8,83 ,0,2,90 } 00216 }; 00217 const GLfloat GraphicsHelper::sphere_vertices [92][3] = { 00218 {0.00618002f,0.0190211f,7.25448e-008f},{0.0117558f,0.01618f,7.25448e-008f},{0.01618f,0.0117558f,7.25448e-008f}, 00219 {0.0190211f,0.00618f,7.25448e-008f},{0.02f,0.0f,7.25448e-008f},{0.0190211f,-0.00618f,7.25448e-008f}, 00220 {0.01618f,-0.0117558f,7.25448e-008f},{0.0117558f,-0.01618f,7.25448e-008f},{0.00618002f,-0.0190211f,7.25448e-008f}, 00221 {0.0f,-0.02f,7.25448e-008f},{0.00500002f,-0.0190211f,-0.00363254f},{0.00951054f,-0.01618f,-0.00690942f}, 00222 {0.0130905f,-0.0117558f,-0.00951044f},{0.0153884f,-0.00618f,-0.0111801f},{0.01618f,0.0f,-0.0117557f}, 00223 {0.0153884f,0.00618f,-0.0111801f},{0.0130905f,0.0117558f,-0.00951044f},{0.00951054f,0.01618f,-0.00690942f}, 00224 {0.00500002f,0.0190211f,-0.00363254f},{0.00190947f,0.0190211f,-0.00587782f},{0.00363264f,0.01618f,-0.0111801f}, 00225 {0.00500002f,0.0117558f,-0.0153884f},{0.0058779f,0.00618f,-0.0180905f},{0.00618002f,0.0f,-0.0190211f}, 00226 {0.0058779f,-0.00618f,-0.0180905f},{0.00500002f,-0.0117558f,-0.0153884f},{0.00363264f,-0.01618f,-0.0111801f}, 00227 {0.00190947f,-0.0190211f,-0.00587782f},{-0.00190947f,-0.0190211f,-0.00587782f},{-0.00363264f,-0.01618f,-0.0111801f}, 00228 {-0.005f,-0.0117558f,-0.0153884f},{-0.00587788f,-0.00618f,-0.0180905f},{-0.00618f,0.0f,-0.0190211f}, 00229 {-0.00587788f,0.00618f,-0.0180905f},{-0.005f,0.0117558f,-0.0153884f},{-0.00363264f,0.01618f,-0.0111801f}, 00230 {-0.00190947f,0.0190211f,-0.00587782f},{0.0f,0.02f,7.25448e-008f},{-0.005f,0.0190211f,-0.00363254f}, 00231 {-0.00951052f,0.01618f,-0.00690942f},{-0.0130905f,0.0117558f,-0.00951044f},{-0.0153884f,0.00618f,-0.0111801f}, 00232 {-0.01618f,0.0f,-0.0117557f},{-0.0153884f,-0.00618f,-0.0111801f},{-0.0130905f,-0.0117558f,-0.00951044f}, 00233 {-0.00951052f,-0.01618f,-0.00690942f},{-0.005f,-0.0190211f,-0.00363254f},{-0.00618f,-0.0190211f,7.25448e-008f}, 00234 {-0.0117558f,-0.01618f,7.25448e-008f},{-0.01618f,-0.0117558f,7.25448e-008f},{-0.0190211f,-0.00618f,7.25448e-008f}, 00235 {-0.02f,0.0f,7.25448e-008f},{-0.0190211f,0.00618f,7.25448e-008f},{-0.01618f,0.0117558f,7.25448e-008f}, 00236 {-0.0117558f,0.01618f,7.25448e-008f},{-0.00618f,0.0190211f,7.25448e-008f},{-0.005f,0.0190211f,0.0036327f}, 00237 {-0.00951052f,0.01618f,0.00690944f},{-0.0130905f,0.0117558f,0.00951058f},{-0.0153884f,0.00618f,0.0111801f}, 00238 {-0.01618f,0.0f,0.0117558f},{-0.0153884f,-0.00618f,0.0111801f},{-0.0130905f,-0.0117558f,0.00951058f}, 00239 {-0.00951052f,-0.01618f,0.00690944f},{-0.005f,-0.0190211f,0.0036327f},{-0.00190947f,-0.0190211f,0.00587796f}, 00240 {-0.00363264f,-0.01618f,0.0111801f},{-0.005f,-0.0117558f,0.0153885f},{-0.00587788f,-0.00618f,0.0180905f}, 00241 {-0.00618f,0.0f,0.0190211f},{-0.00587788f,0.00618f,0.0180905f},{-0.005f,0.0117558f,0.0153885f}, 00242 {-0.00363264f,0.01618f,0.0111801f},{-0.00190947f,0.0190211f,0.00587796f},{0.00190947f,0.0190211f,0.00587796f}, 00243 {0.00363264f,0.01618f,0.0111801f},{0.00500002f,0.0117558f,0.0153885f},{0.0058779f,0.00618f,0.0180905f}, 00244 {0.00618002f,0.0f,0.0190211f},{0.0058779f,-0.00618f,0.0180905f},{0.00500002f,-0.0117558f,0.0153885f}, 00245 {0.00363264f,-0.01618f,0.0111801f},{0.00190947f,-0.0190211f,0.00587796f},{0.00500002f,-0.0190211f,0.0036327f}, 00246 {0.00951054f,-0.01618f,0.00690944f},{0.0130905f,-0.0117558f,0.00951058f},{0.0153884f,-0.00618f,0.0111801f}, 00247 {0.01618f,0.0f,0.0117558f},{0.0153884f,0.00618f,0.0111801f},{0.0130905f,0.0117558f,0.00951058f}, 00248 {0.00951054f,0.01618f,0.00690944f},{0.00500002f,0.0190211f,0.0036327f} 00249 }; 00250 const GLfloat GraphicsHelper::sphere_normals [102][3] = { 00251 {-7.70428e-008f,-1.0f,1.13298e-009f},{0.256119f,-0.940613f,-0.222823f},{0.338169f,-0.940616f,-0.0297359f}, 00252 {0.466817f,-0.809656f,-0.355724f},{0.586766f,-0.809646f,-0.0133919f},{0.648383f,-0.5887f,-0.482734f}, 00253 {0.808305f,-0.588688f,-0.00944755f},{0.766413f,-0.309632f,-0.562796f},{0.950834f,-0.309663f,-0.00486008f}, 00254 {0.949855f,-0.0501532f,-0.308643f},{0.949855f,0.0501398f,-0.308644f},{0.7721f,0.309648f,-0.554959f}, 00255 {0.950833f,0.309665f,0.00486227f},{0.659483f,0.588708f,-0.467446f},{0.808306f,0.588686f,0.00944868f}, 00256 {0.482581f,0.809645f,-0.334053f},{0.586765f,0.809646f,0.0133939f},{0.291059f,0.940616f,-0.174716f}, 00257 {0.33817f,0.940615f,0.0297366f},{-7.70428e-008f,1.0f,1.13298e-009f},{0.132778f,0.940611f,-0.312444f}, 00258 {0.194056f,0.809649f,-0.553905f},{0.258765f,0.588716f,-0.765803f},{0.29845f,0.30967f,-0.902791f}, 00259 {0.587057f,0.0501236f,-0.807992f},{0.587056f,-0.0501536f,-0.807991f},{0.289228f,-0.309641f,-0.905798f}, 00260 {0.240779f,-0.588735f,-0.771633f},{0.168578f,-0.809647f,-0.562186f},{0.0762226f,-0.940611f,-0.33082f}, 00261 {-0.132778f,-0.940611f,-0.312444f},{-0.194056f,-0.809649f,-0.553905f},{-0.258765f,-0.588716f,-0.765803f}, 00262 {-0.29845f,-0.30967f,-0.902791f},{0.0f,-0.0501303f,-0.998743f},{0.0f,0.0501303f,-0.998743f}, 00263 {-0.289228f,0.309641f,-0.905798f},{-0.240779f,0.588735f,-0.771633f},{-0.168579f,0.809647f,-0.562186f}, 00264 {-0.0762228f,0.940611f,-0.33082f},{-0.256119f,0.940613f,-0.222823f},{-0.466817f,0.809656f,-0.355724f}, 00265 {-0.648383f,0.5887f,-0.482734f},{-0.766413f,0.309632f,-0.562796f},{-0.587056f,0.0501536f,-0.807991f}, 00266 {-0.587057f,-0.0501236f,-0.807992f},{-0.7721f,-0.309649f,-0.554958f},{-0.659483f,-0.588708f,-0.467446f}, 00267 {-0.48258f,-0.809645f,-0.334053f},{-0.291059f,-0.940616f,-0.174716f},{-0.33817f,-0.940615f,0.0297366f}, 00268 {-0.586765f,-0.809647f,0.013394f},{-0.808306f,-0.588686f,0.00944848f},{-0.950833f,-0.309665f,0.00486216f}, 00269 {-0.949856f,-0.0501399f,-0.308643f},{-0.949855f,0.050154f,-0.308643f},{-0.950834f,0.309663f,-0.00485999f}, 00270 {-0.808305f,0.588688f,-0.00944734f},{-0.586766f,0.809646f,-0.013392f},{-0.338169f,0.940616f,-0.0297359f}, 00271 {-0.29106f,0.940616f,0.174718f},{-0.48258f,0.809644f,0.334055f},{-0.659482f,0.588709f,0.467445f}, 00272 {-0.7721f,0.309647f,0.55496f},{-0.949855f,0.0501419f,0.308644f},{-0.949854f,-0.0501541f,0.308644f}, 00273 {-0.766412f,-0.309632f,0.562798f},{-0.648384f,-0.588697f,0.482736f},{-0.466815f,-0.809657f,0.355723f}, 00274 {-0.256122f,-0.940612f,0.222826f},{-0.0762237f,-0.940609f,0.330825f},{-0.168579f,-0.809649f,0.562183f}, 00275 {-0.240778f,-0.588733f,0.771634f},{-0.289229f,-0.309633f,0.9058f},{-0.587052f,-0.0501587f,0.807994f}, 00276 {-0.587053f,0.0501239f,0.807995f},{-0.298448f,0.309665f,0.902794f},{-0.258766f,0.588715f,0.765803f}, 00277 {-0.194054f,0.80965f,0.553904f},{-0.13278f,0.940609f,0.312448f},{0.0762235f,0.940609f,0.330825f}, 00278 {0.168579f,0.809649f,0.562183f},{0.240778f,0.588733f,0.771634f},{0.289229f,0.309633f,0.9058f}, 00279 {0.0f,0.0501303f,0.998743f},{0.0f,-0.0501303f,0.998743f},{0.298449f,-0.309665f,0.902793f}, 00280 {0.258766f,-0.588715f,0.765803f},{0.194054f,-0.80965f,0.553904f},{0.13278f,-0.940609f,0.312448f}, 00281 {0.29106f,-0.940616f,0.174718f},{0.48258f,-0.809644f,0.334055f},{0.659482f,-0.588709f,0.467445f}, 00282 {0.7721f,-0.309646f,0.55496f},{0.587053f,-0.0501239f,0.807995f},{0.587052f,0.0501587f,0.807994f}, 00283 {0.766412f,0.309632f,0.562798f},{0.648384f,0.588697f,0.482736f},{0.466815f,0.809657f,0.355723f}, 00284 {0.256121f,0.940612f,0.222826f},{0.949854f,0.0501533f,0.308645f},{0.949855f,-0.0501418f,0.308645f} 00285 }; 00286 GLint GraphicsHelper::initializeSphere() 00287 { 00288 //num_sphere_vertices=sizeof(sphere_face_indicies)/sizeof(sphere_face_indicies[0])*3; 00289 //float *vertexdata=new float[num_sphere_vertices*3]; 00290 //float *normaldata=new float[num_sphere_vertices*3]; 00291 //float *curvertex=vertexdata,*curnormal=normaldata; 00292 00293 unsigned int i, j; 00294 GLint lid=glGenLists(1); 00295 glNewList(lid, GL_COMPILE); 00296 glBegin (GL_TRIANGLES); 00297 for(i=0;i<sizeof(sphere_face_indicies)/sizeof(sphere_face_indicies[0]);i++) 00298 { 00299 for(j=0;j<3;j++) 00300 { 00301 int vi=sphere_face_indicies[i][j]; 00302 int ni=sphere_face_indicies[i][j+3];//Normal index 00303 glNormal3f (sphere_normals[ni][0],sphere_normals[ni][1],sphere_normals[ni][2]); 00304 glVertex3f (sphere_vertices[vi][0],sphere_vertices[vi][1],sphere_vertices[vi][2]); 00305 00306 //memcpy(curvertex,sphere_vertices[vi],sizeof(float)*3); 00307 //memcpy(curnormal,sphere_normals[ni],sizeof(float)*3); 00308 //curvertex+=3; 00309 //curnormal+=3; 00310 } 00311 } 00312 glEnd (); 00313 glEndList(); 00314 00315 //glGenBuffersARB(1, &sphere_vertices_vbo); 00316 //glBindBufferARB(GL_ARRAY_BUFFER_ARB, sphere_vertices_vbo); 00317 //glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_sphere_vertices*3*sizeof(GLfloat), vertexdata, GL_STATIC_DRAW_ARB); 00318 00319 //glGenBuffersARB(1, &sphere_normals_vbo); 00320 //glBindBufferARB(GL_ARRAY_BUFFER_ARB, sphere_normals_vbo); 00321 //glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_sphere_vertices*3*sizeof(GLfloat), normaldata, GL_STATIC_DRAW_ARB); 00322 00323 //delete[] vertexdata; 00324 //delete[] normaldata; 00325 00326 return lid; 00327 }; 00328 00329 void GraphicsHelper::drawSphere(double x, double y, double z, double scale) 00330 { 00331 if (!sphere_display_initialized) 00332 { 00333 sphere_display_list=initializeSphere(); 00334 sphere_display_initialized=true; 00335 } 00336 glPushMatrix(); 00337 glTranslatef(x, y, z); 00338 glScalef(scale,scale,scale); 00339 glCallList(sphere_display_list); 00340 glPopMatrix(); 00341 } 00342 00343 // Draw an X-Y-Z Frame. The red arrow corresponds to the X-Axis, 00344 // green to the Y-Axis, and blue to the Z-Axis. 00345 void GraphicsHelper::drawCoordinateFrame(double scale) 00346 { 00347 double a_axisThicknessScale = 3*scale; 00348 00349 // initialize vertex buffer objects 00350 if(!arrow_initialized) 00351 initializeArrow(); 00352 00353 // Set up nice color-tracking 00354 glEnable(GL_COLOR_MATERIAL); 00355 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); 00356 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00357 00358 int k; 00359 for(k=0; k<3; k++) { 00360 00361 glPushMatrix(); 00362 00363 // Rotate to the appropriate axis 00364 if (k==0) { 00365 glRotatef(-90.0,0,1,0); 00366 glColor3f(1.0f,0.0f,0.0f); 00367 } 00368 else if (k==1) { 00369 glRotatef(90.0,1,0,0); 00370 glColor3f(0.0f,1.0f,0.0f); 00371 } 00372 else { 00373 glRotatef(180.0,1,0,0); 00374 glColor3f(0.0f,0.0f,1.0f); 00375 } 00376 00377 glScaled(a_axisThicknessScale,a_axisThicknessScale,scale); 00378 00379 if (!GLEW_ARB_vertex_buffer_object) 00380 { 00381 glBegin(GL_TRIANGLES); 00382 for (int i=0;i<num_arrow_triangle_vertices;i++) 00383 { 00384 glVertex3d(arrow_triangle_vertices[i*3],arrow_triangle_vertices[i*3+1],arrow_triangle_vertices[i*3+2]); 00385 glNormal3d(arrow_triangle_normals[i*3],arrow_triangle_normals[i*3+1],arrow_triangle_normals[i*3+2]); 00386 } 00387 glEnd(); 00388 00389 glBegin(GL_QUADS); 00390 for (int i=0;i<num_arrow_quad_vertices;i++) 00391 { 00392 glVertex3d(arrow_quad_vertices[i*3],arrow_quad_vertices[i*3+1],arrow_quad_vertices[i*3+2]); 00393 glNormal3d(arrow_quad_normals[i*3],arrow_quad_normals[i*3+1],arrow_quad_normals[i*3+2]); 00394 } 00395 glEnd(); 00396 } 00397 else 00398 { 00399 glEnableClientState(GL_NORMAL_ARRAY); 00400 glEnableClientState(GL_VERTEX_ARRAY); 00401 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_triangle_vertices_vbo); 00402 glVertexPointer(3, GL_FLOAT, 0, 0); 00403 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_triangle_normals_vbo); 00404 glNormalPointer(GL_FLOAT, 0, 0); 00405 glDrawArrays(GL_TRIANGLES, 0, num_arrow_triangle_vertices); 00406 00407 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_quad_vertices_vbo); 00408 glVertexPointer(3, GL_FLOAT, 0, 0); 00409 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_quad_normals_vbo); 00410 glNormalPointer(GL_FLOAT, 0, 0); 00411 glDrawArrays(GL_QUADS, 0, num_arrow_quad_vertices); 00412 00413 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 00414 00415 glDisableClientState(GL_NORMAL_ARRAY); 00416 glDisableClientState(GL_VERTEX_ARRAY); 00417 } 00418 00419 glPopMatrix(); 00420 } 00421 } 00422 00423 void GraphicsHelper::drawGrid(double center_x, double center_y, int size, double resolution) const 00424 { 00425 double grid_x, grid_y; 00426 double size_2=(double)size/2.0; 00427 00428 glLineWidth(0.5); 00429 glEnable(GL_BLEND); 00430 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00431 00432 glEnable(GL_LINE_SMOOTH); 00433 glBegin(GL_LINES); 00434 for(grid_x = -size_2; grid_x < size_2; grid_x+=resolution) { 00435 glVertex3f(grid_x - center_x, -size_2 - center_y, 0); 00436 glVertex3f(grid_x - center_x, size_2 - center_y, 0); 00437 } 00438 for(grid_y = -size_2; grid_y < size_2; grid_y+=resolution) { 00439 glVertex3f(-size_2 - center_x, grid_y - center_y, 0); 00440 glVertex3f( size_2 - center_x, grid_y - center_y, 0); 00441 } 00442 glEnd(); 00443 glDisable(GL_LINE_SMOOTH); 00444 glDisable(GL_BLEND); 00445 } 00446 00447 // color table 00448 const unsigned char GraphicsHelper::graphics_colorpalette[COLOR_PALETTE_SIZE][3] = { 00449 {128,51,128}, 00450 {51,128,128}, 00451 {255,51,51}, 00452 {51,255,51}, 00453 {51,51,255}, 00454 {51,179,204}, 00455 {128,255,51}, 00456 {255,128,51}, 00457 {51,128,255}, 00458 {239,230,0}, 00459 {230,0,230}, 00460 {0,230,230}, 00461 {230,0,0}, 00462 }; 00463 00464 Vec3uc GraphicsHelper::getColorFromPalette(int index) { 00465 return graphics_colorpalette[index%COLOR_PALETTE_SIZE]; 00466 } 00467 00468 //============================================================================== 00469 } // namespace rtc 00470 //============================================================================== 00471