Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_GL_GL_DRAW_ARC_H
00002 #define OPENTISSUE_UTILITY_GL_GL_DRAW_ARC_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_functions.h>
00014
00015
00016 namespace OpenTissue
00017 {
00018
00019 namespace gl
00020 {
00021
00028 template<typename vector3_type>
00029 inline void DrawArc(vector3_type const & x0, vector3_type const & x1, typename vector3_type::value_type const & theta)
00030 {
00031 typedef typename vector3_type::value_traits value_traits;
00032 typedef typename vector3_type::value_type real_type;
00033 using std::fabs;
00034
00035 if(fabs(theta) < value_traits::one()/4096)
00036 {
00037 glBegin(GL_LINES);
00038 glVertex3f(x0(0), x0(1), 0.f);
00039 glVertex3f(x1(0), x1(1), 0.f);
00040 glEnd();
00041 return;
00042 }
00043
00044 size_t const segments = 16;
00045
00046
00047 using std::sin;
00048 using std::sqrt;
00049 using std::fabs;
00050
00051 real_type const l = math::length(x1-x0);
00052 real_type const r = l/(value_traits::two()*sin(fabs(theta)));
00053
00054 real_type const h = sqrt(r*r-l*l/value_traits::four());
00055
00056 vector3_type const u = math::unit(x1-x0);
00057
00058 vector3_type const u_hat = vector3_type(u(1), -u(0), value_traits::zero());
00059
00060
00061 vector3_type const midpoint = value_traits::half()*(x1+x0);
00062 vector3_type const c = midpoint + math::sgn(theta)*h*u_hat;
00063
00064 vector3_type p0 = x0;
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 glBegin(GL_LINES);
00078 for(size_t n = 1; n < segments; ++n)
00079 {
00080
00081 real_type const a = n*value_traits::two()*theta/(segments-1);
00082 vector3_type const p = math::Rz(-a)*(x0-c)+c;
00083 glVertex3f(p0(0), p0(1), 0.f);
00084 glVertex3f(p(0), p(1), 0.f);
00085 p0 = p;
00086 }
00087 glEnd();
00088 }
00089
00090 }
00091
00092 }
00093
00094
00095 #endif