Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_GL_GL_DRAW_CAPSULE_H
00002 #define OPENTISSUE_UTILITY_GL_GL_DRAW_CAPSULE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/gl/gl.h>
00013 #include <OpenTissue/core/math/math_constants.h>
00014 #include <cmath>
00015
00016 namespace OpenTissue
00017 {
00018
00019 namespace gl
00020 {
00021
00028 template<typename capsule_type>
00029 inline void DrawCapsule(capsule_type const & capsule, bool wireframe = false)
00030 {
00031 using std::acos;
00032 typedef typename capsule_type::real_type real_type;
00033 typedef typename capsule_type::vector3_type vector3_type;
00034 typedef typename capsule_type::value_traits value_traits;
00035
00036 glPolygonMode(GL_FRONT_AND_BACK,(wireframe?GL_LINE:GL_FILL));
00037
00038 vector3_type const & p0 = capsule.point0();
00039 vector3_type const & p1 = capsule.point1();
00040 real_type const & radius = capsule.radius();
00041
00042 vector3_type ls(p1 - p0);
00043 vector3_type const za(math::detail::axis_z<real_type>());
00044 real_type const ln = length(ls);
00045 if (ln > value_traits::zero())
00046 {
00047 ls /= ln;
00048 }
00049 else
00050 {
00051 ls = za;
00052 }
00053 vector3_type const rt(cross(za, ls));
00054 real_type const an = math::to_degrees<real_type>(acos(za*ls));
00055
00056 GLdouble plane[4];
00057 plane[0] = 0.;
00058 plane[1] = 0.;
00059 plane[2] = -1.;
00060 plane[3] = 0.;
00061 GLUquadricObj* qobj = gluNewQuadric();
00062
00063 glPushMatrix();
00064 glTranslated(p0[0], p0[1], p0[2]);
00065 glRotated(an, rt[0], rt[1], rt[2]);
00066 glClipPlane(GL_CLIP_PLANE0,plane);
00067 glEnable(GL_CLIP_PLANE0);
00068 gluSphere(qobj, radius, 16, 16);
00069 glDisable(GL_CLIP_PLANE0);
00070 glPopMatrix();
00071
00072 glPushMatrix();
00073 glTranslated(p1[0], p1[1], p1[2]);
00074 glRotated(an, rt[0], rt[1], rt[2]);
00075 plane[2] *= -1;
00076 glClipPlane(GL_CLIP_PLANE0,plane);
00077 glEnable(GL_CLIP_PLANE0);
00078 gluSphere(qobj, radius, 16, 16);
00079 glDisable(GL_CLIP_PLANE0);
00080 glPopMatrix();
00081
00082 if (ln > 0.)
00083 {
00084 glPushMatrix();
00085 glTranslated(p0[0], p0[1], p0[2]);
00086 glRotated(an, rt[0], rt[1], rt[2]);
00087 gluCylinder(qobj, radius, radius, ln, 16, 1);
00088 glPopMatrix();
00089 }
00090
00091 gluDeleteQuadric(qobj);
00092
00093 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
00094 }
00095
00096 }
00097
00098 }
00099
00100
00101 #endif