bool Clipping::clipCurve(Object *obj){
    auto& coords = obj->getNCoords();
    Coordinates newPath;
    bool prevInside = true;
    Coordinate prev;

    for(unsigned int i = 0; i < coords.size(); i++){
        if(clipPoint(coords[i])){
            if(!prevInside){
                clipLine(prev, coords[i]);
                newPath.push_back(prev);
            }
            newPath.push_back(coords[i]);
            prevInside = true;
        }else{
            if(prevInside && newPath.size() != 0){
                clipLine(prev, coords[i]);
                newPath.push_back(coords[i]);
            }
            prevInside = false;
        }
        prev = coords[i];
    }

    if(newPath.size() == 0)
        return false;

    obj->setNCoord(newPath);
    return true;
}
Пример #2
0
void main(){
	int color;
	int clip1X, clip1Y, clip2X, clip2Y;
	int end1X, end1Y, end2X, end2Y, retval;
	
	srand(*my_clock);
	set_mode(VGA_256_COLOR_MODE);
	
//	color=rand()%NUM_COLORS;
	color=175;
	
//	membuat view (kotak)
	line_bresenham(KIRI,ATAS,KANAN,ATAS,color);
	line_bresenham(KANAN,ATAS,KANAN,BAWAH,color);
	line_bresenham(KANAN,BAWAH,KIRI,BAWAH,color);
	line_bresenham(KIRI,BAWAH,KIRI,ATAS,color);
	
//	garis pemotong 1
	clip1X = clip1Y = clip2X = clip2Y = 0;
	
	end1X = 130; end1Y = 30; end2X = 150; end2Y = 150;
	line_bresenham(end1X,end1Y,end2X,end2Y,color);
	retval = clipLine(end1X,end1Y,end2X,end2Y,&clip1X,&clip1Y,&clip2X,&clip2Y);
	if(retval) {
		line_bresenham(clip1X,clip1Y,clip2X,clip2Y,color-99);
	}
	
//	garis pemotong 2
	end1X = 50; end1Y = 90; end2X = 215; end2Y = 90;
	line_bresenham(end1X,end1Y,end2X,end2Y,color);
	retval = clipLine(end1X,end1Y,end2X,end2Y,&clip1X,&clip1Y,&clip2X,&clip2Y);
	if(retval) {
		line_bresenham(clip1X,clip1Y,clip2X,clip2Y,color-99);
	}
	
//	garis tak memotong
	end1X = 200; end1Y = 15; end2X = 200; end2Y = 170;
	line_bresenham(end1X,end1Y,end2X,end2Y,color);
	retval = clipLine(end1X,end1Y,end2X,end2Y,&clip1X,&clip1Y,&clip2X,&clip2Y);
	if(retval) {
		line_bresenham(clip1X,clip1Y,clip2X,clip2Y,color-99);
	}
	
//	garis memotong di dalam (trivial accept)
	end1X = KANAN; end1Y = ATAS; end2X = KIRI; end2Y = BAWAH;
	line_bresenham(end1X,end1Y,end2X,end2Y,color);
	retval = clipLine(end1X,end1Y,end2X,end2Y,&clip1X,&clip1Y,&clip2X,&clip2Y);
	if(retval) {
		line_bresenham(clip1X,clip1Y,clip2X,clip2Y,color-99);
	}
	
	sleep(2);	
	set_mode(TEXT_MODE);
	return;
}
Пример #3
0
// clip the triangle (V1, V2, V3) by the near and far clipping plane and
// obtain a set of vertices after the clipping.  The number of vertices
// is at most 5.
void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3],
                                     float triNormals[][3], float n1[3], float n2[3], float n3[3],
                                     bool edgeMarks[], bool em1, bool em2, bool em3, int clip[3])
{
	float *v[3], *n[3];
	bool em[3];
	int i, j, k;

	v[0] = v1; n[0] = n1;
	v[1] = v2; n[1] = n2;
	v[2] = v3; n[2] = n3;
	em[0] = em1; /* edge mark of the edge between v1 and v2 */
	em[1] = em2; /* edge mark of the edge between v2 and v3 */
	em[2] = em3; /* edge mark of the edge between v3 and v1 */
	k = 0;
	for (i = 0; i < 3; i++) {
		j = (i + 1) % 3;
		if (clip[i] == NOT_CLIPPED) {
			copy_v3_v3(triCoords[k], v[i]);
			copy_v3_v3(triNormals[k], n[i]);
			edgeMarks[k] = em[i];
			k++;
			if (clip[j] != NOT_CLIPPED) {
				clipLine(v[i], v[j], triCoords[k], (clip[j] == CLIPPED_BY_NEAR) ? _z_near : _z_far);
				copy_v3_v3(triNormals[k], n[j]);
				edgeMarks[k] = false;
				k++;
			}
		}
		else if (clip[i] != clip[j]) {
			if (clip[j] == NOT_CLIPPED) {
				clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far);
				copy_v3_v3(triNormals[k], n[i]);
				edgeMarks[k] = em[i];
				k++;
			}
			else {
				clipLine(v[i], v[j], triCoords[k], (clip[i] == CLIPPED_BY_NEAR) ? _z_near : _z_far);
				copy_v3_v3(triNormals[k], n[i]);
				edgeMarks[k] = em[i];
				k++;
				clipLine(v[i], v[j], triCoords[k], (clip[j] == CLIPPED_BY_NEAR) ? _z_near : _z_far);
				copy_v3_v3(triNormals[k], n[j]);
				edgeMarks[k] = false;
				k++;
			}
		}
	}
	BLI_assert(k == 2 + numTris);
	(void)numTris;  /* Ignored in release builds. */
}
bool Clipping::clip(Object* obj){
    switch(obj->getType()){
    case ObjType::OBJECT:
        break;
    case ObjType::POINT:
        return clipPoint(obj->getNCoord(0));
    case ObjType::LINE:
        return clipLine(obj->getNCoord(0), obj->getNCoord(1));
    case ObjType::POLYGON:
        return clipPolygon(obj);
    case ObjType::BEZIER_CURVE:
    case ObjType::BSPLINE_CURVE:
        return clipCurve(obj);
    case ObjType::OBJECT3D:{
        Object3D *obj3d = (Object3D*) obj;
        bool draw = false;
        for(auto &face : obj3d->getFaceList()){
            bool tmp = clipPolygon(&face);
            if(!tmp){ face.getNCoords().clear(); }
            draw |= tmp;
        }
        return draw;
    }case ObjType::BEZIER_SURFACE:
    case ObjType::BSPLINE_SURFACE:{
        Surface *surf = (Surface*) obj;
        bool draw = false;
        for(auto &curve : surf->getCurveList()){
            bool tmp = clipCurve(&curve);
            if(!tmp){ curve.getNCoords().clear(); }
            draw |= tmp;
        }
        return draw;
    }}
    return false;
}
Пример #5
0
/*
** Routine for clipping a polyline, stored in a shapeObj struct, to a
** rectangle. Uses clipLine() function to create a new shapeObj.
*/
void msClipPolylineRect(shapeObj *shape, rectObj rect)
{
  int i,j;
  lineObj line={0,NULL};
  double x1, x2, y1, y2;
  shapeObj tmp={0,NULL};

  if(shape->numlines == 0) /* nothing to clip */
    return;

  for(i=0; i<shape->numlines; i++) {

    line.point = (pointObj *)malloc(sizeof(pointObj)*shape->line[i].numpoints);
    line.numpoints = 0;

    x1 = shape->line[i].point[0].x;
    y1 = shape->line[i].point[0].y;
    for(j=1; j<shape->line[i].numpoints; j++) {
      x2 = shape->line[i].point[j].x;
      y2 = shape->line[i].point[j].y;

      if(clipLine(&x1,&y1,&x2,&y2,rect) == MS_TRUE) {
	if(line.numpoints == 0) { /* first segment, add both points */
	  line.point[0].x = x1;
	  line.point[0].y = y1;
	  line.point[1].x = x2;
	  line.point[1].y = y2;
	  line.numpoints = 2;
	} else { /* add just the last point */
	  line.point[line.numpoints].x = x2;
	  line.point[line.numpoints].y = y2;
	  line.numpoints++;
	}

	if((x2 != shape->line[i].point[j].x) || (y2 != shape->line[i].point[j].y)) {
	  msAddLine(&tmp, &line);
	  line.numpoints = 0; /* new line */
	}
      }

      x1 = shape->line[i].point[j].x;
      y1 = shape->line[i].point[j].y;
    }

    if(line.numpoints > 0)
      msAddLine(&tmp, &line);
    free(line.point);
    line.numpoints = 0; /* new line */
  }

  for (i=0; i<shape->numlines; i++) free(shape->line[i].point);
  free(shape->line);

  shape->line = tmp.line;
  shape->numlines = tmp.numlines;
}
Пример #6
0
inline void fill2EllipseLines(pb_rgba *pb, const uint32_t cx, const uint32_t cy, const unsigned int x, const unsigned int y, const uint32_t color)
{
	int x1 = cx - x;
	int y1 = cy+y;
	int x2 = cx + x;
	int y2 = cy+y;

	if (clipLine(pb->frame, x1, y1, x2, y2)) {
		raster_rgba_hline_blend(pb, x1, y1, x2-x1, color);
	}
	
	y1 = cy - y;
	y2 = cy - y;
	if (clipLine(pb->frame, x1, y1, x2, y2)) {
		raster_rgba_hline_blend(pb, x1, y1, x2 - x1, color);
	}

	//raster_rgba_hline_blend(pb, cx - x, cy - y, 2 * x, color);
}
Пример #7
0
    bool Frustum::project(osg::Vec3 &v1, osg::Vec3 &v2) {

        bool v1Inside, v2Inside;
        bool projected = false;
        osg::Vec3 ov1,ov2;
        ov1 = v1;
        ov2 = v2;
        
        v1Inside = inside(v1);
        v2Inside = inside(v2);

        if ((v1Inside) && (v2Inside))
            return true;

        // ok, einer oder beide punkte liegen ausserhalb des frustum-volumes, 
        // jetzt müssen wir die Schnittpunkte suchen
        
        PlaneVector::iterator itr;
         
        if (!v1Inside) {
            for (itr = _planes.begin(); itr !=_planes.end(); itr++) {
                if (clipLine((*itr), v1,ov2)) {
                    osg::notify(osg::DEBUG_INFO) << "clipped " << ov1 << " to " << v1 << " plane: " << ((*itr).name) << std::endl;
                    projected = true;
                    break;
                }
            }
        }

        if (!v2Inside) {
            for (itr = _planes.begin(); itr !=_planes.end(); itr++) {
                if (clipLine((*itr), v2,ov1)) {
                    osg::notify(osg::DEBUG_INFO) << "clipped " << ov2 << " to " << v2 << " plane: " << ((*itr).name) << std::endl;
                    projected = true;
                    break;
                }
                    
            }
        }

        return projected;
    }
bool Clipping::clip(Object* obj){
    switch(obj->getType()){
    case ObjType::POINT:
        return clipPoint(obj->getNCoord(0));
    case ObjType::LINE:
        return clipLine(obj->getNCoord(0), obj->getNCoord(1));
    case ObjType::POLYGON:
        return clipPolygon(obj);
    case ObjType::BEZIER_CURVE:
        return clipCurve(obj);
    default:
        return false;
    }
}
Пример #9
0
void PipeLine::drawLine(int x1,int y1,int x2,int y2,uint32_t c,uint32_t depth){

    if( clipLine(x1,y1,x2,y2) == false)
		return;
        


    int x, y, rem = 0;
    if (x1 == x2 && y1 == y2) {
        fillPoint( x1, y1, c,depth);
    }else if (x1 == x2) {
        int inc = (y1 <= y2)? 1 : -1;
        for (y = y1; y != y2; y += inc) fillPoint( x1, y, c,depth);
        fillPoint( x2, y2, c,depth);
    }else if (y1 == y2) {
        int inc = (x1 <= x2)? 1 : -1;
        for (x = x1; x != x2; x += inc) fillPoint( x, y1, c,depth);
        fillPoint( x2, y2, c,depth);
    }else {
        // Bresenham line
        int dx = (x1 < x2)? (x2 - x1) : (x1 - x2);
        int dy = (y1 < y2)? (y2 - y1) : (y1 - y2);
        if (dx >= dy) {
            /* x axis 每次加1 y + dy 如果大于 dx需要矫正
			*/
			if (x2 < x1) { std::swap(x1, x2);std::swap(y1, y2); }
            int delta = (y2 >= y1)? 1 : -1;
            for (x = x1, y = y1; x <= x2; x++/* x 每次加1 */) {
                rem += dy;
                if (rem >= dx) {
                    rem -= dx;
                    y += delta;
                }
                fillPoint(x,y,c,depth);
            }
        }else {
            if (y2 < y1) std::swap(x1,x2),std::swap(y1,y2);
            int delta = (x2 >= x1)? 1 : -1;
            for (x = x1, y = y1; y <= y2; y++) {
                rem += dx;
                if (rem >= dy) {
                    rem -= dy;
                    x += delta;
                }
                fillPoint(x, y,c,depth);
            }
        }
        fillPoint(x2,y2,c,depth);
    }
}
static void WinClipAndDrawLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width )
{
    GRLastMoveToX = x2;
    GRLastMoveToY = y2;

    if( ClipBox )
    {
        EDA_RECT clipbox(*ClipBox);
        clipbox.Inflate(width/2);
        if( clipLine( &clipbox, x1, y1, x2, y2 ) )
            return;
    }

    DC->DrawLine( x1, y1, x2, y2 );
}
void ProjectVisitor::ProjectTriangleToHeightField::insertTouchedLines(const osg::Vec3d& v1, const osg::Vec3d& v2)
{
  osg::Vec2d p1InGrind, p2InGrind;
  findGridFromPoint(v1, p1InGrind);
  findGridFromPoint(v2, p2InGrind);

  bool valid = clipLine(p1InGrind, p2InGrind);
  if (!valid)
    return;

  osg::ref_ptr<osg::Vec3Array> array = followLine(p1InGrind, p2InGrind);
  InsertGeometryHelper inserter;
  inserter.init(_result.get());
  inserter.appendLineStrip(array.get());
}
Пример #12
0
static void WinClipAndDrawLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
                                EDA_COLOR_T Color, int width = 1 )
{
    GRLastMoveToX = x2;
    GRLastMoveToY = y2;

    if( ClipBox )
    {
        EDA_RECT clipbox(*ClipBox);
        clipbox.Inflate(width/2);
        if( clipLine( &clipbox, x1, y1, x2, y2 ) )
            return;
    }

    GRSetColorPen( DC, Color, width );
    DC->DrawLine( x1, y1, x2, y2 );
}
Пример #13
0
//Implementation of the Cohen-Sutherland clipping algorithm.
ClipResult clipLine(float x0, float y0, float x1, float y1,
					float xMin, float yMin, float xMax, float yMax){
	ClipResult result;

	int startCode = getOutCode(x0, y0, xMin, yMin, xMax, yMax);
	int endCode   = getOutCode(x1, y1, xMin, yMin, xMax, yMax);

	//Line is entirely within the clipping window.
	if((startCode | endCode) == 0){
		return ClipResult(x0, y0, x1, y1, false);
	}

	//Line does not cross the clipping window, remove it.
	if(startCode & endCode)
		return ClipResult(x0, y0, x1, y1, true);

	int clipCode = startCode ? startCode : endCode;
	float xClip = 0;
	float yClip = 0;

	if(clipCode & Math::UP_OUTCODE){ // Get x intersection with window's top border.
		xClip = x0 + ((yMin - y0) / (y1 - y0)) * (x1 - x0);
		yClip = yMin;
	} else if(clipCode & Math::DOWN_OUTCODE){ // Get x intersection with window's bottom border.
		xClip = x0 + ((yMax - y0) / (y1 - y0)) * (x1 - x0);
		yClip = yMax;
	} else if(clipCode & Math::LEFT_OUTCODE){ // Get y intersection with window's left border.
		xClip = xMin;
		yClip = y0 + ((xMin - x0) / (x1 - x0)) * (y1 - y0);
	} else if(clipCode & Math::RIGHT_OUTCODE){ // Get y intersection with window's right border.
		xClip = xMax;
		yClip = y0 + ((xMax - x0) / (x1 - x0)) * (y1 - y0);
	}

	// Update coordinates of the result.
	if(clipCode == startCode){
		x0 = xClip;
		y0 = yClip;
	} else {
		x1 = xClip;
		y1 = yClip;
	}

	// Recursive, but maximum of two calls (if in a corner region), so little overhead.
	return clipLine(x0, y0, x1, y1, xMin, yMin, xMax, yMax);
};
Пример #14
0
void
pamd_line(tuple **      const tuples, 
          int           const cols, 
          int           const rows, 
          int           const depth, 
          sample        const maxval, 
          pamd_point    const p0,
          pamd_point    const p1,
          pamd_drawproc       drawProc,
          const void *  const clientdata) {

    pamd_point c0, c1;
    bool noLine;  /* There's no line left after clipping */

    pamd_validateCoord(cols);
    pamd_validateCoord(rows);
    pamd_validatePoint(p0);
    pamd_validatePoint(p1);

    if (lineclip) {
        clipLine(p0, p1, cols, rows, &c0, &c1, &noLine);
    } else {
        c0 = p0;
        c1 = p1;
        noLine = FALSE;
    }

    if (noLine) {
        /* Nothing to draw */
    } else if (pointsEqual(c0, c1)) {
        /* This line is just a point.  Because there aren't two
           distinct endpoints, we have a special case.
        */
        drawPoint(drawProc, clientdata, tuples, cols, rows, depth, maxval, c0);
    } else {
        /* Draw, using a simple DDA. */
        if (abs(c1.x - c0.x) > abs(c1.y - c0.y))
            drawShallowLine(drawProc, clientdata, tuples, cols, rows,
                            depth, maxval, c0, c1);
        else
            drawSteepLine(drawProc, clientdata, tuples, cols, rows,
                          depth, maxval, c0, c1);
    }
}
Пример #15
0
void plotLinesToPainter(QPainter& painter,
			const Numpy1DObj& x1, const Numpy1DObj& y1,
			const Numpy1DObj& x2, const Numpy1DObj& y2,
			const QRectF* clip, bool autoexpand)
{
  const int maxsize = min(x1.dim, x2.dim, y1.dim, y2.dim);

  // if autoexpand, expand rectangle by line width
  QRectF clipcopy;
  if ( clip != 0 && autoexpand )
    {
      const qreal lw = painter.pen().widthF();
      qreal x1, y1, x2, y2;
      clip->getCoords(&x1, &y1, &x2, &y2);
      clipcopy.setCoords(x1, y1, x2, y2);
      clipcopy.adjust(-lw, -lw, lw, lw);
    }

  if( maxsize != 0 )
    {
      QVector<QLineF> lines;
      for(int i = 0; i < maxsize; ++i)
	{
	  QPointF pt1(x1(i), y1(i));
	  QPointF pt2(x2(i), y2(i));
	  if( clip != 0 )
	    {
	      if( clipLine(clipcopy, pt1, pt2) )
		lines << QLineF(pt1, pt2);
	    }
	  else
	    lines << QLineF(pt1, pt2);
	}

      painter.drawLines(lines);
    }
}
Пример #16
0
void Viewer::paintGL() {
  draw_init();

  auto viewM = viewPoint.getViewMatrix();
  auto perspectiveM = perspectiveMatrix();

  // Norms of clipping planes
  Vector3D nearNorm = {0, 0, 1};
  Vector3D farNorm = {0, 0, -1};
  Vector3D leftNorm = {1, 0, 0};
  Vector3D rightNorm = {-1, 0, 0};
  Vector3D topNorm = {0, -1, 0};
  Vector3D bottomNorm = {0, 1, 0};

  // Points on clipping planes
  Point3D nearPoint = {0, 0, near};
  Point3D farPoint = {0, 0, far};
  Point3D leftPoint = {-1, 0, 0};
  Point3D rightPoint = {1, 0, 0};
  Point3D topPoint = {0, 1, 0};
  Point3D bottomPoint = {0, -1, 0};

  // Convert vp1 and vp2 into points in range [-1, 1]
  Point2D vp1, vp2;
  getAdjustedViewportBounds(&vp1, &vp2);

  int idx = 0;
  for (const auto& model : {boxModel, boxGnomon, worldGnomon}) {
    idx += 1;
    auto v = model.getLines();

    int jdx = -1;
    for (auto& line : v) {
      jdx += 1;
      // Last minute colour additions lol
      if (idx == 1) {
        if (jdx < 4) {
          set_colour(QColor(0.0, 1.0, 1.0));
        }
        else {
          set_colour(QColor(1.0, 1.0, 1.0));
        }
      }
      else if (idx == 2) {
        // Draw box gnomon as some kind of red
        set_colour(QColor(1.0, 1.0, 0.0));
      }
      else {
        // Draw world gnomon in fancy colours
        set_colour(QColor(jdx == 0 ? 1.0 : 0.0,
                          jdx == 1 ? 1.0 : 0.0,
                          jdx == 2 ? 1.0 : 0.0));
      }
      // Now we have the view coordinates
      line.start = viewM * line.start;
      line.end = viewM * line.end;

      // Now we want to clip the line to the near and far planes first, to
      // avoid ambiguity. (Actually, we only need to do the near one, but
      // far is the same so why not do that too) :)
      if (!clipLine(&line, nearNorm, nearPoint) ||
          !clipLine(&line, farNorm, farPoint)) {
        continue;
      }

      // We need these because our vectors are 3D not 4D...
      auto startZ = line.start[2];
      auto endZ = line.end[2];

      // Now multiply to project it onto the near plane
      line.start = perspectiveM * line.start;
      line.end = perspectiveM * line.end;

      // We no longer care about depth
      // TODO: Convert to 2D
      for (int i = 0; i < 3; ++i) {
        line.start[i] /= startZ;
        line.end[i] /= endZ;
      }

      // We can clip these afterwards (in 2D, since we don't care about depth)
      // TODO: 2D
      if (!clipLine(&line, rightNorm, rightPoint) ||
          !clipLine(&line, leftNorm, leftPoint) ||
          !clipLine(&line, topNorm, topPoint) ||
          !clipLine(&line, bottomNorm, bottomPoint)) {
        continue;
      }

      const Line2D windowLine = {
        {line.start[0], line.start[1]},
        {line.end[0], line.end[1]}
      };

      const Line2D viewportLine = {
        adjustForViewport(windowLine.start, vp1, vp2),
        adjustForViewport(windowLine.end, vp1, vp2)
      };

      draw_line(viewportLine.start, viewportLine.end);
    }
  }

  // Finally, draw viewport lines
  set_colour(QColor(0.0, 0.0, 0.0));
  draw_line(vp1, {vp1[0], vp2[1]});
  draw_line(vp1, {vp2[0], vp1[1]});
  draw_line({vp1[0], vp2[1]}, vp2);
  draw_line({vp2[0], vp1[1]}, vp2);
}
Пример #17
0
void timelineWidget::paintEvent( QPaintEvent * )
    {
    if( jLib::math::fcmp( timeInView( ), 0 ) )
        {
        if( endTime() != jLib::floatLimits::infinity() &&
             beginTime() != jLib::floatLimits::infinity() )
            {
            timeInView( endTime() - beginTime() );
            viewCentre( ( endTime() + beginTime() ) / 2 );
            }
        else
            {
            timeInView( 10 );
            viewCentre( 5 );
            }
        }

    QPainter painter(this);
    painter.setRenderHint( QPainter::Antialiasing, TRUE );

    if( timeInView() > ( endTime( ) - beginTime( ) ) )
        {
        timeInView( endTime( ) - beginTime( ) );
        }

    JFLOAT realBeginDrawing = viewCentre() - ( timeInView()/2 );
    JFLOAT realEndDrawing = viewCentre() + ( timeInView()/2 );

    if( realEndDrawing > endTime() )
        {
        realEndDrawing = endTime( );
        realBeginDrawing = endTime( ) - timeInView( );
        viewCentre( endTime( ) - ( timeInView()/2 ) );
        }
    if( realBeginDrawing < beginTime() )
        {
        realBeginDrawing = beginTime( );
        realEndDrawing = beginTime( ) + timeInView( );
        viewCentre( beginTime( ) + ( timeInView()/2 ) );
        }

    JFLOAT timeSpikeIntervals[] = { 0.125, 0.25, 0.5, 1, 1.25, 2.5, 5, 10, 50 };

    JFLOAT timeSpikeInterval = jLib::floatLimits::nan();

    JFLOAT minDist = jLib::floatLimits::infinity();
    for( int x=0; x<9; x++ )
        {
        JFLOAT size = timeToPixel( timeSpikeIntervals[x], 0, ( realEndDrawing - realBeginDrawing ), width() );

        if( ( size - 50.0 ) < minDist )
            {
            timeSpikeInterval = timeSpikeIntervals[x];
            minDist = size;
            }
        }

    if( timeSpikeInterval != timeSpikeInterval )
        {
        timeSpikeInterval = 1.0;
        }

    JFLOAT beginDrawing = realBeginDrawing - fmod( realBeginDrawing, timeSpikeInterval ) - 1;
    JFLOAT endDrawing = realEndDrawing + ( timeSpikeInterval - fmod( realEndDrawing, timeSpikeInterval ) );

    painter.setPen( QApplication::palette().color( QPalette::Text ) );
    for( JFLOAT x=( beginDrawing - timeSpikeInterval ); x<=endDrawing; x+=timeSpikeInterval )
        {
        JFLOAT actualTime = x + 1;
        JFLOAT xMidPos = timeToPixel( actualTime + ( 0.5 * timeSpikeInterval ), realBeginDrawing, realEndDrawing, width() );
        painter.drawLine( QPointF( xMidPos, height() ), QPointF( xMidPos, height() - minorTimeHeight() ) );

        JFLOAT xPos = timeToPixel( actualTime, realBeginDrawing, realEndDrawing, width() );

        painter.drawText( (int)(xPos+2), (int)(height() - majorTimeHeight()-5), formatTime( actualTime ) );
        painter.drawLine( QPointF( xPos, height() ), QPointF( xPos, height() - majorTimeHeight() ) );
        }

    QColor clipColourA( QApplication::palette().color( QPalette::Shadow ) );
    clipColourA.setAlpha( 200 );
    QColor clipColourB( QApplication::palette().color( QPalette::Shadow ) );
    clipColourB.setAlpha(100 );
    QLinearGradient clipGrad( 0, 0, 0, height() );
    clipGrad.setColorAt( 0.0, clipColourA );
    clipGrad.setColorAt( 1.0, clipColourB );

    QPen clipLine( QApplication::palette().color( QPalette::Shadow ) );
    clipLine.setWidthF( 1.5 );
    if( clipBegin() > realBeginDrawing )
        {
        JFLOAT clipBeginPix = timeToPixel( clipBegin(), realBeginDrawing, realEndDrawing, width() );
        painter.setPen( Qt::transparent );
        painter.setBrush( clipGrad );
        painter.drawRect( 0, 0, (int)clipBeginPix, (int)height() );
        painter.setPen( clipLine );
        painter.drawLine( (int)(clipBeginPix+1), 0, (int)(clipBeginPix+1), height() );
        }

    if( clipEnd() < realEndDrawing )
        {
        JFLOAT clipEndPix = timeToPixel( clipEnd(), realBeginDrawing, realEndDrawing, width() );
        if( clipEndPix < 0 )
            {
            clipEndPix = 0;
            }
        painter.setPen( Qt::transparent );
        painter.setBrush( clipGrad );
        painter.drawRect( (int)clipEndPix, 0, width(), height() );
        painter.setPen( clipLine );
        painter.drawLine( (int)clipEndPix, 0, (int)clipEndPix, height() );
        }


    JFLOAT now = timeToPixel( currentTime(), realBeginDrawing, realEndDrawing, width() );
    QColor nowColour = QApplication::palette().color( QPalette::Highlight );
    nowColour.setAlpha( 200 );

    QPen nowPen( nowColour );
    nowPen.setWidthF( 2.5 );
    painter.setPen( nowPen );

    painter.drawLine( QPointF( now, 0 ), QPointF( now, height() ) );
    painter.setPen( QApplication::palette().color( QPalette::Text ) );
    painter.drawText( (int)(now+2), (int)(height() - majorTimeHeight()-20), formatTime( currentTime() ) );

    nowColour.setAlpha( 150 );
    QLinearGradient highlight( now, 0, now-_nowGradientSpread, 0 );
    highlight.setColorAt(0, nowColour );
    highlight.setColorAt(1, Qt::transparent );
    painter.fillRect( QRectF( now-_nowGradientSpread, 0, _nowGradientSpread, height() ), highlight );
    }
void WireframeTriangleRasterizer::drawLine(const math::vertex &p1, const math::vertex &p2, FrameBuffer *fb)
{
    math::vec3 pc1(p1.p), pc2(p2.p);

    int cols = fb->width();

    if (clipLine(pc1, pc2, fb))
    {
        int error;
        int x0 = pc1.x, x1 = pc2.x;
        int y0 = pc1.y, y1 = pc2.y;
        int pixNum;

        pixNum = y0 * cols + x0;

        int dx = x1 - x0;
        int dy = y1 - y0;

        int xInc, yInc;
        if (dx >= 0)
            xInc = 1;
        else
        {
            xInc = -1;
            dx = -dx;
        }

        if (dy >= 0)
            yInc = cols;
        else
        {
            yInc = -cols;
            dy = -dy;
        }

        int dx2 = dx * 2;
        int dy2 = dy * 2;

        if (dx > dy)
        {
            error = dy2 - dx;

            for (int index = 0; index <= dx; index++)
            {
                fb->wpixel(pixNum, p1.color);

                if (error >= 0)
                {
                    error -= dx2;
                    pixNum += yInc;
                }

                error += dy2;
                pixNum += xInc;
            }
        }
        else
        {
            error = dx2 - dy;

            for (int index = 0; index <= dy; index++)
            {
                fb->wpixel(pixNum, p1.color);

                if (error >= 0)
                {
                    error -= dy2;
                    pixNum += xInc;
                }

                error += dx2;
                pixNum += yInc;
            }
        }
    }
}
Пример #19
0
void drawLine(float *img, /* pointer to start of image region to draw to */
		int w, int h, int bands, /* with height, and bands of region */
		int pitch, /* distance between rows in image */
		int x, int y, int dx, int dy,
		float *rgb)
{
	float *p;
	int xinc, yinc;
	int i;
	int j;
	int error;
	int ret;

	/* do line clipping */
	if (x<0 || x>=w || x+dx<0 || x+dx>=w
	    || y<0 || y>=h || y+dy<0 || y+dy>=h)
	{
		ret=clipLine(&x,&y,&dx,&dy,w,h);
		if (ret==ALL_OUTSIDE) return;
	}

	p=&img[pitch*y+bands*x];

	if (dx>=0) xinc=bands;
	else 
	{
		xinc=-bands;
		dx=-dx;
	}

	if (dy>=0) yinc=pitch;
	else
	{
		yinc=-pitch;
		dy=-dy;
	}

	error=0;

	if (dx>dy)
	{
		for (i=0;i<=dx;i++)
		{
			for (j=0;j<bands;j++) p[j]=rgb[j];
			error+=dy;

			if (error>dx)
			{
				error-=dx;
				p+=yinc;
			}
			
			p+=xinc;
		}
	}
	else
	{
		for (i=0;i<=dy;i++)
		{
			for (j=0;j<bands;j++) p[j]=rgb[j];
			error+=dx;
			if (error>=dy)
			{
				error-=dy;
				p+=xinc;
			}
			p+=yinc;
		}
	}
	return;
}