Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_GL_GL_DRAW_ELLIPSOID_H
00002 #define OPENTISSUE_UTILITY_GL_GL_DRAW_ELLIPSOID_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/gl/gl.h>
00013
00014 namespace OpenTissue
00015 {
00016
00017 namespace gl
00018 {
00019
00026 template<typename ellipsoid_type>
00027 inline void DrawEllipsoid(ellipsoid_type const & ellipsoid, bool wireframe = false)
00028 {
00029 typedef typename ellipsoid_type::real_type real_type;
00030 typedef typename ellipsoid_type::vector3_type vector3_type;
00031
00032 vector3_type const & center = ellipsoid.center();
00033 vector3_type const & axis0 = ellipsoid.axis0();
00034 vector3_type const & axis1 = ellipsoid.axis1();
00035 vector3_type const & axis2 = ellipsoid.axis2();
00036 real_type const & radius0 = ellipsoid.radius0();
00037 real_type const & radius1 = ellipsoid.radius1();
00038 real_type const & radius2 = ellipsoid.radius2();
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 int glindex = 0;
00051 GLfloat glmatrix[16];
00052 for (unsigned int col = 0; col < 4; ++col)
00053 {
00054 for (unsigned int row = 0; row < 4; ++row)
00055 {
00056 if(row==col && row==3)
00057 glmatrix[glindex++] = 1;
00058 else if(row==3 || col==3)
00059 glmatrix[glindex++] = 0;
00060 else if (col==0)
00061 glmatrix[glindex++] = axis0(row);
00062 else if (col==1)
00063 glmatrix[glindex++] = axis1(row);
00064 else if (col==2)
00065 glmatrix[glindex++] = axis2(row);
00066 }
00067 }
00068 glMultMatrixf(glmatrix);
00069
00070 glScalef(
00071 (GLfloat)radius0,
00072 (GLfloat)radius1,
00073 (GLfloat)radius2
00074 );
00075
00076 gluSphere(qobj,1.0,32,32);
00077 glPopMatrix();
00078 gluDeleteQuadric(qobj);
00079 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
00080 }
00081
00082 }
00083
00084 }
00085
00086
00087 #endif