home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / freedraft.tar.gz / freedraft.tar / FREEdraft-050298 / DRAWABLES / drawablecircle.cpp < prev    next >
C/C++ Source or Header  |  1998-04-23  |  3KB  |  78 lines

  1. // drawablecircle.cpp
  2.  
  3. // Copyright (C) 1997  Cliff Johnson                                       //
  4. //                                                                         //
  5. // This program is free software; you can redistribute it and/or           //
  6. // modify it under the terms of the GNU  General Public                    //
  7. // License as published by the Free Software Foundation; either            //
  8. // version 2 of the License, or (at your option) any later version.        //
  9. //                                                                         //
  10. // This software is distributed in the hope that it will be useful,        //
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of          //
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       //
  13. // General Public License for more details.                                //
  14. //                                                                         //
  15. // You should have received a copy of the GNU General Public License       //
  16. // along with this software (see COPYING); if not, write to the        //
  17. // Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
  18.  
  19. #include <geom_enum.h>
  20. #include <drawablecircle.h>
  21. #include <GL/gl.h>
  22. #include <GL/glu.h>
  23. #include <point.h>
  24. #include <circle.h>
  25.  
  26. DrawableCircle::DrawableCircle(): DrawableGeom(CIRCLE) {}
  27.  
  28. void DrawableCircle::Draw(const Geom* geom,const float& scale) const
  29. {
  30.     if(DrawableGeom::Type()!=CIRCLE)return;
  31.  
  32. // experimental - adaptave drawing
  33. // experimental - figure out how many points are necessary based on the size
  34. // of the circle and the scale. The question is: is it faster to adapt the 
  35. // number of points, or does it take longer to figure out home many points to use. 
  36.  
  37. // size is size on screen
  38.     float size = scale * 2 * (dynamic_cast<const Circle*>(geom))->Radius();
  39.     int npoints;
  40.  
  41. // linear 
  42.     if(size < .1)return; // in most human sized cases the maximum zoom will be reached before this happens.
  43.     if(size < 5. ) npoints = 5;
  44.     else if( size < 200.) npoints = (int) (15 + .1 * size);
  45.     else npoints = 35;
  46. // at 5 mm 5 points
  47. // at 200 mm 35 points
  48.  
  49.         glBegin(GL_LINE_LOOP);
  50.         Point p;    
  51.         double u,du;
  52.         du  = 1./npoints;
  53.         for(int i=0; i<npoints; i++){
  54.             p = (dynamic_cast<const Circle*>(geom))->U(u);
  55.                     glVertex2f(p[0],p[1]);
  56.             u += du;
  57.         }
  58.         glEnd();
  59. }
  60.  
  61. void DrawableCircle::Select(const Geom* geom,const Handle& h,const float& scale) const
  62. {
  63.     if(DrawableGeom::Type()!=CIRCLE)return;
  64.  
  65.     glLoadName(h.Value());
  66.  
  67.         glBegin(GL_LINE_LOOP);
  68.         Point p;    
  69.         double u,du;
  70.         du  = 1./37.;
  71.         for(int i=0; i<37; i++){
  72.             p = (dynamic_cast<const Circle*>(geom))->U(u);
  73.                     glVertex2f(p[0],p[1]);
  74.             u += du;
  75.         }
  76.         glEnd();
  77. }
  78.