0
請問先生,你能告訴我怎樣才能糾正這個代碼 這個想法是消除我的球體中的交點,因爲它使我的數字不清晰 這裏是我的代碼的一方 我這是怎麼保存的座標如何消除兩個球體之間的點相交
int nombre=0;
for (int i = 0; i < size; i++)
{
Sphere *s = &sphereTree.nodes.index(sphNum);//this is a sphere
Point rt(s->c.x, s->c.y, s->c.z);//this is the center
Vpoint.push_back(rt);//I saved centers here
Vrayon.push_back(s->r);//I saved radiu of spheres
std::vector<Point> pp;
pp=triangulateSphere(rt, s->r);//the points of sphere (rt,s->r)
for (int indice=0;indice<pp.size();indice++)
{
Point p1=pp[indice];
tableau2[i].push_back(p1);//I saved points of sphere i in //tableau2[i];
}
nombre++;
}
然後只得到不包括在我做了這樣的
glBegin(GL_TRIANGLE_STRIP);
for(int indsphere=0; indsphere<=nombre;indsphere++)// the spheres indexes
{
for (int indautresphere = 0;indautresphere<=nombre;indautresphere++)//other spheres created
{
if(indsphere!=indautresphere)
{
for (int nbrpointsi=0;nbrpointsi<tableau2[indsphere].size();nbrpointsi++)
{
float v1=(tableau2[indsphere][nbrpointsi].x)-(Vpoint[indautresphere].x);
float v2=(tableau2[indsphere][nbrpointsi].y)-(Vpoint[indautresphere].y);
float v3=(tableau2[indsphere][nbrpointsi].z)-(Vpoint[indautresphere].z);
float val=sqrt(v1*v1+v2*v2+v3*v3);//calculate distance between points
if(val >= (Vrayon[indautresphere]))
glVertex3fv(&((tableau2[indsphere][nbrpointsi]).x));
}
}
}
}
glEnd();
這個其他領域分也沒有編譯錯誤,但它顯示了所有即使那些與其他球體有交點的球員也會得分。它不排除任何一點
非常感謝Sir先生的幫助,但它給出了完全相同的結果,它保留了其他領域內存在的球體s1點。 – user3320319
@ user3320319:好的,只是看到了你做的其他錯誤:你不是通過球體來繪製球體,而是作爲一個整體,所以每個球體之間有一個三角形......嘗試編輯的答案('glBegin'和'glEnd'在循環中)。 – Jarod42
對不起,我真的沒有找到解決辦法。這是一樣的東西 – user3320319