00001 #ifndef OPENTISSUE_UTILITY_GL_GL_DRAW_OBB_H
00002 #define OPENTISSUE_UTILITY_GL_GL_DRAW_OBB_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_rotation.h>
00014 #include <OpenTissue/core/math/math_constants.h>
00015
00016 namespace OpenTissue
00017 {
00018
00019 namespace gl
00020 {
00021
00028 template<typename obb_type>
00029 inline void DrawOBB(obb_type const & obb, bool wireframe = false)
00030 {
00031 typedef typename obb_type::real_type real_type;
00032 typedef typename obb_type::vector3_type vector3_type;
00033 typedef typename obb_type::matrix3x3_type matrix3x3_type;
00034
00035 vector3_type T = obb.center();
00036 vector3_type const & ext = obb.ext();
00037 matrix3x3_type const & R = obb.orientation();
00038
00039 glPushMatrix();
00040 glTranslatef(
00041 (GLfloat)T[0],
00042 (GLfloat)T[1],
00043 (GLfloat)T[2]
00044 );
00045 math::Rotation<real_type> rot;
00046 rot = R;
00047 real_type degrees = math::to_degrees(rot.angle());
00048 glRotatef((GLfloat)degrees,(GLfloat)rot.axis()[0],(GLfloat)rot.axis()[1],(GLfloat)rot.axis()[2]);
00049 GLenum const mode = wireframe ? GL_LINE_LOOP : GL_POLYGON;
00050
00051 glBegin(mode);
00052 glNormal3f(0,0,1);
00053 glVertex3f((GLfloat)-ext[0],(GLfloat)-ext[1],(GLfloat)ext[2]);
00054 glNormal3f(0,0,1);
00055 glVertex3f((GLfloat)ext[0],(GLfloat)-ext[1],(GLfloat)ext[2]);
00056 glNormal3f(0,0,1);
00057 glVertex3f((GLfloat)ext[0],(GLfloat)ext[1],(GLfloat)ext[2]);
00058 glNormal3f(0,0,1);
00059 glVertex3f((GLfloat)-ext[0],(GLfloat)ext[1],(GLfloat)ext[2]);
00060 glEnd();
00061
00062 glBegin(mode);
00063 glNormal3f(1,0,0);
00064 glVertex3f((GLfloat)ext[0],(GLfloat)-ext[1],(GLfloat)ext[2]);
00065 glNormal3f(1,0,0);
00066 glVertex3f((GLfloat)ext[0],(GLfloat)-ext[1],(GLfloat)-ext[2]);
00067 glNormal3f(1,0,0);
00068 glVertex3f((GLfloat)ext[0],(GLfloat)ext[1],(GLfloat)-ext[2]);
00069 glNormal3f(1,0,0);
00070 glVertex3f((GLfloat)ext[0],(GLfloat)ext[1],(GLfloat)ext[2]);
00071 glEnd();
00072
00073 glBegin(mode);
00074 glNormal3f(0,1,0);
00075 glVertex3f((GLfloat)-ext[0],(GLfloat)ext[1],(GLfloat)ext[2]);
00076 glNormal3f(0,1,0);
00077 glVertex3f((GLfloat)ext[0],(GLfloat)ext[1],(GLfloat)ext[2]);
00078 glNormal3f(0,1,0);
00079 glVertex3f((GLfloat)ext[0],(GLfloat)ext[1],(GLfloat)-ext[2]);
00080 glNormal3f(0,1,0);
00081 glVertex3f((GLfloat)-ext[0],(GLfloat)ext[1],(GLfloat)-ext[2]);
00082 glEnd();
00083
00084 glBegin(mode);
00085 glNormal3f(0,0,-1);
00086 glVertex3f((GLfloat)-ext[0],(GLfloat)-ext[1],(GLfloat)-ext[2]);
00087 glNormal3f(0,0,-1);
00088 glVertex3f((GLfloat)-ext[0],(GLfloat)ext[1],(GLfloat)-ext[2]);
00089 glNormal3f(0,0,-1);
00090 glVertex3f((GLfloat)ext[0],(GLfloat)ext[1],(GLfloat)-ext[2]);
00091 glNormal3f(0,0,-1);
00092 glVertex3f((GLfloat)ext[0],(GLfloat)-ext[1],(GLfloat)-ext[2]);
00093 glEnd();
00094
00095 glBegin(mode);
00096 glNormal3f(0,-1,0);
00097 glVertex3f((GLfloat)-ext[0],(GLfloat)-ext[1],(GLfloat)-ext[2]);
00098 glNormal3f(0,-1,0);
00099 glVertex3f((GLfloat)ext[0],(GLfloat)-ext[1],(GLfloat)-ext[2]);
00100 glNormal3f(0,-1,0);
00101 glVertex3f((GLfloat)ext[0],(GLfloat)-ext[1],(GLfloat)ext[2]);
00102 glNormal3f(0,-1,0);
00103 glVertex3f((GLfloat)-ext[0],(GLfloat)-ext[1],(GLfloat)ext[2]);
00104 glEnd();
00105
00106 glBegin(mode);
00107 glNormal3f(-1,0,0);
00108 glVertex3f((GLfloat)-ext[0],(GLfloat)-ext[1],(GLfloat)-ext[2]);
00109 glNormal3f(-1,0,0);
00110 glVertex3f((GLfloat)-ext[0],(GLfloat)-ext[1],(GLfloat)ext[2]);
00111 glNormal3f(-1,0,0);
00112 glVertex3f((GLfloat)-ext[0],(GLfloat)ext[1],(GLfloat)ext[2]);
00113 glNormal3f(-1,0,0);
00114 glVertex3f((GLfloat)-ext[0],(GLfloat)ext[1],(GLfloat)-ext[2]);
00115 glEnd();
00116 glPopMatrix();
00117 }
00118
00119 }
00120
00121 }
00122
00123
00124 #endif