示例#1
0
b2Joint *Box2DWeldJoint::createJoint(b2World *world)
{
    mJointDef.Initialize(bodyA()->body(), bodyB()->body(), 0.5f * (bodyA()->body()->GetWorldCenter() + bodyA()->body()->GetWorldCenter()));
    mJointDef.collideConnected = collideConnected();

    return world->CreateJoint(&mJointDef);
}
void Box2DDistanceJoint::cleanup(b2World *world)
{
    if (mDistanceJoint && bodyA() && bodyB()) {
        mDistanceJoint->SetUserData(0);
        world->DestroyJoint(mDistanceJoint);
        mDistanceJoint = 0;
    }
}
void Box2DFrictionJoint::cleanup(b2World *world)
{
    if (mFrictionJoint && bodyA() && bodyB()) {
        mFrictionJoint->SetUserData(0);
        world->DestroyJoint(mFrictionJoint);
        mFrictionJoint = 0;
    }
}
void Box2DFrictionJoint::createJoint()
{
    mFrictionJointDef.Initialize(bodyA()->body(), bodyB()->body(), bodyA()->body()->GetWorldCenter());
    mFrictionJointDef.collideConnected = collideConnected();

    mFrictionJoint = static_cast<b2FrictionJoint*>(world()->CreateJoint(&mFrictionJointDef));
    mInitializePending = false;
}
void Box2DPrismaticJoint::cleanup(b2World *world)
{
    if (mPrismaticJoint && bodyA() && bodyB()) {
        mPrismaticJoint->SetUserData(0);
        world->DestroyJoint(mPrismaticJoint);
        mPrismaticJoint = 0;
    }
}
示例#6
0
void Box2DWeldJoint::createJoint()
{
    if (anchorsAuto)
        mWeldJointDef.Initialize(bodyA()->body(), bodyB()->body(),bodyA()->body()->GetWorldCenter());
    else
    {
        mWeldJointDef.bodyA = bodyA()->body();
        mWeldJointDef.bodyB = bodyB()->body();
    }
    mWeldJointDef.collideConnected = collideConnected();
    mWeldJoint = static_cast<b2WeldJoint*>
            (world()->CreateJoint(&mWeldJointDef));

    mWeldJoint->SetUserData(this);
    mInitializePending = false;
    emit created();
}
示例#7
0
void Box2DMouseJoint::createJoint()
{    
    mMouseJointDef.bodyA = bodyA()->body();
    mMouseJointDef.bodyB = bodyB()->body();

    mMouseJoint = static_cast<b2MouseJoint*>
            (world()->CreateJoint(&mMouseJointDef));
    mMouseJoint->SetUserData(this);
    mInitializePending = false;
    emit created();
}
示例#8
0
void Box2DMouseJoint::cleanup(b2World *world)
{
    if (!world) {
        qWarning() << "MouseJoint: There is no world connected";
        return;
    }
    if (mMouseJoint && bodyA() && bodyB()) {
        mMouseJoint->SetUserData(0);
        world->DestroyJoint(mMouseJoint);
        mMouseJoint = 0;
    }
}
void Box2DPrismaticJoint::createJoint()
{
    mPrismaticJointDef.Initialize(bodyA()->body(), bodyB()->body(),
                                 bodyA()->body()->GetWorldCenter(),
                                  mPrismaticJointDef.localAxis1);
    mPrismaticJointDef.collideConnected = collideConnected();

    mPrismaticJoint = static_cast<b2PrismaticJoint*>
            (world()->CreateJoint(&mPrismaticJointDef));
    mPrismaticJoint->SetUserData(this);
    mInitializePending = false;
}
示例#10
0
void Box2DGearJoint::createJoint()
{    
    if (!mGearJointDef.joint1 || !mGearJointDef.joint2)
        return;
    mGearJointDef.bodyA = bodyA()->body();
    mGearJointDef.bodyB = bodyB()->body();

    mGearJoint = static_cast<b2GearJoint*>(world()->CreateJoint(&mGearJointDef));
    mGearJoint->SetUserData(this);
    mInitializePending = false;
    emit created();
}
示例#11
0
void Box2DDistanceJoint::createJoint()
{
    b2Vec2 anchorA = mOverrideLocalAnchorA ?
                b2Vec2(mLocalAnchorA.x() / scaleRatio,
                       -mLocalAnchorA.y() / scaleRatio) +
                bodyA()->body()->GetPosition() :
                bodyA()->body()->GetWorldCenter();

    b2Vec2 anchorB = mOverrideLocalAnchorB ?
                b2Vec2(mLocalAnchorB.x() / scaleRatio,
                       -mLocalAnchorB.y() / scaleRatio) +
                bodyB()->body()->GetPosition() :
                bodyB()->body()->GetWorldCenter();

    mDistanceJointDef.Initialize(bodyA()->body(), bodyB()->body(),
                                 anchorA, anchorB);
    mDistanceJointDef.collideConnected = collideConnected();
    if (mOverrideAnchorLength)
        mDistanceJointDef.length = mLength;
    mDistanceJoint = static_cast<b2DistanceJoint*>
            (world()->CreateJoint(&mDistanceJointDef));
    mDistanceJoint->SetUserData(this);
    mInitializePending = false;
}