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


C++ b2World::GetBodyList方法代码示例

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


在下文中一共展示了b2World::GetBodyList方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ReleaseNormalKeyInput

void ReleaseNormalKeyInput (unsigned char key, int x, int y)
{
   printf (" input %d\n", key );
   switch (key)
   {
      case 'w':
         break;
      case 'f':

         break;
      case 'a':

         break;
      case 'r':
         for ( b2Body * b = myWorld.GetBodyList (); b; b = b->GetNext () )
         {
            myWorld.DestroyBody (b);
         }
         delete agent;

         agent = new Agent (myWorld);
         readFile ("map.txt");
         break;

      case '1':
         break;
      default:
         break;
   }
}
开发者ID:rakib-csedu,项目名称:savide,代码行数:30,代码来源:main.cpp

示例2: if

void Box2DDebugRenderer::renderBodies ( b2World& world) {
    renderer.begin(ShapeRenderer::ShapeType::Line);

    if (mDrawBodies || mDrawAABBs) {        
        for (b2Body * body = world.GetBodyList(); body; body = body->GetNext())  {
            
            const b2Transform& transform = body->GetTransform();
            for (b2Fixture* fixture = body->GetFixtureList(); fixture; fixture = fixture->GetNext()) {
                if (mDrawBodies) {
                    if (body->IsActive() == false)
                        drawShape(*fixture, transform, SHAPE_NOT_ACTIVE);
                    else if (body->GetType() == b2_staticBody)
                        drawShape(*fixture, transform, SHAPE_STATIC);
                    else if (body->GetType() == b2_kinematicBody)
                        drawShape(*fixture, transform, SHAPE_KINEMATIC);
                    else if (body->IsAwake() == false)
                        drawShape(*fixture, transform, SHAPE_NOT_AWAKE);
                    else
                        drawShape(*fixture, transform, SHAPE_AWAKE);
                }

                if (mDrawAABBs) {
                    drawAABB(*fixture, transform);
                }
            }
        }
    }

    if (mDrawJoints) {
        for (b2Joint* joint = world.GetJointList(); joint; joint= joint->GetNext())
        {
            drawJoint(*joint);            
        }
    }
    
    renderer.end();

    if (gl10 != NULL) {
        gl10->glPointSize(3);
    }
    
    renderer.begin(ShapeRenderer::ShapeType::Point);

    for (b2Contact* contact = world.GetContactList(); contact; contact = contact->GetNext()) {
        drawContact(*contact);
    }
    renderer.end();
    
    if (gl10 != NULL) {
        gl10->glPointSize(1);
    }
}
开发者ID:Brodjaga,项目名称:libgdx-cpp,代码行数:52,代码来源:Box2DDebugRenderer.cpp

示例3: display_world

    void display_world(b2World& world,sf::RenderWindow& render)
    {
        world.Step(1.0/60,int32(8),int32(3));

        render.clear();

        for (b2Body* body=world.GetBodyList(); body!=nullptr; body=body->GetNext())
        {   
            sf::Shape* shape = static_cast<sf::Shape*>(body->GetUserData());
            shape->setPosition(converter::meters_to_pixels(body->GetPosition().x),converter::meters_to_pixels(body->GetPosition().y));
            shape->setRotation(converter::rad_to_deg<double>(body->GetAngle()));
            render.draw(*shape);
        }

        render.display();
    }
开发者ID:Krozark,项目名称:SFML-book,代码行数:16,代码来源:main.cpp

示例4: Update

void Update (int timer)
{
   float32 timeStep = 1 /
                      60.0f;    //the length of time passed to simulate (seconds)
   int32 velocityIterations = 6;   //how strongly to correct velocity
   int32 positionIterations = 3;   //how strongly to correct position

   myWorld.Step ( timeStep, velocityIterations, positionIterations);
   for ( b2Body * b = myWorld.GetBodyList (); b; b = b->GetNext () )
   {
      //do something with the body 'b'
      if (b->GetUserData () == 0)
      { break; }
   }
   glutPostRedisplay ();
   CalculateFps ();
   glutTimerFunc (1000.0f / 60.0f , Update, 1);
}
开发者ID:rakib-csedu,项目名称:savide,代码行数:18,代码来源:main.cpp

示例5: mContext

    MapLevel::MapLevel(Context& context, std::size_t level, sf::Image& levelData, b2World& world)
        : mContext(context)
        , mWorld(LevelWidth, std::vector<Tile>(LevelHeight))
        , mBoxWorld(world)
        , mTexture(context.getTexture(Textures::GameAtlas))
        , mDestinationList()
        , mSourceList()
        , mEntities()
    {
        LOG_CALL("MapLevel::MapLevel");

        // Reset Box2D world
        LOG_DEBUG("Clearing Box2D world from entities: %d to remove.", mBoxWorld.GetBodyCount());
        b2Body* body = world.GetBodyList();
        while (nullptr != body) {

            b2Body* nextBody = body->GetNext();
            world.DestroyBody(body);
            body = nextBody;
        }

        // Create Box2D world boundaries
        b2utils::createGround(mBoxWorld, 20.f, 300.f, 40.f, 600.f);
        b2utils::createGround(mBoxWorld, 780.f, 300.f, 40.f, 600.f);

        b2utils::createGround(mBoxWorld, 400.f, 18.f, 800.f, 36.f);
        b2utils::createGround(mBoxWorld, 400.f, 582.f, 800.f, 36.f);

        loadLevel(level, levelData);
        initSprites();

        //mDebugPlayerSpawn.setFillColor(sf::Color::Yellow);
        //LOG_DEBUG("Player spawn position: (%d, %d)", mPlayerSpawnPos.x, mPlayerSpawnPos.y);
        //mDebugPlayerSpawn.setPosition(WorldOffsetX + TileWidth * mPlayerSpawnPos.x, WorldOffsetY + TileHeight * mPlayerSpawnPos.y);
        //mDebugPlayerSpawn.setSize(sf::Vector2f(24.f, 24.f));
    }
开发者ID:silentlamb,项目名称:ld30-entry,代码行数:36,代码来源:MapLevel.cpp

示例6: Render

void Render ()
{
   LoadFPS (60);
   glClearColor (250/255.0, 245/255.0, 245/255.0, 1);
   srand (time (NULL) );
   //at global scope
   static float currentRayAngle = 0;
   currentRayAngle += 6;
   //calculate points of ray


   b2Vec2 p1 ( b2Vec2 (agent->body->GetPosition ().x,
                       agent->body->GetPosition ().y) ); //center of scene
   b2Vec2 p2 = p1 + rayLength * b2Vec2 (sinf (DEGTORAD * (currentRayAngle  ) ),
                                        cosf ( DEGTORAD * (currentRayAngle ) ) );

   b2Vec2 p3 ( b2Vec2 (agent->body->GetPosition ().x,
                       agent->body->GetPosition ().y) );
   b2Vec2 p4 = p3 + rayLength * b2Vec2 (sinf (DEGTORAD * (currentRayAngle + 90) ),
                                        cosf ( DEGTORAD * (currentRayAngle + 90) ) );

   b2Vec2 p5 ( b2Vec2 (agent->body->GetPosition ().x,
                       agent->body->GetPosition ().y) ); //center of scene
   b2Vec2 p6 = p5 + rayLength * b2Vec2 (sinf (DEGTORAD * (currentRayAngle + 180) ),
                                        cosf ( DEGTORAD * (currentRayAngle + 180) ) );

   b2Vec2 p7 ( b2Vec2 (agent->body->GetPosition ().x,
                       agent->body->GetPosition ().y) );
   b2Vec2 p8 = p7 + rayLength * b2Vec2 (sinf (DEGTORAD * (currentRayAngle + 270 ) ),
                                        cosf ( DEGTORAD * (currentRayAngle + 270 ) ) );
   b2Vec2 p9 =  b2Vec2 (agent->body->GetPosition ().x ,
                        agent->body->GetPosition ().y  - 4 ) ;
   b2Vec2 p10 = b2Vec2 (agent->body->GetPosition ().x ,
                        agent->body->GetPosition ().y - 4 )  + rayLength / 2.0 * b2Vec2 (sinf ( (
                                 agent->angle + 1.57) ),
                              cosf ( ( agent->angle + 1.57  ) ) );

   b2Vec2 p11 =  b2Vec2 (agent->body->GetPosition ().x ,
                         agent->body->GetPosition ().y + 4  ) ;
   b2Vec2 p12 = b2Vec2 (agent->body->GetPosition ().x,
                        agent->body->GetPosition ().y + 4   )  + rayLength / 2.0  * b2Vec2 (sinf ( (
                                 agent->angle + 1.57) ),
                              cosf ( ( agent->angle + 1.57 ) ) );

   b2RayCastInput input;
   input.p1 = p1;
   input.p2 = p2;
   input.maxFraction = rayLength / 50.0;

   b2RayCastInput input2;
   input2.p1 = p3;
   input2.p2 = p4;
   input2.maxFraction = rayLength / 50.0;

   b2RayCastInput input3;
   input3.p1 = p5;
   input3.p2 = p6;
   input3.maxFraction = rayLength / 50.0 ;

   b2RayCastInput input4;
   input4.p1 = p7;
   input4.p2 = p8;
   input4.maxFraction = rayLength / 50.0;

   b2RayCastInput input5;
   input5.p1 = p9;
   input5.p2 = p10;
   input5.maxFraction = rayLength / 50.0;

   b2RayCastInput input6;
   input6.p1 = p11;
   input6.p2 = p12;
   input6.maxFraction = rayLength / 50.0;

   //check every fixture of every body to find closest
   float closestFraction = rayLength / 50.0; //start with end of line as p2
   float closestFraction2 = rayLength / 50.0 ;
   float closestFraction3 =  rayLength / 50.0;
   float closestFraction4 =  rayLength / 50.0;
   float closestFraction5 = rayLength / 50.0;
   float closestFraction6 = rayLength / 50.0;
   static int timer = 0;
   timer++;
   b2Vec2 intersectionNormal (0, 0);

   bool isObstacle[5] = {0} ;
   static int freeAngle[5] = {0};
   freeAngle[1] = agent->angle;
   static int count = 0 ;
   /*
    * Raycasting is done here, there are 6 ray here
   */
   for (b2Body * b = myWorld.GetBodyList (); b; b = b->GetNext () )
   {
      if (100 == (int) b->GetUserData () )
      { break; }
      for (b2Fixture * f = b->GetFixtureList (); f; f = f->GetNext () )
      {
         b2RayCastOutput output;

//.........这里部分代码省略.........
开发者ID:rakib-csedu,项目名称:savide,代码行数:101,代码来源:main.cpp


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