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