1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
/**
* Render the interpolated points and the edges between them
* for each stage of the de casteljau algorithm. Colour each final
* point (the points on the curve) differently.
*/
void GLWidget::drawDeCasteljau(float t) {
Point p;
int N_PTS = 4;
p.x = pow((1-t),3)*vertices[0].x+3* t * pow((1 -t), 2) * vertices[1].x + 3 * (1-t)*pow(t,2)*vertices[2].x+ pow (t, 3)*vertices[3].x;
p.y = pow((1-t),3)*vertices[0].y+3* t * pow((1 -t), 2) * vertices[1].y + 3 * (1-t)*pow(t,2)*vertices[2].y+ pow (t, 3)*vertices[3].y;
p.z = pow((1-t),3)*vertices[0].z+3* t * pow((1 -t), 2) * vertices[1].z + 3 * (1-t)*pow(t,2)*vertices[2].z+ pow (t, 3)*vertices[3].z;
int bezPoints[3][3] ;
for (float u = 0.0; u <= 1.0; u += t) {
for (int diag = N_PTS-2; diag >= 0; diag--) {
for (int i = 0; i <= diag; i++) {
int j = diag - i;
bezPoints[i][j] = (1.0-u)*bezPoints[i][j+1] + u*bezPoints[i+1][j];
}
}
// set the pixel for this parameter value
//Set pixel method for theImage object.
// void setPixel(Index row, Index col, Byte red, Byte green, Byte blue, Byte alpha=255);
// void setPixel(Index row, Index col, RGBValue colour, Byte alpha = 255);
theImage.setPixel(bezPoints[0][0], bezPoints[0][0], RGBValue());
}
}
void GLWidget::drawBezierCurve() {
}
|