我想将锥体放在球体的表面上,如:
我的尝试看起来像:
// black sphere
initMaterials2();
drawSphere(0.8);
// red cones
int n = 6;
initMaterials();
double angleIncrement = 360/n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
glPushMatrix();
glRotatef(angleIncrement * i, 1, 0, 0);
glRotatef(angleIncrement * j, 0, 0, 1);
glTranslatef(0, 0.7, 0);
drawCone(0.15, 0.6);
glPopMatrix();
}
}
正如你所看到的,一堆锥体聚集在一侧...我认为我的旋转计算是错误的...我该如何解决?
答案 0 :(得分:2)
看起来我需要改变循环的顺序
int n = 3;
initMaterials();
double angleIncrement = 180/n;
for (int i = 0; i < n; i++) {
glPushMatrix();
glRotatef(angleIncrement * i, 0, 1, 0);
for (double angle = 0; angle < 360; angle += 45) {
glPushMatrix();
glRotatef(angle, 1, 0, 0);
glTranslatef(0, 0.7, 0);
drawCone(0.15, 0.6);
glPopMatrix();
}
glPopMatrix();
}