예제 #1
0
        /// <summary>
        /// Sets the world matrix.
        /// </summary>
        /// <param name="worldMatrix">The world matrix.</param>
        /// <param name="source">The source object that caused this change or null when not important.</param>
        public override void SetWorldMatrix(MatrixD worldMatrix, object source = null, bool forceUpdate = false, bool updateChildren = true)
        {
            if (Entity.Parent != null && source != Entity.Parent)
            {
                return;
            }

            worldMatrix.AssertIsValid();

            if (Scale != null)
            {
                MyUtils.Normalize(ref worldMatrix, out worldMatrix);
                worldMatrix = MatrixD.CreateScale(Scale.Value) * worldMatrix;
            }
            if (!forceUpdate && m_worldMatrix.EqualsFast(ref worldMatrix))
            {
                return;
            }

            if (this.Container.Entity.Parent == null)
            {
                m_localMatrix = worldMatrix;
            }
            else
            {
                m_localMatrix = (Matrix)(worldMatrix * this.Container.Entity.Parent.WorldMatrixInvScaled);
            }
            this.m_worldMatrix = worldMatrix;

            OnWorldPositionChanged(source, updateChildren);
        }
예제 #2
0
 /// <summary>
 /// Sets the local matrix.
 /// </summary>
 /// <param name="localMatrix">The local matrix.</param>
 /// <param name="source">The source object that caused this change or null when not important.</param>
 public void SetLocalMatrix(MatrixD localMatrix, object source = null)
 {
     if (m_localMatrix != localMatrix)
     {
         //m_localMatrixChanged = true;
         m_localMatrix = localMatrix;
         m_localMatrix.AssertIsValid();
         UpdateWorldMatrix(source);
     }
 }
예제 #3
0
        /// <summary>
        /// Sets the world matrix.
        /// </summary>
        /// <param name="worldMatrix">The world matrix.</param>
        /// <param name="source">The source object that caused this change or null when not important.</param>
        public virtual void SetWorldMatrix(MatrixD worldMatrix, object source = null, bool forceUpdate = false, bool updateChildren = true)
        {
            if (Entity.Parent != null && source != Entity.Parent)
            {
                return;
            }

            worldMatrix.AssertIsValid();

            if (Scale != null)
            {
                MyUtils.Normalize(ref worldMatrix, out worldMatrix);
                worldMatrix = MatrixD.CreateScale(Scale.Value) * worldMatrix;
            }

            if (!forceUpdate && m_worldMatrix.EqualsFast(ref worldMatrix))
            {
                return;
            }


            if (Container.Entity.Parent == null)
            {
                m_worldMatrix = worldMatrix;
                m_localMatrix = worldMatrix;
            }
            else
            {
                MatrixD matParentInv = MatrixD.Invert(Container.Entity.Parent.WorldMatrix);
                m_localMatrix = worldMatrix * matParentInv;
            }

            //if (!m_localMatrix.EqualsFast(ref localMatrix))
            {
                //m_localMatrixChanged = true;
                //m_localMatrix = localMatrix;
                UpdateWorldMatrix(source);
            }
        }
예제 #4
0
 /// <summary>
 /// Updates the world matrix (change caused by parent)
 /// </summary>
 public virtual void UpdateWorldMatrix(ref MatrixD parentWorldMatrix, object source = null)
 {
     MatrixD.Multiply(ref m_localMatrix, ref parentWorldMatrix, out m_worldMatrix);
     m_worldMatrix.AssertIsValid();
     OnWorldPositionChanged(source);
 }