4

起初我有一个像这样的简单的白色矩形棱镜:

在此处输入图像描述

这是代码:

 glBegin(GL_QUADS);               

      glColor3f(255,255,255);    
      glVertex3f( 0.3, 0, 2.5);//sisi bawah
      glVertex3f(0.5, 0, 2.5);
      glVertex3f(0.5, 0,  2.6);
      glVertex3f( 0.3, 0,  2.6);

      glVertex3f(0.5, 0,  2.6);//sisi kiri
      glVertex3f( 0.3, 0,  2.6);
      glVertex3f( 0.3, 1.5,  2.6);
      glVertex3f(0.5, 1.5,  2.6);

      glVertex3f(0.5, 0, 2.5);//sisi depan
      glVertex3f(0.5, 0,  2.6);
      glVertex3f(0.5, 1.5,  2.6);
      glVertex3f(0.5, 1.5,  2.5);

      glVertex3f( 0.3, 0, 2.5);//sisi belakang
      glVertex3f( 0.3, 0,  2.6);
      glVertex3f( 0.3, 1.5,  2.6);
      glVertex3f( 0.3, 1.5, 2.5);

      glVertex3f( 0.3, 1.5, 2.5);//sisi atas
      glVertex3f(0.5, 1.5, 2.5);
      glVertex3f(0.5, 1.5,  2.6);
      glVertex3f( 0.3, 1.5,  2.6);

      glVertex3f(0.5, 0,  2.5);//sisi kanan
      glVertex3f( 0.3, 0,  2.5);
      glVertex3f( 0.3, 1.5,  2.5);
      glVertex3f(0.5, 1.5,  2.5);

glEnd();

然后,我想画另一个像这样的矩形棱柱:

在此处输入图像描述

我可以只使用重绘另一个棱镜,glTranslate这样我就不必手动插入数字了吗?

4

1 回答 1

6

是的,创建一个函数来调用绘制命令绘制关于其模型坐标的棱镜,drawPrism。然后在代码中你可以这样做:

//draw prism 1
glPushMatrix();
glTranslate(x1, y1, z1);
drawPrism();
glPopMatrix();

//draw prism 2
glPushMatrix();
glTranslate(x2, y2, z2);
drawPrism();
glPopMatrix();
于 2013-10-16T16:25:16.517 回答