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


rtc
Author(s): Benjamin Pitzer
autogenerated on Mon Oct 6 2014 10:07:34