示例#1
0
    void Node::Update() const
    {
        if (!dirty_ || hide_)
            return;

        dirty_ = false;

        PNode parent = parent_.lock();

        if (parent)
        {
            globalModel_ = parent->GetGlobalModelMatrix() * GetTransform();
            globalPosition_ = Translation(globalModel_);
            globalOrientation_ = parent->GetGlobalOrientation() * q_;
            globalScale_ = Scale(globalModel_);
        }
        else
        {
            globalModel_ = GetTransform();
            globalPosition_ = position_;
            globalOrientation_ = q_;
            globalScale_ = scale_;
        }

        isScaleUniform_ = NSG::IsScaleUniform(globalScale_);
        globalModelInv_ = Inverse(globalModel_);
        globalModelInvTransp_ = Transpose(Inverse(Matrix3(globalModel_)));
        lookAtDirection_ = globalOrientation_ * VECTOR3_LOOKAT_DIRECTION;
        upDirection_ = globalOrientation_ * VECTOR3_UP;
        signalUpdated_->Run();
    }
示例#2
0
 void Node::SetGlobalLookAtDirection(const Vertex3& direction)
 {
     float length = Length(direction);
     if (length > 0)
     {
         auto rot = QuaternionFromLookRotation(-direction, GetUpDirection());
         PNode parent = parent_.lock();
         if (parent)
         {
             Quaternion q = Inverse(parent->GetGlobalOrientation());
             SetOrientation(q * rot);
         }
         else
         {
             SetOrientation(rot);
         }
     }
 }
示例#3
0
 void Node::SetGlobalLookAtPosition(const Vertex3& lookAtPosition, const Vertex3& up)
 {
     const Vertex3& position = GetGlobalPosition();
     auto direction = lookAtPosition - position;
     float length = Length(direction);
     if (length > 0)
     {
         auto rot = QuaternionFromLookRotation(-direction, up);
         PNode parent = parent_.lock();
         if (parent)
         {
             Quaternion q = Inverse(parent->GetGlobalOrientation());
             SetOrientation(q * rot);
         }
         else
         {
             SetOrientation(rot);
         }
     }
 }