00001 #ifndef OPENTISSUE_OPENTISSUE_UTILITY_GL_GL_DRAW_PRISM_H
00002 #define OPENTISSUE_OPENTISSUE_UTILITY_GL_GL_DRAW_PRISM_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 prism_type>
00027 inline void DrawPrism(prism_type const & prism, unsigned int mode)
00028 {
00029 typedef typename prism_type::real_type real_type;
00030 typedef typename prism_type::vector3_type vector3_type;
00031
00032 vector3_type const & p0 = prism.p0();
00033 vector3_type const & p1 = prism.p1();
00034 vector3_type const & p2 = prism.p2();
00035 real_type const & height = prism.height();
00036
00037
00038 vector3_type u = (p1-p0);
00039 vector3_type v = (p2-p0);
00040 vector3_type n = unit ( u % v);
00041
00042 vector3_type p0h = p0 + height*n;
00043 vector3_type p1h = p1 + height*n;
00044 vector3_type p2h = p2 + height*n;
00045
00046 glBegin(mode);
00047 glNormal3f((GLfloat)-n[0],(GLfloat)-n[1],(GLfloat)-n[2]);
00048 glVertex3f((GLfloat)p0[0],(GLfloat)p0[1],(GLfloat)p0[2]);
00049 glNormal3f((GLfloat)-n[0],(GLfloat)-n[1],(GLfloat)-n[2]);
00050 glVertex3f((GLfloat)p2[0],(GLfloat)p2[1],(GLfloat)p2[2]);
00051 glNormal3f((GLfloat)-n[0],(GLfloat)-n[1],(GLfloat)-n[2]);
00052 glVertex3f((GLfloat)p1[0],(GLfloat)p1[1],(GLfloat)p1[2]);
00053 glEnd();
00054 glBegin(mode);
00055 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00056 glVertex3f((GLfloat)p0h[0],(GLfloat)p0h[1],(GLfloat)p0h[2]);
00057 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00058 glVertex3f((GLfloat)p1h[0],(GLfloat)p1h[1],(GLfloat)p1h[2]);
00059 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00060 glVertex3f((GLfloat)p2h[0],(GLfloat)p2h[1],(GLfloat)p2h[2]);
00061 glEnd();
00062
00063
00064 u = (p1-p0);
00065 v = (p1h-p1);
00066 n = unit ( u % v);
00067
00068 glBegin(mode);
00069 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00070 glVertex3f((GLfloat)p0[0],(GLfloat)p0[1],(GLfloat)p0[2]);
00071 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00072 glVertex3f((GLfloat)p1[0],(GLfloat)p1[1],(GLfloat)p1[2]);
00073 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00074 glVertex3f((GLfloat)p1h[0],(GLfloat)p1h[1],(GLfloat)p1h[2]);
00075 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00076 glVertex3f((GLfloat)p0h[0],(GLfloat)p0h[1],(GLfloat)p0h[2]);
00077 glEnd();
00078
00079 u = (p2-p1);
00080 v = (p2h-p2);
00081 n = unit ( u % v);
00082
00083 glBegin(mode);
00084 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00085 glVertex3f((GLfloat)p1[0],(GLfloat)p1[1],(GLfloat)p1[2]);
00086 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00087 glVertex3f((GLfloat)p2[0],(GLfloat)p2[1],(GLfloat)p2[2]);
00088 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00089 glVertex3f((GLfloat)p2h[0],(GLfloat)p2h[1],(GLfloat)p2h[2]);
00090 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00091 glVertex3f((GLfloat)p1h[0],(GLfloat)p1h[1],(GLfloat)p1h[2]);
00092 glEnd();
00093
00094 u = (p0-p2);
00095 v = (p0h-p0);
00096 n = unit ( u % v);
00097
00098 glBegin(mode);
00099 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00100 glVertex3f((GLfloat)p2[0],(GLfloat)p2[1],(GLfloat)p2[2]);
00101 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00102 glVertex3f((GLfloat)p0[0],(GLfloat)p0[1],(GLfloat)p0[2]);
00103 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00104 glVertex3f((GLfloat)p0h[0],(GLfloat)p0h[1],(GLfloat)p0h[2]);
00105 glNormal3f((GLfloat)n[0],(GLfloat)n[1],(GLfloat)n[2]);
00106 glVertex3f((GLfloat)p2h[0],(GLfloat)p2h[1],(GLfloat)p2h[2]);
00107 glEnd();
00108 }
00109
00110 }
00111
00112 }
00113
00114
00115 #endif