Example #1
0
void Stroke::discPoint(float x,float y,float brushRadius)
{
#ifdef SCAN_CONVERT
  // really ought to implement scan-conversion of the circle here
  
  glColor3ub(0,0,255);
  drawCap(Point(x,y),1,0,0,0);
  drawCap(Point(x,y),-1,0,0,0);
#else
  glPushMatrix();
  glTranslatef(x,y,z);
  gluDisk(qobj,0,brushRadius,NUM_SLICES,1);
  glPopMatrix();
#endif
}
void CubicCurve::drawBeginningCap()
{
    // Calculate the dimenions of the caps
    Vec2f d1 = _control1 - _anchor1;
    Vec2f d2 = _control2 - _anchor2;
    
    Vec2f normalVec1 = Vec2f(-d1.y,d1.x).normalized();
    Vec2f normalVec2 = Vec2f(-d2.y,d2.x).normalized();
    
    // If either normals are Nan then recalculate using the anchor points
    if(normalVec2.x != normalVec2.x || normalVec1.x != normalVec1.x)
    {
        Vec2f d = _anchor1 - _anchor2;
        normalVec2 = Vec2f(-d.y,d.x).normalized();
        
        d = _anchor2 - _anchor1;
        normalVec1 = Vec2f(-d.y,d.x).normalized();
    }
    
    normalVec1 = normalVec1 * Vec2f(_lineWidthFront,_lineWidthFront);
    normalVec2 = normalVec2 * Vec2f(_lineWidthFront,_lineWidthFront);
    
        Vec2f a0 = _anchor1 + normalVec1;
        Vec2f a1 = _anchor1 - normalVec1;
        Vec2f a2 = (_anchor1 - normalVec1) - (_anchor2-_anchor1).normalized() * _lineWidthFront;
        Vec2f a3 = (_anchor1 + normalVec1) - (_anchor2-_anchor1).normalized() * _lineWidthFront;
        
        drawCap(a0,a1,a2,a3,0);
    
}
Example #3
0
void Stroke::drawThickCurve(vector<Point> * curve, float radius,bool cap)
{

  float radius1;
  cap &= !taperBrush;

  if (useTexture)
    glEnable(GL_TEXTURE_2D);
  else
    glDisable(GL_TEXTURE_2D);

  int i=0;
  float dx,dy,mag;
  Point p0;
  Point p1;
  Point p2;	

  if (curve->empty())
    return;

  p0 = (*curve)[0];

  if (curve->size() == 1)
    {
      if (cap) discPoint(p0.x,p0.y,radius);
      return;
    }

  p1 = (*curve)[1];

  dx = p1.y - p0.y;
  dy = p0.x - p1.x;

  mag = sqrt(dx*dx + dy*dy);

  dx /= mag;
  dy /= mag;

  float textureU = ustart;
  float textureV = vstart;

  glColor3ub(0,0,255);

  if (cap)
    drawCap(p0, dx, dy,textureU,textureV);

#ifdef SCAN_CONVERT
  glDisable(GL_TEXTURE_2D);

  Point v0(p0.x + radius * dx, p0.y + radius * dy);
  Point v1(p0.x - radius * dx, p0.y - radius * dy);

#else
  glBegin(GL_TRIANGLE_STRIP);


  //////////////////////// tapering ///////////////////////////
  radius1 = taperBrush ? 0 : radius; 
  //////////////////////// tapering ///////////////////////////

  glTexCoord2f(textureU,textureV + vfreq);
  glVertex3f(p0.x + radius1 * dx, p0.y + radius1 * dy,z);
  
  glTexCoord2f(textureU,textureV - vfreq);
  glVertex3f(p0.x - radius1 * dx, p0.y - radius1 * dy,z);
#endif

  textureU += ufreq;

#ifdef SCAN_CONVERT
  // draw the patch in between with extra subdivision to match the caps,
  // to prevent holes from appearing in the stroke
  if (curve->size() >= 2)
    {
      float dist = sqrt((p1.x-p0.x)*(p1.x-p0.x)+(p1.y-p0.y)*(p1.y-p0.y));
      textureU += ufreq * dist;

      v0 = Point(p0.x + radius * dx, p0.y + radius * dy);
      v1 = Point(p0.x - radius * dx, p0.y - radius * dy);
      Point v2(p1.x + radius * dx, p1.y + radius * dy);
      Point v3(p1.x - radius * dx, p1.y - radius * dy);
	  
      glColor3ub(255,0,0);
      //      drawTriangle(v2,v3,v0);
      drawTriangle(v2,p1,v0);
      glColor3ub(255,255,0);
      drawTriangle(p1,v3,v0);

      glColor3ub(0,255,0);
      //      drawTriangle(v0,v1,v3);
      drawTriangle(v0,p0,v3);
      glColor3ub(0,255,255);
      drawTriangle(p0,v1,v3);

      glColor3ub(0,0,255);

      if (curve->size() == 2)
	{
	  drawCap(p1,-dx,-dy,textureU,textureV);
	  return;
	}


      v0 = v2;
      v1 = v3;
    }
#endif

#ifdef SCAN_CONVERT
  for(i=2;i<curve->size()-1;i++)
#else
  for(i=1;i<curve->size()-1;i++)
#endif
    {
      p0 = (*curve)[i-1];
      p1 = (*curve)[i];
      p2 = (*curve)[i+1];

      dx = p2.y - p0.y;
      dy = p0.x - p2.x;

      mag = sqrt(dx*dx + dy*dy);

      dx /= mag;
      dy /= mag;

      float dist = sqrt((p1.x-p0.x)*(p1.x-p0.x)+(p1.y-p0.y)*(p1.y-p0.y));
      textureU += ufreq * dist;

#ifdef SCAN_CONVERT
      Point v2(p1.x + radius * dx, p1.y + radius * dy);
      Point v3(p1.x - radius * dx, p1.y - radius * dy);

      glColor3ub(255,0,0);
      drawTriangle(v2,v3,v0);

      glColor3ub(0,255,0);
      drawTriangle(v0,v1,v3);
	  
      v0 = v2;
      v1 = v3;
#else

      //////////////////////// tapering ///////////////////////////
      radius1 = taperBrush ? tapering(radius, i, curve->size()) : radius; 

      glTexCoord2f(textureU,textureV + vfreq);
      glVertex3f(p1.x + radius1 * dx, p1.y + radius1 * dy,z);
	  
      glTexCoord2f(textureU,textureV - vfreq);
      glVertex3f(p1.x - radius1 * dx, p1.y - radius1 * dy,z);
      //////////////////////// tapering ///////////////////////////

#endif

    }

  p0 = (*curve)[curve->size()-2];
  p1 = (*curve)[curve->size()-1];
    
  dx = p1.y - p0.y;
  dy = p0.x - p1.x;
    
  mag = sqrt(dx*dx + dy*dy);

  dx /= mag;
  dy /= mag;
      
  textureU += ufreq *mag;
  
#ifdef SCAN_CONVERT
  Point v2(p1.x + radius * dx, p1.y + radius * dy);
  Point v3(p1.x - radius * dx, p1.y - radius * dy);
      
  glColor3ub(255,0,0);
  //  drawTriangle(v2,v3,v0);
  drawTriangle(v2,p1,v0);
  glColor3ub(255,255,0);
  drawTriangle(p1,v3,v0);

  glColor3ub(0,255,0);
    drawTriangle(v0,v3,v1);
    //  drawTriangle(v0,p0,v3);
    //  glColor3ub(0,255,255);
    //  drawTriangle(p0,v1,v3);

#else

  //////////////////////// tapering ///////////////////////////
  radius1 = taperBrush ? 0 : radius; 
  //////////////////////// tapering ///////////////////////////

  glTexCoord2f(textureU,textureV + vfreq);
  glVertex3f(p1.x + radius1 * dx, p1.y + radius1 * dy,z);
  glTexCoord2f(textureU,textureV - vfreq);
  glVertex3f(p1.x - radius1 * dx, p1.y - radius1 * dy,z);
      
  glEnd();
#endif



  glColor3ub(0,0,255);

  if (cap)
    {
      drawCap(p1, -dx, -dy,textureU,textureV);
    }

}