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


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

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


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

示例1: DropParticle

// Destroy all particles in the system, drop a particle onto the fixture and
// keep track of the number of contacts with the fixture in addition to the
// stuck particle candiates.
void BodyContactTests::DropParticle()
{
	// Reset counters.
	m_contacts = 0;
	m_stuck = 0;
	DestroyAllParticles();

	const float32 timeStep = 1.0f / 60.0f;
	const int32 timeout = (int32)(1.0f / timeStep) * 10; // 10 "seconds"
	const int32 velocityIterations = 6;
	const int32 positionIterations = 2;

	// Step once to eliminate particles.
	m_world->Step(timeStep, velocityIterations, positionIterations);

	b2ParticleDef pd;
	pd.position.Set(0.0f, 33.0f);
	pd.velocity.Set(0.0f, -1.0f);
	m_particleSystem->CreateParticle(pd);

	for (int32 i = 0; i < timeout; ++i)
	{
		m_world->Step(timeStep, velocityIterations, positionIterations);
		m_contacts += m_particleSystem->GetBodyContactCount();
		int32 stuck = m_particleSystem->GetStuckCandidateCount();
		if (stuck)
		{
			m_stuck += stuck;
			// Should always be particle 0.
			EXPECT_EQ(*(m_particleSystem->GetStuckCandidates()), 0);
		}
	}
}
开发者ID:3rd3,项目名称:liquidfun,代码行数:36,代码来源:BodyContactsTests.cpp

示例2: Square

void Ex58AdvancedCollisionsApp::update() {
    if ( Rand::randInt( 100 ) == 90 ) {
        squares.push_back( new Square( world, Vec2f( Rand::randFloat( getWindowWidth() ), -10.0f ), 0.0f, 10.0f ) );
    }
    if ( Rand::randInt( 100 ) == 90 ) {
    circles.push_back( new Circle( world, Vec2f( Rand::randFloat( getWindowWidth() ), -10.0f ), 0.0f, 10.0f ) );
    }
    if ( Rand::randInt( 100 ) == 90 ) {
    triangles.push_back( new Triugolnik( world, Vec2f( Rand::randFloat( getWindowWidth() ), -10.0f ), 0.0f, 10.0f ) );
    }
    
    world->Step( timeStep, velocityIterations, positionIterations );
    
    for ( auto& s : squares ) {
        s->update();
    }
    
    for ( auto& t : triangles ) {
        t->update();
    }
    
    for ( auto& c : circles ) {
        c->update();
    }
    
}
开发者ID:ilzxc,项目名称:The-Nature-of-Cinder,代码行数:26,代码来源:Ex58AdvancedCollisionsApp.cpp

示例3: particleSystem

void Box2dApp::update()
{
    for( int i = 0; i < 10; ++i ){
        mWorld->Step( 1 / 30.0f, 10, 10 );
    }
    for( list<box1*>::iterator boxIt = mBoxes.begin(); boxIt != mBoxes.end(); ) {
        if((*boxIt)->isDead()){
        ps.push_back(new particleSystem(200,(*boxIt)->getPosition(), (*boxIt)->getAngle()));
        boxIt = mBoxes.erase(boxIt);
     }else {
        (*boxIt)->update();
        ++boxIt;
     }
    }
    for( list<particleSystem*>::iterator psIt = ps.begin(); psIt != ps.end();) {
        if((*psIt)->isDead() == true){
            psIt = ps.erase(psIt);}
                else{
                    (*psIt)->update();
                    ++psIt;
            }

    }
   
}
开发者ID:dmelancon,项目名称:Box2DparticleSystem,代码行数:25,代码来源:Box2dApp.cpp

示例4: step

void step(b2World& world, float dt)
{
	const int maxSteps = 20;
	const float fixedDt = 1.0f / 60.f;
	const float minDt = fixedDt / 10.f;
	int stepsPerformed = 0;
	float frameTime = dt;

	while (frameTime > 0.0f && stepsPerformed < maxSteps)
	{
		float delta = (std::min)(frameTime, fixedDt);
		frameTime -= delta;
		if (frameTime < minDt)
		{
			delta += frameTime;
			frameTime = 0.0f;
		}
		const int velocityIterations = 8;
		const int positionIterations = 3;
		world.Step(delta, velocityIterations, positionIterations);

	}

	world.ClearForces();
}
开发者ID:ZhangYunjie,项目名称:DestructibleBox2D,代码行数:25,代码来源:main.cpp

示例5: physics_step

// advance the physical simulator steps (must be called every frame to do physics)
void physics_step(b2World& world)
{
	static Uint32 time = Ness::get_ticks();
	static Uint32 lasttime = time;

    time = Ness::get_ticks();
    world.Step((time - lasttime) / 1000.0f, 10, 10);
    lasttime = time; // lasttime is a member variable that holds the ticks since the last loop
}
开发者ID:RonenNess,项目名称:ness-engine,代码行数:10,代码来源:main.cpp

示例6: RunStep

// Run simulation for a specified amount of time at the specified
// frequency.
void BodyContactTests::RunStep(const float32 frequencyHz,
							   const float32 simulationTime)
{
	const float32 timeStep = 1.0f / frequencyHz;
	const int32 frames = b2Max((int32)(frequencyHz * simulationTime), 1);
	for (int32 i = 0; i < frames; ++i)
	{
		m_world->Step(timeStep, 1, 1);
	}
}
开发者ID:3rd3,项目名称:liquidfun,代码行数:12,代码来源:BodyContactsTests.cpp

示例7: 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

示例8: 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

示例9:

int32
ConfinementTests::TestLeakCount()
{
	for (int32 t = 0; t < NUMBER_OF_STEPS; t++) {
		m_world->Step(DELTA_T, 1, 1);
	}
	int32 bufferIndex = m_particleGroup->GetBufferIndex();
	int32 particleCount = m_particleGroup->GetParticleCount();
	const b2Vec2 *positionBuffer = m_particleSystem->GetPositionBuffer();
	int32 leakCount = 0;
	for (int32 i = 0; i < particleCount; i++) {
		b2Vec2 p = positionBuffer[bufferIndex + i];
		if (std::abs(p.x) > WIDTH || std::abs(p.y) > HEIGHT) {
			leakCount++;
		}
	}
	return leakCount;
}
开发者ID:383530895,项目名称:liquidfun,代码行数:18,代码来源:ConfinementTests.cpp

示例10: Box

void Ex52FixedObjectsApp::update() {
    
    if (addBoxes) {
        boxes.push_back( Box( world, mousePosition.x, mousePosition.y, Rand::randFloat(5.0f, 20.0f), Rand::randFloat(5.0f, 20.0f) ) );
    }
    
    // World step:
    float32 timeStep = 1.0f / 60.0f;
    int32 velocityIterations = 8;
    int32 positionIterations = 3;
    world->Step( timeStep, velocityIterations, positionIterations );
    
    for ( std::vector<Box>::iterator iter = boxes.begin(); iter != boxes.end(); ) {
        iter->update( world );
        if (iter->isDead()) {
            world->DestroyBody( iter->getBody() );
            boxes.erase( iter );
        } else {
            ++iter;
        }
    }
}
开发者ID:ilzxc,项目名称:The-Nature-of-Cinder,代码行数:22,代码来源:Ex52FixedObjectsApp.cpp

示例11: main

int main(int argc, char * argv[])
{
    // VARS
    const float32 fps = 60.0f;
    const float32 timeStep = 1.0f / fps;

    const int32 velocityIter = 8;
    const int32 positionIter = 3;

    // SFML
    EventWindow app(VideoMode(WIDTH, HEIGHT, BPP), "Box2D",60);
    app.addEvent(EventManager::createEvent<sf::RenderWindow*>(addSoftCircleCallBack,&app,sf::Event::MouseButtonPressed,sf::Mouse::Left));
    app.addEvent(EventManager::createEvent<sf::RenderWindow*>(addCircleCallBack,&app,sf::Event::MouseButtonPressed,sf::Mouse::Right));
    app.addEvent(EventManager::createEvent<sf::RenderWindow*>(addEntityCallBack,&app,sf::Event::KeyPressed,sf::Keyboard::Space),true);
    //Move event
    app.addEvent(EventManager::createEvent<sf::RenderWindow*,float,float>(moveWindow,&app,10.f,0.f,sf::Event::KeyPressed,sf::Keyboard::Right),true);
    app.addEvent(EventManager::createEvent<sf::RenderWindow*,float,float>(moveWindow,&app,-10.f,0.f,sf::Event::KeyPressed,sf::Keyboard::Left),true);
    app.addEvent(EventManager::createEvent<sf::RenderWindow*,float,float>(moveWindow,&app,0.f,10.f,sf::Event::KeyPressed,sf::Keyboard::Down),true);
    app.addEvent(EventManager::createEvent<sf::RenderWindow*,float,float>(moveWindow,&app,0.f,-10.f,sf::Event::KeyPressed,sf::Keyboard::Up),true);



    // BOX2D

    bodys[0] = new RectBody(0,300,10000,10,b2_staticBody);
    bodys[0]->SetRotation(25);

    bodys[1] = new RectBody(300,0,10000,10,b2_staticBody);
    bodys[1]->SetRotation(90);

    bodys[2] = new RectBody(0,-3500,10000,10,b2_staticBody);
    bodys[2]->SetRotation(180);

    bodys[3] = new RectBody(-400,0,10000,10,b2_staticBody);
    bodys[3]->SetRotation(90);


    {
        sf::Image image;
        if (!image.loadFromFile("smile.png"))
            exit(1);
        glEnable(GL_TEXTURE_2D);
        glGenTextures(1, &texture);
        glBindTexture(GL_TEXTURE_2D, texture);
        Vector2u size = image.getSize();
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr());
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
        glDisable(GL_TEXTURE_2D);

    }

    // MAIN LOOP
    while(app.isOpen())
    {
        app.doEvents();

        world.Step(timeStep, velocityIter, positionIter); // on calcule la frame suivante

        app.clear(sf::Color::Red);

        for (int i =bodys.size()-1;i>=0;--i)
                bodys[i]->Draw(app);

        app.display();
    }
    glDeleteTextures(1, &texture);

    for(unsigned int i=0; i<bodys.size();++i)
        delete bodys[i];

    return EXIT_SUCCESS;
}
开发者ID:Krozark,项目名称:Ekiis,代码行数:73,代码来源:main.cpp

示例12: main


//.........这里部分代码省略.........
            menu_logo_bottom->setPosition(window_width - textures["menu_logo_bottom"].getSize().x, window_height - textures["menu_logo_bottom"].getSize().y);

            menu.update(gameEvents);
            menu.draw(window);

            // Instructions
            if(show_instructions)
            {
                showInstructions();

                if(show_instructions_controls)
                {
                    showControls();
                }

                if(show_instructions_gameplay)
                {
                    showGameplay();
                }
            }
        }
        else
        {
            window.setView(windowView);

            // ------------------------------- Updates -------------------------------

            // Player
            player.update(physicsWorld, gameEvents, gameWorld);

            if(!global_isPaused)
            {
                // Physics
                physicsWorld.Step(TIME_STEP, VELOCITY_ITERATIONS, POSITION_ITERATIONS);

                // World
                gameWorld.update(gameEvents, physicsWorld, player);

                // UI
                ui.update(gameWorld, player);
            }


            // Calculate viewable area
            int viewShiftX = window.getSize().x/2 - window.getView().getCenter().x;
            int viewShiftY = window.getSize().y/2 - window.getView().getCenter().y;
            int windowMinX = -100 - viewShiftX;
            int windowMaxX = windowMinX + window_width + 200;
            int windowMinY = -100 - viewShiftY;
            int windowMaxY = windowMinY + window_height + 200;

            // ------------------------------- Drawing -------------------------------

            window.setView(ui.getView());
            // Background
            sf::Vertex rectangle[] =
            {
                sf::Vertex(sf::Vector2f(0.0f, 0.0f), sf::Color(0, 100, 130, 255)),
                sf::Vertex(sf::Vector2f(window_width, 0.0f), sf::Color(0, 100,130, 255)),
                sf::Vertex(sf::Vector2f(window_width, window_height), sf::Color(0, 200, 230, 255)),
                sf::Vertex(sf::Vector2f(0.0f, window_height), sf::Color(0, 200, 230, 255))
            };
            window.draw(rectangle, 4, sf::Quads);

            window.setView(windowView);
开发者ID:TheNinthFox,项目名称:foxbox,代码行数:66,代码来源:main.cpp

示例13:

void Ex59AdvancedJointsApp::update() {
    arm->update( mouse );
    world->Step( timeStep, velocityIterations, positionIterations );
    world->ClearForces();
}
开发者ID:ilzxc,项目名称:The-Nature-of-Cinder,代码行数:5,代码来源:Ex59AdvancedJointsApp.cpp

示例14: update

void _TBOX_PREFIX_App::update()
{
	for( int i = 0; i < 10; ++i )
		mWorld->Step( 1 / 30.0f, 10, 10 );
}
开发者ID:AKS2346,项目名称:Cinder,代码行数:5,代码来源:_TBOX_PREFIX_App.cpp

示例15:

void NOC_5_07_RevoluteJointApp::update()
{
	for( int i = 0; i < 2; ++i )
		mWorld->Step( 1 / 30.0f, 10, 10 );
}
开发者ID:FreeArtBureau,项目名称:The-Nature-of-Code-Examples,代码行数:5,代码来源:NOC_5_07_RevoluteJointApp.cpp


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