Beispiel #1
0
void Body::getWorldTransform(btTransform& worldTrans) const
{
    Transforms* pTransforms = getTransforms();
    if (pTransforms)
    {
        worldTrans = btTransform(toBullet(pTransforms->getWorldOrientation()),
                                 toBullet(pTransforms->getWorldPosition()));
    }
}
Beispiel #2
0
Handle<Value> Transforms_GetWorldPosition(Local<String> property, const AccessorInfo &info)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(info.This());
    assert(ptr);

    return handle_scope.Close(toJavaScript(ptr->getWorldPosition()));
}
Beispiel #3
0
void Body::setWorldTransform(const btTransform& worldTrans)
{
    Transforms* pTransforms = getTransforms();
    if (pTransforms)
    {
        pTransforms->translate(fromBullet(worldTrans.getOrigin()) - pTransforms->getWorldPosition(), Transforms::TS_WORLD);

        if (m_bRotationEnabled)
            pTransforms->rotate(pTransforms->getWorldOrientation().rotationTo(fromBullet(worldTrans.getRotation())), Transforms::TS_WORLD);
    }
}
Beispiel #4
0
void Transforms::update()
{
    if (!m_bDirty)
        return;

    Transforms* pParent = getTransforms();
    if (pParent)
    {
        // Update orientation
        const Quaternion& parentOrientation = pParent->getWorldOrientation();
        if (m_bInheritOrientation)
        {
            // Combine orientation with that of parent
            m_fullOrientation = parentOrientation * m_orientation;
            m_fullOrientation.normalise();
        }
        else
        {
            // No inheritence
            m_fullOrientation = m_orientation;
        }

        // Update scale
        const Vector3& parentScale = pParent->getWorldScale();
        if (m_bInheritScale)
        {
            // Scale own position by parent scale, NB just combine
            // as equivalent axes, no shearing
            m_fullScale = parentScale * m_scale;
        }
        else
        {
            // No inheritence
            m_fullScale = m_scale;
        }

        // Change position vector based on parent's orientation & scale
        m_fullPosition = parentOrientation * (parentScale * m_position);

        // Add altered position vector to parents
        m_fullPosition += pParent->getWorldPosition();
    }
    else
    {
        // No parent
        m_fullPosition      = m_position;
        m_fullOrientation   = m_orientation;
        m_fullScale         = m_scale;
    }

    m_bDirty = false;
}