当前位置: 首页>>代码示例>>C++>>正文


C++ ConvexPolygon::getSize方法代码示例

本文整理汇总了C++中ConvexPolygon::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ ConvexPolygon::getSize方法的具体用法?C++ ConvexPolygon::getSize怎么用?C++ ConvexPolygon::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConvexPolygon的用法示例。


在下文中一共展示了ConvexPolygon::getSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);

        }
开发者ID:KIAaze,项目名称:iteam_hacking,代码行数:62,代码来源:GP2D_chipmunk_combo.cpp

示例2: main

int main(void)
{
    cpInitChipmunk(); /* Actually, that's pretty much it */

	space=cpSpaceNew();

    space->gravity=cpv(0,-100);
	space->elasticIterations=7;

    cpFloat dt=0.008;

    cpBody* staticBody = cpBodyNew(INFINITY, INFINITY);
    cpShape* bottom=cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 5.0f);
    cpShape* leftside=cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 5.0f);
    cpShape* rightside=cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 5.0f);
    cpSpaceAddStaticShape(space,bottom);
    cpSpaceAddStaticShape(space,leftside);
    cpSpaceAddStaticShape(space,rightside);

    cpFloat dim=10;
    int count=1000;
    cpSpaceResizeStaticHash(space, dim, count);
    cpSpaceResizeActiveHash(space, dim, count);

    GPEngine* engine = GPEngine::getInstance();
    engine->initAll();
	window = GPWindow::getInstance();
    window->setRenderMode(GPWindow::GP_OPENGL);
    window->setWindowTitle("Gamepower 2D Testing App");
    window->createWindow(640, 480, 24);
    window->setGraphicsDefaults();

    GPKeyboardHandler* handler = new GPKeyboardHandler();
    handler->registerKeyAction(GPKeyEvent::GP_KEY_ESCAPE, new ExitAction());
    handler->registerKeyAction(GPKeyEvent::GP_KEY_SPACE, new TogglePhysics());

	GPMouseHandler* mhandler = new GPMouseHandler();
    mhandler->registerMouseAction(new MouseAction());

    GPInputProcessor* proc = new GPInputProcessor();
    proc->addHandler(handler);
    proc->addHandler(mhandler);

    cam = new GPGameCamera(window->getHeight() / 2);
    cam->setPosition(0.0f, 0.0f);

	texSprite[0] = new GPTexture("susi.png");
    texSprite[1] = new GPTexture("debin.png");
    texSprite[2] = new GPTexture("fidori.png");
    texSprite[3] = new GPTexture("genti.png");
    texSprite[4] = new GPTexture("lini.png");
    
    texSusi = new GPTexture("susi.png");
    texMissile = new GPTexture("missile.png");
    texLeaves = new GPTexture("iteam_leaves_animation.png");

    ConvexPolygon polySprite[5];
    ConvexPolygon polyMissile;

    cout<<"=================="<<endl;
    for(int l_TYPE=0;l_TYPE<4;l_TYPE++)
    {
        cout<<"++++++++++++++++"<<endl;
        cout<<"Susi:"<<endl;
        polySprite[0]=CreateConvexPolySetFromTexture(texSprite[0],l_TYPE);
        cout<<"Debin:"<<endl;
        polySprite[1]=CreateConvexPolySetFromTexture(texSprite[1],l_TYPE);
        cout<<"Fidori:"<<endl;
        polySprite[2]=CreateConvexPolySetFromTexture(texSprite[2],l_TYPE);
        cout<<"Genti:"<<endl;
        polySprite[3]=CreateConvexPolySetFromTexture(texSprite[3],l_TYPE);
        cout<<"Lini:"<<endl;
        polySprite[4]=CreateConvexPolySetFromTexture(texSprite[4],l_TYPE);
        cout<<"Missile:"<<endl;
        polyMissile=CreateConvexPolySetFromTexture(texMissile,l_TYPE);
    }
    cout<<"=================="<<endl;

    ConvexPolygon polyLeaves=CreateConvexPolySetFromTexture(texLeaves,TYPE);
    ConvexPolygon polySusi=CreateConvexPolySetFromTexture(texSusi,TYPE);
    
    polySusi.setPosition(0,0);
    polyMissile.setPosition(100,0);
    polyLeaves.setPosition(0,100);
    
    for(int i=0;i<5;i++) cout<<"polySprite[i].getSize()="<<polySprite[i].getSize()<<endl;
    cout<<"polySusi.getSize()="<<polySusi.getSize()<<endl;
    cout<<"polyMissile.getSize()="<<polyMissile.getSize()<<endl;
    cout<<"polyLeaves.getSize()="<<polyLeaves.getSize()<<endl;

    class_testing(texSusi,space);

//     vector <GP_chipmunk_combo> sprSusi1;
//     sprSusi1.push_back(GP_chipmunk_combo(texSusi,space));
//     sprSusi1[sprSusi1.size()-1].setPosition(0.0f, 0.0f);
//     GP_chipmunk_combo S(texSusi,space,"normal element");
//     S.setPosition(0,0);
//     S.setRotation_Z(0);

//     S.sprite.setRotCenter(64,-64,0);
//.........这里部分代码省略.........
开发者ID:KIAaze,项目名称:iteam_hacking,代码行数:101,代码来源:GP2D_chipmunk_combo.cpp


注:本文中的ConvexPolygon::getSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。