00001 #ifndef OPENTISSUE_UTILITY_GL_GL_DRAW_TETRAHEDRON_H
00002 #define OPENTISSUE_UTILITY_GL_GL_DRAW_TETRAHEDRON_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 tetrahedron_type>
00027 inline void DrawTetrahedron(tetrahedron_type const & tetrahedron, bool wireframe = false)
00028 {
00029 typedef typename tetrahedron_type::vector3_type vector3_type;
00030
00031 vector3_type const & p0 = tetrahedron.p0();
00032 vector3_type const & p1 = tetrahedron.p1();
00033 vector3_type const & p2 = tetrahedron.p2();
00034 vector3_type const & p3 = tetrahedron.p3();
00035
00036 GLenum const mode = wireframe ? GL_LINE_LOOP : GL_POLYGON ;
00037
00038 vector3_type n, v, u;
00039
00040 v = p0 - p1;
00041 u = p2 - p1;
00042 n = unit(v % u);
00043 glBegin(mode);
00044 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00045 glVertex3f((GLfloat)p1[0],(GLfloat)p1[1],(GLfloat)p1[2]);
00046 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00047 glVertex3f((GLfloat)p0[0],(GLfloat)p0[1],(GLfloat)p0[2]);
00048 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00049 glVertex3f((GLfloat)p2[0],(GLfloat)p2[1],(GLfloat)p2[2]);
00050 glEnd();
00051
00052 v = p1 - p0;
00053 u = p3 - p0;
00054 n = unit(v % u);
00055 glBegin(mode);
00056 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00057 glVertex3f((GLfloat)p0[0],(GLfloat)p0[1],(GLfloat)p0[2]);
00058 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00059 glVertex3f((GLfloat)p1[0],(GLfloat)p1[1],(GLfloat)p1[2]);
00060 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00061 glVertex3f((GLfloat)p3[0],(GLfloat)p3[1],(GLfloat)p3[2]);
00062 glEnd();
00063
00064
00065 v = p2 - p1;
00066 u = p3 - p1;
00067 n = unit(v % u);
00068 glBegin(mode);
00069 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00070 glVertex3f((GLfloat)p1[0],(GLfloat)p1[1],(GLfloat)p1[2]);
00071 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00072 glVertex3f((GLfloat)p2[0],(GLfloat)p2[1],(GLfloat)p2[2]);
00073 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00074 glVertex3f((GLfloat)p3[0],(GLfloat)p3[1],(GLfloat)p3[2]);
00075 glEnd();
00076
00077 v = p0 - p2;
00078 u = p3 - p2;
00079 n = unit(v % u);
00080 glBegin(mode);
00081 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00082 glVertex3f((GLfloat)p2[0],(GLfloat)p2[1],(GLfloat)p2[2]);
00083 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00084 glVertex3f((GLfloat)p0[0],(GLfloat)p0[1],(GLfloat)p0[2]);
00085 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00086 glVertex3f((GLfloat)p3[0],(GLfloat)p3[1],(GLfloat)p3[2]);
00087 glEnd();
00088 }
00089
00090 }
00091
00092 }
00093
00094
00095 #endif