如何在opengl中随机创建1000个对象(例如立方体,球体,圆柱体)?

时间:2014-06-23 14:05:55

标签: opengl random

我创造了一个房间。这是我在会议室的代码:

    void room(){
    glColor3f(1.0, 1.0 ,0.0);  
    glNormal3f(0,1,0);
    glVertex3f( 500 ,-3.0, 500); 
    glVertex3f(-500 ,-3.0, 500); 
    glVertex3f(-500 ,-3.0,-500); 
    glVertex3f( 500 ,-3.0,-500); 
}

现在我想在地板上随机生成很多物体,如立方体,球体,圆柱体。你能帮我吗?怎么做?

1 个答案:

答案 0 :(得分:3)

质量问题需要质量响应

for (int i = 0; i < 50000; i++) {
  glPushMatrix();
  glTranslatef(-500 + rand() % 1000, 7 + rand() % 100, -500 + rand() % 1000);
  glutSolidTeapot(10);
  glPopMatrix();
}

或者可能没有过剩

GLUquadric* q = gluNewQuadric();
for (int i = 0; i < 50000; i++) {
  glPushMatrix();
  glTranslatef(-500 + rand() % 1000, 7 + rand() % 100, -500 + rand() % 1000);
  gluSphere(q, 10, 10, 10);
  glPopMatrix();
}
gluDeleteQuadric(q);