proj home

Files   Classes   Functions   Hierarchy  

d2simplexintersection.cpp

Go to the documentation of this file.
00001 #include <GL/glut.h>
00002 #include <GL/gl.h>
00003 
00004 
00005 #include <d2simplexintersection.h>
00006 
00007 #include <d2arrow.h>
00008 
00009 
00010 void d2simplexintersection::draw()
00011 {
00012   glPushAttrib(GL_LIGHTING);
00013   glPushAttrib(GL_CURRENT_BIT);
00014 
00015   glDisable(GL_LIGHTING);
00016 
00017   if (intersection)
00018   {
00019     glColor3ub(255,0,0);
00020 
00021     d2simplexFill(s1).draw();
00022     d2simplexFill(s2).draw();
00023   }
00024 
00025   glColor3ub(0,255,127);
00026   s1g.draw();
00027   d2simplexNormals(s1).draw();
00028 
00029   glColor3ub(255,255,0);
00030   s2g.draw();
00031   d2simplexNormals(s2).draw();
00032 
00033   glPopAttrib();
00034   glPopAttrib();
00035 }
00036 
00037 d2simplexintersection::d2simplexintersection
00038 (
00039   d2simplex & _s1,
00040   d2simplex & _s2
00041 )
00042   : s1(_s1), s2(_s2), s1g(s1), s2g(s2), intersection(false) 
00043 {
00044 }
00045 
00046 
00047 d2simplexOutline::d2simplexOutline(d2simplex & _s)
00048   : s(_s)
00049 {
00050 }
00051 
00052 void d2simplexOutline::draw()
00053 {
00054   glBegin(GL_LINES);
00055 
00056   glVertex3f(s.v[0].x,s.v[0].y,0.0);
00057   glVertex3f(s.v[1].x,s.v[1].y,0.0);
00058   glVertex3f(s.v[1].x,s.v[1].y,0.0);
00059   glVertex3f(s.v[2].x,s.v[2].y,0.0);
00060   glVertex3f(s.v[0].x,s.v[0].y,0.0);
00061   glVertex3f(s.v[2].x,s.v[2].y,0.0);
00062 
00063   glEnd();
00064 }
00065 
00066 
00067 d2simplexFill::d2simplexFill(d2simplex & _s)
00068   : s(_s)
00069 {
00070 }
00071 
00072 void d2simplexFill::draw()
00073 {
00074   glBegin(GL_TRIANGLES);
00075 
00076   glVertex3f(s.v[0].x,s.v[0].y,0.0);
00077   glVertex3f(s.v[1].x,s.v[1].y,0.0);
00078   glVertex3f(s.v[2].x,s.v[2].y,0.0);
00079 
00080   glVertex3f(s.v[2].x,s.v[2].y,0.0);
00081   glVertex3f(s.v[1].x,s.v[1].y,0.0);
00082   glVertex3f(s.v[0].x,s.v[0].y,0.0);
00083 
00084   glEnd();
00085 }
00086 
00087 d2simplexNormals::d2simplexNormals(d2simplex & _s)
00088   : s(_s), arrowlength(0.1), headlength(0.03)
00089 {
00090 }
00091 
00092 void d2simplexNormals::draw()
00093 {
00094 //  double const arrowlength=0.1;
00095 //  double const headlength=0.03;
00096   d2arrow * arrow[3];
00097   arrow[0] = new d2arrow(s.v[1],s.v[0],arrowlength,headlength);
00098   arrow[1] = new d2arrow(s.v[2],s.v[1],arrowlength,headlength);
00099   arrow[2] = new d2arrow(s.v[0],s.v[2],arrowlength,headlength);
00100 
00101   for (uint i=0; i<3; ++i)
00102   {
00103     arrow[i]->draw();
00104     delete arrow[i];
00105   }
00106 
00107   // Note the more efficient way of doing this is to construct the
00108   // arrows once and transform the points as the simplex points are
00109   // transformed.  
00110 
00111   // I am currently assuming that the graphics is separate from the
00112   // simplex so an on the fly computation is needed.  When the simplex
00113   // is rotated so too is the normals but I would need to redesign
00114   // the interfaces.  The on the fly computation creates a separation
00115   // at the cost of performance, though in this case it is not too bad
00116   // because vector calculus is good.
00117 
00118 }
00119 
00120 
00121 
00122 
00123 
00124 

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