本文整理汇总了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);
}
}
}
示例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();
}
}
示例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;
}
}
}
示例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();
}
示例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
}
示例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);
}
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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);
示例13:
void Ex59AdvancedJointsApp::update() {
arm->update( mouse );
world->Step( timeStep, velocityIterations, positionIterations );
world->ClearForces();
}
示例14: update
void _TBOX_PREFIX_App::update()
{
for( int i = 0; i < 10; ++i )
mWorld->Step( 1 / 30.0f, 10, 10 );
}
示例15:
void NOC_5_07_RevoluteJointApp::update()
{
for( int i = 0; i < 2; ++i )
mWorld->Step( 1 / 30.0f, 10, 10 );
}