1.绘制目标
Bézier 曲面建模及显示
‘x’:绕x轴旋转
‘y’:绕y轴旋转
‘z’:绕z轴旋转
‘r’:复原
2.核心代码
// Begin globals.
// Initial control points.
static float controlPoints[6][4][3] =
{
TODO: set the values of the control points here
{{-3.0, -2.0, 5.0}, {-0.25, 2.0, 5.0}, {0.25, 3.0, 5.0}, {3.0, 4.0, 5.0}}, {{-3.0, -1.0, 3.0}, {-0.25, 3.0, 3.0}, {0.25, 4.0, 3.0}, {3.0, 3.5, 3.0}},
{{-3.0, 0.0, 1.0}, {-0.25, -1.0, 1.0}, {0.25, 0.0, 5.0}, {3.0, 2.0, 5.0}}, {{-3.0, -1.5, -1.0}, {-0.25, -0.8, -1.0}, {0.25, 0.5, -1.0}, {3.0, 1.5, -1.0}},
{{-3.0, -0.5, -3.0}, {-0.25, 0.0, -3.0}, {0.25, 1.0, -3.0}, {3.0, -0.2, -3.0}}, {{-3.0, -0.8, -5.0}, {-0.25, -1.0, -5.0}, {0.25, -0.5, -5.0}, {3.0, 2.0, -5.0}}
};
// Initialization routine.
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glEnable(GL_DEPTH_TEST);
TODO: Specify and enable the Bezier surface.
glMap2f(GL_MAP2_VERTEX_3, 0, 1, 12, 6, 0, 1, 3, 4, &controlPoints[0][0][0]);
glEnable(GL_MAP2_VERTEX_3);
}
TODO: Specify the virtual camera here
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
///
/ TODO: Draw the Bezier surface using a mesh approximation.
glMapGrid2f(24, 0.0, 1.0, 24, 0.0, 1.0);
glEvalMesh2(GL_LINE, 0, 24, 0, 24);
///
TODO: Specify the perspective projection here. /
gluPerspective(80.0, float(w) / float(h), 1.0, 20.0);
///
case 'x':
TODO: Update the Xangle here.
Xangle += 1.0f;
glutPostRedisplay();
break;
case 'y':
TODO: Update the Yangle here.
Yangle += 1.0f;
glutPostRedisplay();
break;
case 'z':
TODO: Update the Zangle here.
Zangle += 1.0f;
break;
case 'r':
TODO: Reset the X,Y, Z angle here.
Xangle = 30.0;
Yangle = 0.0;
Zangle = 0.0;
glutPostRedisplay();
break;
3.运行结果