示例#1
0
void CompPhysics::applyForce(const Vector2D& impulse, const Vector2D& point)
{
    if (m_body==NULL)
    {
        log(Warning) << "applyForce: component was not yet initialized by physics system\n";
        return;
    }
    m_body->ApplyForce(*impulse.to_b2Vec2(), *point.to_b2Vec2(), false);
}
示例#2
0
Vector2D CompPhysics::globalToLocal(const Vector2D& global) const
{
    if (m_body==NULL)
    {
        log(Warning) << "globalToLocal: component was not yet initialized by physics system\n";
        return Vector2D();
    }
    return m_body->GetWorldVector(*global.to_b2Vec2());
}
示例#3
0
void CompPhysics::setLinearVelocity(const Vector2D& vel)
{
    if (m_body==NULL)
    {
        log(Warning) << "setLinearVelocity: component was not yet initialized by physics system\n";
        return;
    }
    m_body->SetLinearVelocity( *vel.to_b2Vec2() );
}
示例#4
0
void CompPhysics::rotate( float deltaAngle, const Vector2D& localPoint )
{
    if (m_body==NULL)
    {
        log(Warning) << "rotate: component was not yet initialized by physics system\n";
        return;
    }

    float newAngle = m_body->GetAngle() + deltaAngle;

    Vector2D worldRotationCenter( Vector2D(m_body->GetPosition()) + localPoint.rotated(m_body->GetAngle()) );
    Vector2D worldRotationCenterToBodyCenter ( -localPoint.rotated(newAngle) );
    Vector2D newPos = worldRotationCenter + worldRotationCenterToBodyCenter;

    m_body->SetTransform( *newPos.to_b2Vec2(), newAngle );
}