Exemple #1
0
 void StableWorld::SaveState()
 {
     ForEachDynamicBody(GetBodyList(), [](b2Body* body) {
         auto d = GetBodyState(body);
         const auto& t = body->GetTransform();
         d->prev_p = d->curr_p;
         d->curr_p = t.p;
         d->prev_r = d->curr_r;
         d->curr_r = t.q.GetAngle();
     });
 }
Exemple #2
0
    void StableWorld::RestoreState()
    {
        ForEachDynamicBody(GetBodyList(), [this](b2Body* body) {
            auto d = GetBodyState(body);
            if (!d->sprite)
                return;

            const Vec2f position(d->curr_p.x * ptm_, d->curr_p.y * ptm_);
            d->sprite->set_position(position);
            d->sprite->set_rotation(d->curr_r);
        });
    }
Exemple #3
0
    void StableWorld::Interpolate()
    {
        const float ratio = elapsed_ * kStepsPerMs;
        ForEachDynamicBody(
            GetBodyList(),
            [this](b2Body* body, float ratio, float rest) {
                if (!body->IsAwake())
                    return;

                auto d = GetBodyState(body);
                if (!d->sprite)
                    return;

                const b2Vec2 v = ptm_ * (ratio * d->curr_p + rest * d->prev_p);
                d->sprite->set_position(Vec2f(v.x, v.y));
                d->sprite->set_rotation(ratio * d->curr_r + rest * d->prev_r);
            },
            ratio,
            1.0f - ratio);
    }
Exemple #4
0
 void StableWorld::DestroyBody(b2Body* body)
 {
     delete GetBodyState(body);
     b2World::DestroyBody(body);
 }
Exemple #5
0
void Menu::Include(Control* c) {
    scene_->Insert(c);
    c->SetState(GetBodyState());
    Reparent(c, this);
}