2013-01-12 304 views
2

下面的代碼爲我繪製了一個三維球體對象的圓,在x和z座標平面中。在C++中繪製圓圈

double radiusCircle =0.5; 
double i; 
double j; 

for(i = 0.0f;i<6.0f;i+=0.2f){ 
    sphere1 = new Sphere; 
    sphere1->position.x = radiusCircle *cos(i * (2.0 * 3.14) /6)+4; 
    sphere1->position.z = radiusCircle *sin(i * (2.0 * 3.14)/6)+2; 
} 

我想將它們堆疊在y軸上,但不能正確地做。我想知道是否有人可以幫助我做到這一點。

基本上,我想要上面的代碼將30 sphere1畫成一個圓圈,但我也想讓它高4。

+0

有兩種方法可以繪製一個球體的一部分。你想要縱向繪圖還是橫向繪圖?或兩者? – user1118321

回答

0
double radiusCircle =0.5; 
double i; 
double j; 


for (y = 0; y < 4; y++) { 
    for(i = 0.0f;i<6.0f;i+=0.2f){ 
     sphere1 = new Sphere; 
     sphere1->position.x = radiusCircle *cos(i * (2.0 * 3.14) /6)+4; 
     sphere1->position.z = radiusCircle *sin(i * (2.0 * 3.14)/6)+2; 
     sphere1->position.y = sphere1.radius * 2 * y; // <-- assign position.y to the sphere height 
    } 
}