本文整理汇总了C++中ConvexPolygon::getPolygon方法的典型用法代码示例。如果您正苦于以下问题:C++ ConvexPolygon::getPolygon方法的具体用法?C++ ConvexPolygon::getPolygon怎么用?C++ ConvexPolygon::getPolygon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConvexPolygon
的用法示例。
在下文中一共展示了ConvexPolygon::getPolygon方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Build
void Build(GPTexture* tex, cpSpace* a_space)
{
sprite=GPSprite(tex);
space=a_space;
ConvexPolygon polyset;
SimplePolygon BB=CreateBoundingBoxFromTexture(tex);
// polyset.addPolygon(BB);
/* SimplePolygon BB=CreateBoundingBoxFromTexture(tex);
SimplePolygon triangle1;
SimplePolygon triangle2;
triangle1.addVertex(BB.getVertex(0));
triangle1.addVertex(BB.getVertex(1));
triangle1.addVertex(BB.getVertex(2));
triangle2.addVertex(BB.getVertex(2));
triangle2.addVertex(BB.getVertex(3));
triangle2.addVertex(BB.getVertex(0));
polyset.addPolygon(triangle1);
polyset.addPolygon(triangle2);*/
polyset=CreateConvexPolySetFromTexture(tex,TYPE);
cpFloat m=1;//mass
cpFloat inertia=1;//inertia
body=cpBodyNew(m,inertia);
inertia=0;
int N_polys=polyset.getSize();
cout<<"N_polys="<<N_polys<<endl;
shape.resize(N_polys);
Nshapes+=N_polys;
for(int i=0;i<N_polys;i++)
{
SimplePolygon poly=polyset.getPolygon(i);
SDL_Surface* surf = tex->getSurface();
poly.addVector(GPVector(-surf->w/2.0,surf->h/2.0));
int N=poly.getSize();
cpVect* verts=new cpVect[N];
for(int j=0;j<N;j++)
{
// verts[N-1-j]=cpv(poly.getVertex(j).getX(),poly.getVertex(j).getY());
verts[j]=cpv(poly.getVertex(j).getX(),poly.getVertex(j).getY());
}
cpVect offset=cpvzero;
inertia+=cpMomentForPoly(m/(double)N_polys, poly.getSize(), verts, offset);
shape[i] = cpPolyShapeNew(body, poly.getSize(), verts, offset);
cpSpaceAddShape(space,shape[i]);
delete verts;
}
cout<<"inertia="<<inertia<<endl;
// cpBodySetMoment(body,inertia);
// cpBodySetMoment(body,1/*inertia*/);
SetBBInertia(m,BB,tex);
cpSpaceAddBody(space,body);
}