proj home

Files   Classes   Functions   Hierarchy  

ruler Class Reference

#include <ruler.h>

Inheritance diagram for ruler:
Collaboration diagram for ruler:

List of all members.

Public Member Functions

void addStraightRuler (doublec len, point2< double > const &pos0, point2< double > const &pos1, doublec ticklenmajor, doublec ticklenmiddle, doublec ticklenminor)
 Let len be the rulers length.
void addAngleRuler (doublec radius, doublec angle0, doublec angle1, doublec ticklenmajor, doublec ticklenmiddle, doublec ticklenminor)
 Draw a circular arc ruler.


Detailed Description

Definition at line 8 of file ruler.h.


Member Function Documentation

void ruler::addAngleRuler ( doublec  radius,
doublec  angle0,
doublec  angle1,
doublec  ticklenmajor,
doublec  ticklenmiddle,
doublec  ticklenminor 
)

Draw a circular arc ruler.

Every 10 degrees a major tick is drawn. Every 5 degrees a middle tick is drawn. Every 1 degree a minor tick is drawn.

Definition at line 12 of file ruler.cpp.

References degtorad, gobjContainer::push(), point2< T >::x, and point2< T >::y.

Referenced by protractor::addAngleRuler().

00020 {
00021   assert(angle0 >= 0.0);
00022   assert(angle0 < angle1);
00023 
00024   gobjContainer * c = new gobjContainer();
00025 
00026   c->push( new gobjglBegin(GL_LINES) );
00027 
00028   doublec degtorad = PI / 180.0;
00029   double t;
00030 
00031   for (double s=angle0; s<=angle1; )
00032   {
00033     t = s * degtorad;
00034     //point2<double> const w(radius*cos(t),radus*sin(t));  //Save on trig calculations.
00035     point2<double> const nm(-cos(t),-sin(t));  // The normal
00036     point2<double> const w(-nm.x*radius,-nm.y*radius);  // Point on curve.
00037 
00038     c->push( new gobjglVertex2f(w) );
00039     c->push( new gobjglVertex2f(w + nm * ticklenmajor) ); 
00040     s += 10.0;
00041   }
00042 
00043   for (double s=angle0; s<=angle1; )
00044   {
00045     t = s * degtorad;
00046     point2<double> const nm(-cos(t),-sin(t));  // The normal
00047     point2<double> const w(-nm.x*radius,-nm.y*radius);  // Point on curve.
00048 
00049     c->push( new gobjglVertex2f(w) );
00050     c->push( new gobjglVertex2f(w + nm * ticklenmiddle) ); 
00051     s += 5.0;
00052   }
00053 
00054   for (double s=angle0; s<=angle1; )
00055   {
00056     t = s * degtorad;
00057     point2<double> const nm(-cos(t),-sin(t));  // The normal
00058     point2<double> const w(-nm.x*radius,-nm.y*radius);  // Point on curve.
00059 
00060     c->push( new gobjglVertex2f(w) );
00061     c->push( new gobjglVertex2f(w + nm * ticklenminor) ); 
00062     s += 1.0;
00063   }
00064 
00065 
00066   c->push(new gobjglEnd());
00067 
00068   push(c);
00069 }

void ruler::addStraightRuler ( doublec  len,
point2< double > const &  pos0,
point2< double > const &  pos1,
doublec  ticklenmajor,
doublec  ticklenmiddle,
doublec  ticklenminor 
)

Let len be the rulers length.

Every 1.0 unit a major tick is drawn. Every 0.5 unit a middle tick is drawn. Every 0.1 unit a minor tick is drawn. The ruler is scaled and exists from pos0 to pos1.

Definition at line 73 of file ruler.cpp.

References point2< T >::normalize(), gobjContainer::push(), point2< T >::x, and point2< T >::y.

Referenced by protractor::addRadiusRuler().

00081 {
00082   uintc n = (uintc)(floor(len));
00083 
00084   //doublec dt = 1.0 / ((double)n - 1.0);
00085   doublec dt = 1.0 / len;
00086 
00087   point2<double> const p2(pos1-pos0);
00088 
00089   point2<double> tmp(-p2.y,p2.x);
00090   tmp.normalize();
00091   point2<double> const nm(tmp);
00092 
00093   gobjContainer * c = new gobjContainer();
00094 
00095   c->push( new gobjglBegin(GL_LINES) );
00096 
00097   for (uint i=0; i<n; ++i)
00098   {
00099     point2<double> w(pos0 + p2*(dt*i));
00100 
00101     // Write the major ticks.
00102     c->push( new gobjglVertex2f(w) );
00103     c->push( new gobjglVertex2f(w + nm * ticklenmajor) );
00104 
00105     // Write the middle ticks.
00106     point2<double> w2(pos0 + p2*(dt*(i+0.5)));
00107     c->push( new gobjglVertex2f(w2) );
00108     c->push( new gobjglVertex2f(w2 + nm * ticklenmiddle) );
00109 
00110     // Write the minor ticks
00111     for (uint k=1; k<=4; ++k)
00112     {
00113       point2<double> w3(pos0 + p2*(dt*(i+k*0.1)));
00114       c->push( new gobjglVertex2f(w3) );
00115       c->push( new gobjglVertex2f(w3 + nm * ticklenminor) );
00116     }
00117     for (uint k=1; k<=4; ++k)
00118     {
00119       point2<double> w3(pos0 + p2*(dt*(i+0.5+k*0.1)));
00120       c->push( new gobjglVertex2f(w3) );
00121       c->push( new gobjglVertex2f(w3 + nm * ticklenminor) );
00122     }
00123   }
00124 
00125   // Write the last major tick.
00126   if (len>1.0)
00127   {
00128     point2<double> w(pos0 + p2*(dt*n));
00129     c->push( new gobjglVertex2f(w) );
00130     c->push( new gobjglVertex2f(w + nm * ticklenmajor) );
00131   }
00132 
00133   // Write the last middle tick
00134   if ((len-n)>=0.5)
00135   {
00136     point2<double> w(pos0 + p2*(dt*(n+0.5)));
00137     c->push( new gobjglVertex2f(w) );
00138     c->push( new gobjglVertex2f(w + nm * ticklenmiddle) );
00139   }
00140 
00141   // The following suggests an easier way of writing this routine.
00142   // Instead of separating into cases, just write all the minor ticks
00143   // at once, then the middle and major ticks, overwriting the previous ones.
00144   // While it writes unnecessary lines its logic and code is much less.
00145 
00146   if ((len-n)>0.0)
00147   {
00148     for (double s=0.0, s1=len-n; s<=s1; )
00149     {
00150       point2<double> w(pos0 + p2*(dt*(n+s)));
00151       c->push( new gobjglVertex2f(w) );
00152       c->push( new gobjglVertex2f(w + nm * ticklenminor) ); 
00153       s += 0.1;
00154     }
00155   }
00156 
00157   c->push(new gobjglEnd());
00158 
00159   push(c);
00160 }


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:16 2011 for Chelton Evans Source by  doxygen 1.5.8