Пример #1
0
void FrameBuffer::Draw2DBigPoint(int u0, int v0, int psize, const V3 &color, float z) {
	for (int v = v0-psize/2; v <= v0+psize/2; v++) {
		for (int u = u0-psize/2; u <= u0+psize/2; u++) {
			SetGuarded(u, v, color.GetColor(), z);
		}
	}
}
//d. Draw 2-D segment with color interpolation
void FrameBuffer::Draw2DSegment(V3 p0, V3 c0, V3 p1, V3 c1) 
{
  float dx = fabsf(p0[0]-p1[0]);
  float dy = fabsf(p0[1]-p1[1]);
  int n;
  if (dx < dy)
	n = 1+(int)dy;
  else
	n = 1+(int)dx;

  for (int i = 0; i < n; i++) {
	float frac = (float) i / (float) (n-1);
	V3 curr = p0 + (p1-p0)*frac;
	V3 currc = c0 + (c1-c0)*frac;
	int u = (int) curr[0];
	int v = (int) curr[1];
	SetGuarded(u, v, currc.GetColor());
  }
}
void FrameBuffer::Draw2DBigPoint(V3 pp, int psize, V3 color) 
{
  int u0 = (int) pp[0];
  int v0 = (int) pp[1];
  for (int v = v0-psize/2; v <= v0+psize/2; v++) {
	if (v < 0 || v > h-1)
	  continue;
	for (int u = u0-psize/2; u <= u0+psize/2; u++) {
	  if (u < 0 || u > w-1)
		continue;
	  int uv = (h-1-v)*w+u;
	  if (zb[uv] > pp[2])
		continue;
	  zb[uv] = pp[2];
	  Set(u, v, color.GetColor());
	}
  }

}
Пример #4
0
/**
 * Draw 2D segment with color interpolation.
 *
 * @param p0	the first point of the segment
 * @param c0	the color of the first point
 * @param p1	the second point of the segment
 * @param c1	the color of the second point
 */
void FrameBuffer::Draw2DSegment(const V3 &p0, const V3 &c0, const V3 &p1, const V3 &c1) {
	float dx = fabsf(p0.x() - p1.x());
	float dy = fabsf(p0.y() - p1.y());

	int n;
	if (dx < dy) {
		n = 1 + (int)dy;
	} else {
		n = 1 + (int)dx;
	}

	for (int i = 0; i <= n; i++) {
		float frac = (float) i / (float)n;
		V3 curr = p0 + (p1-p0) * frac;
		V3 currc = c0 + (c1-c0) * frac;
		int u = (int)curr[0];
		int v = (int)curr[1];
		SetGuarded(u, v, currc.GetColor(), curr[2]);
	}
}