拼接成象形动物

要求:给定三维图元(立方体,四面体和球),把图元拼接成象形动物;

            要求图元必须按照层级组织;

实现:创建二次几何体,对于每一次变换,建立数据结构存取图元(glPushMatrix()和glPopMatrix();)。

          Just translate, rotate, andscale each one to get the right size, shape, position, and  orientation.

Transformation Hierarchies:   

                                                      

Transformations apply to everything under them—start at the bottom and work your way up.

example:(左手)

	//左手
	glColor3f(1.0, 1.0, 1.0);
	glPushMatrix();
	gluQuadricDrawStyle(quadratic, GLU_SMOOTH);
	glTranslatef(0.5, 0.3, 0.3);
	glRotatef((GLfloat)shoulder2 + 90, 1.0, 1.0, 0.0);
	gluCylinder(quadratic, 0.05, 0.05, 0.5, 20.0, 8.0);
	glPushMatrix();
	glColor3f(0.3, 1.0, 1.0);
	glTranslatef(0.0, 0.0, 0.5);
	//左手轴
	glRotatef((GLfloat)elbow + 90, 0.0, 1.0, 0.0);
	//glTranslatef(0.5, 0.0, 0.0);
	gluCylinder(quadratic, 0.05, 0.05, 0.5, 20.0, 8.0);
	glPopMatrix();
	glPopMatrix();
	glColor3f(1.0, 1.0, 1.0);
	glPushMatrix();
	gluQuadricDrawStyle(quadratic, GLU_SMOOTH);
	glTranslatef(-0.5, 0.3, 0.3);
	glRotatef((GLfloat)shoulder1 - 20, 0.0, 1.0, 1.0);
	gluCylinder(quadratic, 0.05, 0.05, 1.0, 20.0, 8.0);
	glPopMatrix();

添加键盘监听

void keyboard(unsigned char key, int x, int y)
{
	switch (key) {
	case'b':
		shoulder1 = (shoulder1 +5) % 360;
		glutPostRedisplay();
		break;
	case'v':
		shoulder2 = (shoulder2 + 5) % 360;
		glutPostRedisplay();
		break;
	case'm':
		leg1 = (leg1 + 5) % 360;
		glutPostRedisplay();
		break;
	case'n':
		leg2= (leg2 +5) % 360;
		glutPostRedisplay();
		break;
	case'c':
		elbow  = (elbow+ 5) % 360;
		glutPostRedisplay();
		break;
	default:
		break;

	}
}
输出:

                  

键盘转动之后:

                   
    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值