Canvas* texture;
This is a pointer to another Canvas object, used for texture mapping. You also have to initialized it to 0 in the constructor.
// the row(column) number is normalized float value. RGB& Pixel(float normalized_row, float normalized_col);
When you implement this function, you should use Pixel(int, int) with the help of round(). You do the following steps to convert a normalized_row number to the actual row number (the same holds for column)
Set the texture data member of this Canvas to some other Canvas object, which is supposed to be the image to be texture mapped onto this Canvas.
We are going to use the same ScanLineSegment() function to do texture mapping, only now regarding the color arguments as texture coordinates (ignoring the blue component of the color).
void Canvas :: scanLineSegment(int x1, int y1, RGB const col1, int x2, int y2, RGB const col2, set<ScannedResult>* output)
Original inside scanLineSegment() we assign an interpolated color directly to the scanned pixel.
Pixel(Y + vReso/2, X + hReso/2) = col;
Now we are not doing that, since the color should be from the other Canvas object pointed by data member texture. We can do this simply by calling the new added member function, Pixel(float, float).
Pixel(Y + vReso/2, X + hReso/2) = texture->Pixel(col[1], col[0]);
If four texture coordinates are, in counter clockwise order, (0, 0), (1, 0), (1, 1), (0, 1), then the entire texture image is mapped onto the quad.
If instead, for example, they are (0, 0), (.25, 0), (.25, .25), (0, .25), then the lower left quarter of the texture image is mapped onto the the quad.
Continue our example above. If now, for example, the four coordinates are (0, 0), (3, 0), (3, 3), (0, 3), then the quad will be covered by a 3 by 3 arrays of the same texture image.
const float radius = 200; const int a_reso = 40; const int r_reso = 40; float r_step = radius / r_reso, r1 = 0, r2 = r_step; for(int r=0; r<r_reso; r++) { float a_step = 2 * pi / a_reso, a1 = 0, a2 = a_step; for(int a=0; a<a_reso; a++) { int x1 = round(r1 * cos(a1)), y1 = round(r1 * sin(a1)), x2 = round(r1 * cos(a2)), y2 = round(r1 * sin(a2)), x3 = round(r2 * cos(a1)), y3 = round(r2 * sin(a1)), x4 = round(r2 * cos(a2)), y4 = round(r2 * sin(a2)); canvas.FillTriangle(x1, y1, RGB(r1/radius,a1/(2*pi)), x2, y2, RGB(r1/radius,a2/(2*pi)), x4, y4, RGB(r2/radius,a2/(2*pi))); canvas.FillTriangle(x1, y1, RGB(r1/radius,a1/(2*pi)), x3, y3, RGB(r2/radius,a1/(2*pi)), x4, y4, RGB(r2/radius,a2/(2*pi))); a1 = a2; if(a == a_reso - 1) a2 = 0; else a2 += a_step; } r1 = r2; if(r == r_reso - 1) r2 = radius; else r2 += r_step; }
1.3.6