proj home

Files   Classes   Functions   Hierarchy  

tetrahedrondraw.h

Go to the documentation of this file.
00001 #ifndef TETRAHEDRONDRAW_H
00002 #define TETRAHEDRONDRAW_H
00003 
00004 #include <gobj.h>
00005 
00006 #include <tetrahedron.h>
00007 
00008 
00013 template< typename T, typename D >
00014 class tetrahedrondraw : public tetrahedron<T,D> 
00015 {
00016   void displaywindingside
00017   (
00018     gobjContainer & c,
00019     T const & N, 
00020     T const & P0, 
00021     T const & P1, 
00022     T const & P2 
00023   ) const;
00024 public:
00025 
00026   /* Constructor: tetrahedron's points.  The order is 
00027      important.
00028 
00029      The first three points are the tetrahedrons base with an
00030      clockwise winding defining a normal pointing inside the 
00031      tetrahedron. The fourth point is above this triangle. 
00032      eg the base triangle can see the fourth point. */
00033   tetrahedrondraw
00034   (
00035     T const p0_,
00036     T const p1_,
00037     T const p2_,
00038     T const p3_
00039   );
00040 
00041   /* Call the function for any of these options. */
00042 
00043   /* Display the tetrahedron edges. */
00044   void displayedges() const;
00045 
00046   /* Displays the base which is the first three points that
00047      form the tetrahedron. */
00048   void displaybase() const;
00049 
00050   /* Draws the winding on the outside of the tetrahedron.
00051      RGB correspons with the colors at the vertex to indicate
00052      the triangles winding. */
00053   void displaywinding() const;
00054 
00055 };
00056 
00057 
00058 // --------------------------------------------------------- 
00059 // Implementation
00060 
00061 
00062 template< typename T, typename D >
00063 void tetrahedrondraw<T,D>::displaywindingside
00064 (
00065   gobjContainer & c,
00066   T const & N, 
00067   T const & P0, 
00068   T const & P1, 
00069   T const & P2 
00070 ) const 
00071 {
00072   c.push( new gobjglColor3ub(255,0,0) ); 
00073   c.push( new gobjglNormal3f(N) ); 
00074   c.push( new gobjglVertex3f(P0) ); 
00075   c.push( new gobjglColor3ub(0,255,0) ); 
00076   c.push( new gobjglNormal3f(N) ); 
00077   c.push( new gobjglVertex3f(P1) ); 
00078   c.push( new gobjglColor3ub(0,0,255) ); 
00079   c.push( new gobjglNormal3f(N) ); 
00080   c.push( new gobjglVertex3f(P2) ); 
00081 }
00082 
00083 #define TET3SIDE(H3,P0,P1,P2) \
00084 { \
00085   T nH3(tetrahedron<T,D>::H3.normal); \
00086   displaywindingside(c,nH3,tetrahedron<T,D>::P0,tetrahedron<T,D>::P1,tetrahedron<T,D>::P2); \
00087 }
00088 
00089 
00090 template< typename T, typename D >
00091 void tetrahedrondraw<T,D>::displaywinding() const
00092 {
00093   gobjContainer & c = * gobjContainer::global;
00094 
00095   c.push( new gobjglEnable(GL_LIGHTING) );
00096 
00097   c.push( new gobjglBegin(GL_TRIANGLES) );
00098  
00099   TET3SIDE(hi[3],pi[0],pi[1],pi[2])
00100 
00101   TET3SIDE(hi[0],pi[2],pi[1],pi[3])
00102 
00103   TET3SIDE(hi[1],pi[3],pi[0],pi[2])
00104 
00105   TET3SIDE(hi[2],pi[1],pi[0],pi[3])
00106 
00107   c.push( new gobjglEnd() );
00108 }
00109 
00110 template< typename T, typename D >
00111 void tetrahedrondraw<T,D>::displaybase() const
00112 {
00113   gobjContainer* c = gobjContainer::global;
00114   c->push( new gobjglPushAttrib(GL_CURRENT_BIT) );
00115   c->push( new gobjglPushAttrib(GL_LIGHTING_BIT) );
00116 
00117   T N(tetrahedron<T,D>::hi[3].normal);
00118   T N2(N);
00119   N2 *= -1.0;
00120 
00121   c->push( new gobjglBegin(GL_TRIANGLES) );
00122 
00123   c->push( new gobjglColor3ub(255,0,0) );
00124   c->push( new gobjglNormal3f(N) );
00125   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[0]) );
00126   c->push( new gobjglColor3ub(0,255,0) );
00127   c->push( new gobjglNormal3f(N) );
00128   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[1]) );
00129   c->push( new gobjglColor3ub(0,0,255) );
00130   c->push( new gobjglNormal3f(N) );
00131   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[2]) );
00132 
00133 
00134   c->push( new gobjglColor3ub(0,0,255) );
00135   c->push( new gobjglNormal3f(N2) );
00136   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[2]) );
00137   c->push( new gobjglColor3ub(255,255,0) );
00138   c->push( new gobjglNormal3f(N2) );
00139   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[1]) );
00140   c->push( new gobjglColor3ub(255,0,0) );
00141   c->push( new gobjglNormal3f(N2) );
00142   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[0]) );
00143 
00144 
00145 
00146 
00147 
00148 
00149   c->push( new gobjglEnd() );
00150 
00151   c->push( new gobjglPopAttrib() );
00152   c->push( new gobjglPopAttrib() );
00153 }
00154 
00155 
00156 
00157 template< typename T, typename D >
00158 void tetrahedrondraw<T,D>::displayedges() const
00159 {
00160   gobjContainer* c = gobjContainer::global;
00161 //  c->push_back( new gobjglPushAttrib(GL_CURRENT_BIT) );
00162 //  c->push_back( new gobjglPushAttrib(GL_LIGHTING_BIT) );
00163 
00164   //c->push_back( new gobjglColor3f(0.6,0.3,0.0) );
00165   c->push( new gobjglColor3ub(0,0,255) );
00166   c->push( new gobjglDisable(GL_LIGHTING) );
00167   c->push( new gobjglBegin(GL_LINES) );
00168 
00169   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[0]) );
00170   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[1]) );
00171   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[0]) );
00172   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[2]) );
00173   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[0]) );
00174   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[3]) );
00175 
00176   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[1]) );
00177   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[2]) );
00178   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[1]) );
00179   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[3]) );
00180 
00181   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[2]) );
00182   c->push( new gobjglVertex3f(tetrahedron<T,D>::pi[3]) );
00183 
00184   c->push( new gobjglEnd() );
00185 
00186 //  c->push_back( new gobjglPopAttrib() );
00187 //  c->push_back( new gobjglPopAttrib() );
00188 }
00189 
00190 
00191 
00192 template< typename T, typename D >
00193 tetrahedrondraw<T,D>::tetrahedrondraw
00194 (
00195   T const p0_,
00196   T const p1_,
00197   T const p2_,
00198   T const p3_
00199 )
00200   : tetrahedron<T,D>(p0_,p1_,p2_,p3_)
00201 {
00202 }
00203 
00204 
00205 #endif
00206 

Generated on Fri Mar 4 00:49:31 2011 for Chelton Evans Source by  doxygen 1.5.8