如何将x,y,z,sizeX,sizeY,sizeZ值放到顶点以制作立方体?
public static void cube(float x, float y, float z, float sx, float sy, float sz){
glPushMatrix();
{
glTranslatef(x, y, z);
//Just one side of the cube is given due to too much unnecessary code.
glBegin(GL_QUADS);
glVertex3f(-1, -1, 1);
glVertex3f(1, -1, 1);
glVertex3f(1, 1, 1);
glVertex3f(-1, 1, 1);
glEnd();
}
glPopMatrix();
}
感谢。
答案 0 :(得分:0)
您的代码中的任何地方,例如glVertex3f(-1, -1, 1);
多次将它们与sx,sy,sz的相应值除以2,例如glVertex3f(-sx/2, -sy/2, sz/2);
对于该位置,您可以在绘制多维数据集之前发出glTranslatef(x, y, z)
。如果您坚持将其硬编码到顶点中,那么您应该将上述语句写为glVertex3f(x - sx/2, y - sy/2, z + sz/2);