Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_GL_GL_DRAW_CYLINDER_H
00002 #define OPENTISSUE_UTILITY_GL_GL_DRAW_CYLINDER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/gl/gl.h>
00013 #include <cmath>
00014
00015 namespace OpenTissue
00016 {
00017
00018 namespace gl
00019 {
00020
00027 template<typename cylinder_type>
00028 inline void DrawCylinder(cylinder_type const & cylinder, bool wireframe = false)
00029 {
00030 using std::acos;
00031
00032 typedef typename cylinder_type::real_type real_type;
00033 typedef typename cylinder_type::vector3_type vector3_type;
00034
00035 vector3_type center = cylinder.center();
00036 vector3_type const & axis = cylinder.axis();
00037 real_type const & radius = cylinder.radius();
00038 real_type const & height = cylinder.height();
00039
00040 glPolygonMode(GL_FRONT_AND_BACK,(wireframe?GL_LINE:GL_FILL));
00041 GLUquadricObj* qobj = gluNewQuadric();
00042 glPushMatrix();
00043
00044 glTranslatef(
00045 (GLfloat)center[0],
00046 (GLfloat)center[1],
00047 (GLfloat)center[2]
00048 );
00049
00050 GLfloat angle = 0;
00051 GLfloat x = 1;
00052 GLfloat y = 0;
00053 GLfloat z = 0;
00054
00055
00056
00057 if((axis[0]==0) && (axis[1]==0))
00058 {
00059 if(axis[2]>0)
00060 {
00061 angle = 0;
00062 }
00063 else
00064 {
00065 angle = 180;
00066 }
00067 }
00068 else
00069 {
00070 vector3_type k(0,0,1);
00071
00072 vector3_type tmp;
00073 tmp = axis % k;
00074 angle = acos(axis * k);
00075 angle = -180.0*angle/3.1415;
00076 x = tmp[0];
00077 y = tmp[1];
00078 z = tmp[2];
00079 }
00080
00081 glRotatef(angle,x,y,z);
00082 glTranslatef((GLfloat)0,(GLfloat)0,(GLfloat)-height/2.);
00083 gluCylinder(qobj,radius,radius,height,32,1);
00084 glPopMatrix();
00085 gluDeleteQuadric(qobj);
00086 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
00087
00088 }
00089
00090 }
00091
00092 }
00093
00094
00095 #endif