当前位置: 首页>>代码示例>>C++>>正文


C++ Transforms::getWorldOrientation方法代码示例

本文整理汇总了C++中Transforms::getWorldOrientation方法的典型用法代码示例。如果您正苦于以下问题:C++ Transforms::getWorldOrientation方法的具体用法?C++ Transforms::getWorldOrientation怎么用?C++ Transforms::getWorldOrientation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transforms的用法示例。


在下文中一共展示了Transforms::getWorldOrientation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setDirection

void Transforms::setDirection(const Vector3& vec, tTransformSpace relativeTo,
                              const Vector3& localDirectionVector)
{
    // Do nothing if given a zero vector
    if (vec == Vector3::ZERO)
        return;

    // The direction we want the local direction point to
    Vector3 targetDir = vec.normalisedCopy();

    // Retrieve the parent transforms of this component
    Transforms* pParentTransforms = getTransforms();

    // Transform target direction to world space
    switch (relativeTo)
    {
    case TS_LOCAL:
        targetDir = getWorldOrientation() * targetDir;
        break;

    case TS_PARENT:
        if (m_bInheritOrientation && pParentTransforms)
            targetDir = pParentTransforms->getWorldOrientation() * targetDir;
        break;

    case TS_WORLD:
        // default orientation
        break;
    }

    // Calculate target orientation relative to world space
    Quaternion targetOrientation;

    // Get current local direction relative to world space
    const Quaternion& currentOrient = getWorldOrientation();
    Vector3 currentDir = currentOrient * localDirectionVector;

    if ((currentDir + targetDir).squaredLength() < 0.00005f)
    {
        // Oops, a 180 degree turn (infinite possible rotation axes)
        // Default to yaw i.e. use current UP
        targetOrientation =
            Quaternion(-currentOrient.y, -currentOrient.z, currentOrient.w, currentOrient.x);
    }
    else
    {
        // Derive shortest arc to new direction
        Quaternion rotQuat = currentDir.getRotationTo(targetDir);
        targetOrientation = rotQuat * currentOrient;
    }

    // Set target orientation, transformed to parent space
    if (pParentTransforms && m_bInheritOrientation)
        setOrientation(pParentTransforms->getWorldOrientation().UnitInverse() * targetOrientation);
    else
        setOrientation(targetOrientation);
}
开发者ID:Kanma,项目名称:Athena-Entities,代码行数:57,代码来源:Transforms.cpp

示例2: translate

void Transforms::translate(const Vector3& d, tTransformSpace relativeTo)
{
    Vector3 adjusted;

    switch(relativeTo)
    {
    case TS_LOCAL:
        // Position is relative to parent so transform downwards
        m_position += m_orientation * d;
        break;

    case TS_PARENT:
        m_position += d;
        break;

    case TS_WORLD:
        {
            // Position is relative to parent so transform upwards
            Transforms* pParent = getTransforms();
            if (pParent)
                m_position += (pParent->getWorldOrientation().Inverse() * d) / pParent->getWorldScale();
            else
                m_position += d;
            break;
        }
    }

    needUpdate();
}
开发者ID:Kanma,项目名称:Athena-Entities,代码行数:29,代码来源:Transforms.cpp

示例3: getWorldTransform

void Body::getWorldTransform(btTransform& worldTrans) const
{
    Transforms* pTransforms = getTransforms();
    if (pTransforms)
    {
        worldTrans = btTransform(toBullet(pTransforms->getWorldOrientation()),
                                 toBullet(pTransforms->getWorldPosition()));
    }
}
开发者ID:Kanma,项目名称:Athena-Physics,代码行数:9,代码来源:Body.cpp

示例4: GetPtr

Handle<Value> Transforms_GetWorldOrientation(Local<String> property, const AccessorInfo &info)
{
    HandleScope handle_scope;

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

    return handle_scope.Close(toJavaScript(ptr->getWorldOrientation()));
}
开发者ID:Kanma,项目名称:Athena-Entities,代码行数:9,代码来源:Transforms.cpp

示例5: setWorldTransform

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);
    }
}
开发者ID:Kanma,项目名称:Athena-Physics,代码行数:11,代码来源:Body.cpp

示例6: update

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;
}
开发者ID:Kanma,项目名称:Athena-Entities,代码行数:52,代码来源:Transforms.cpp


注:本文中的Transforms::getWorldOrientation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。