【图形学】Bézier 曲面建模及显示

【图形学】Bézier 曲面建模及显示

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.运行结果

在这里插入图片描述
在这里插入图片描述

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

敲代码两年半的练习生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值