QT5-三维

//三维
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	
	glTranslatef(-1.5, 0.0, -6.0);
	glRotatef(rTri, 0.0, 1.0, 0.0);
	glBegin(GL_TRIANGLES);


	//前侧面
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(0.0, 1.0, 0.0);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(-1.0, -1.0, 1.0);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(1.0, -1.0, 1.0);


	//右侧面
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(0.0, 1.0, 0.0);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(1.0, -1.0, 1.0);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(1.0, -1.0, -1.0);


	//后侧面
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(0.0, 1.0, 0.0);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(1.0, -1.0, -1.0);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(-1.0, -1.0, -1.0);


	//左侧面
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(0.0, 1.0, 0.0);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(-1.0, -1.0, -1.0);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(-1.0, -1.0, 1.0);
	glEnd();


	rTri += 1.2;


	//底面
	glBegin(GL_QUADS);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(1.0, -1.0, 1.0);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(1.0, -1.0, -1.0);
	glColor3f(0.0, 0.0, 1.0);
	glVertex3f(-1.0, -1.0, -1.0);
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(-1.0, -1.0, 1.0);
	glEnd();


	//立方体


	glLoadIdentity();
	glTranslatef(1.5, 0.0, -7.0);
	glRotatef(rQuad,1.0,1.0,1.0);


#define f1 1.0, 1.0, 1.0
#define f2 -1.0, 1.0, 1.0
#define f3 -1.0, -1.0, 1.0
#define f4 1.0, -1.0, 1.0


#define b1 -1.0, 1.0, -1.0
#define b2 1.0, 1.0, -1.0
#define b3 1.0, -1.0, -1.0
#define b4 -1.0, -1.0, -1.0
	
	glBegin(GL_QUADS);


	//正侧面
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(f1);
	glVertex3f(f2);
	glVertex3f(f3);
	glVertex3f(f4);




	void setpoint(int o1, int p1, int q1,
		int o2, int p2, int q2,
		int o3, int p3, int q3,
		int o4, int p4, int q4);
	//右侧面
	glColor3f(1.0,0.5, 0.0);
	setpoint(b2, f1, f4, b3);//其实就是按顺序glVertex3f()四个点



	//后侧面
	glColor3f(0.0, 1.0, 1.0);
	setpoint(b1, b2, b3, b4);


	//左侧面
	glColor3f(0.0, 0.5, 1.0);
	setpoint(f2, b1, b4, f3);


	//上底面面
	glColor3f(0.0, 0.0, 1.0);
	setpoint(b2, b1, f2, f1);


	//下底面
	glColor3f(0.0, 1.0, 0.0);
	setpoint(b4, b3, f4, f3);
	glEnd();


	rQuad -= 1.0;


还是修改paintGL()三维就是把立方体的几个面都画出来,画面的时候注意逆时针开始画(画的顺序要一致),面的连接点要注意一致


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值