Example #1
0
    void Node::SetGlobalPosition(const Vertex3& position)
    {
        PNode parent = parent_.lock();

        if (parent == nullptr)
        {
            SetPosition(position);
        }
        else
        {
            SetPosition(Vertex3(parent->GetGlobalModelInvMatrix() * Vertex4(position, 1)));
        }
    }
Example #2
0
    void Node::SetGlobalOrientation(const Quaternion& q)
    {
        PNode parent = parent_.lock();

        if (parent == nullptr)
        {
            SetOrientation(q);
        }
        else
        {
            SetOrientation(Normalize(Quaternion(parent->GetGlobalModelInvMatrix()) * q));
        }
    }
Example #3
0
    void Node::Translate(const Vector3& delta, TransformSpace space)
    {
        switch (space)
        {
            case TS_LOCAL:
                // Note: local space translation disregards local scale for scale-independent movement speed
                position_ += GetOrientation() * delta;
                break;

            case TS_PARENT:
                position_ += delta;
                break;

            case TS_WORLD:
                {
                    PNode parent = parent_.lock();
                    position_ += (parent == scene_.lock() || !parent) ? delta : Vector3(parent->GetGlobalModelInvMatrix() * Vector4(delta, 0.0f));
                    break;
                }
        }

        MarkAsDirty();
    }