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


C# Matrix4x4.Decompose方法代码示例

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


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

示例1: UpdateUi

        private void UpdateUi(Matrix4x4 mat, bool diffAgainstBaseMatrix)
        {
            // use assimp math data structures because they have Decompose()
   
            // the decomposition algorithm is not very sophisticated - it basically extracts translation
            // and row scaling factors and then converts the rest to a quaternion. 
            // question: what if the matrix is non-invertible? the algorithm then yields
            // at least one scaling factor as zero, further results are undefined. We
            // therefore catch this case by checking the determinant and inform the user
            // that the results may be wrong.
            checkBoxNonStandard.Checked = Math.Abs(mat.Determinant()) < 1e-5;

            Vector3D scale;
            Quaternion rot;
            Vector3D trans;

            mat.Decompose(out scale, out rot, out trans);

            // translation
            textBoxTransX.Text = trans.X.ToString(Format);
            textBoxTransY.Text = trans.Y.ToString(Format);
            textBoxTransZ.Text = trans.Z.ToString(Format);

            // scaling - simpler view mode for uniform scalings
            var isUniform = Math.Abs(scale.X - scale.Y) < 1e-5 && Math.Abs(scale.X - scale.Z) < 1e-5;
            textBoxScaleX.Text = scale.X.ToString(Format);
            textBoxScaleY.Text = scale.Y.ToString(Format);
            textBoxScaleZ.Text = scale.Z.ToString(Format);

            textBoxScaleY.Visible = !isUniform;
            textBoxScaleZ.Visible = !isUniform;
            labelScalingX.Visible = !isUniform;
            labelScalingY.Visible = !isUniform;
            labelScalingZ.Visible = !isUniform;

            if (diffAgainstBaseMatrix)
            {
                const double epsilon = 1e-5f;
                if (Math.Abs(scale.X-_scale.X) > epsilon)
                {
                    labelScalingX.ForeColor = ColorIsAnimated;
                    textBoxScaleX.ForeColor = ColorIsAnimated;
                }

                if (Math.Abs(scale.Y - _scale.Y) > epsilon)
                {
                    labelScalingY.ForeColor = ColorIsAnimated;
                    textBoxScaleY.ForeColor = ColorIsAnimated;
                }

                if (Math.Abs(scale.Z - _scale.Z) > epsilon)
                {
                    labelScalingZ.ForeColor = ColorIsAnimated;
                    textBoxScaleZ.ForeColor = ColorIsAnimated;
                }

                if (Math.Abs(trans.X - _trans.X) > epsilon)
                {
                    labelTranslationX.ForeColor = ColorIsAnimated;
                    textBoxTransX.ForeColor = ColorIsAnimated;
                }

                if (Math.Abs(trans.Y - _trans.Y) > epsilon)
                {
                    labelTranslationY.ForeColor = ColorIsAnimated;
                    textBoxTransY.ForeColor = ColorIsAnimated;
                }

                if (Math.Abs(trans.Z - _trans.Z) > epsilon)
                {
                    labelTranslationZ.ForeColor = ColorIsAnimated;
                    textBoxTransZ.ForeColor = ColorIsAnimated;
                }
            }
            else
            {
                labelScalingX.ForeColor = ColorNotAnimated;
                textBoxScaleX.ForeColor = ColorNotAnimated;

                labelScalingY.ForeColor = ColorNotAnimated;
                textBoxScaleY.ForeColor = ColorNotAnimated;

                labelScalingZ.ForeColor = ColorNotAnimated;
                textBoxScaleZ.ForeColor = ColorNotAnimated;

                labelTranslationX.ForeColor = ColorNotAnimated;
                textBoxTransX.ForeColor = ColorNotAnimated;

                labelTranslationY.ForeColor = ColorNotAnimated;
                textBoxTransY.ForeColor = ColorNotAnimated;

                labelTranslationZ.ForeColor = ColorNotAnimated;
                textBoxTransZ.ForeColor = ColorNotAnimated;

                _scale = scale;
                _trans = trans;
                _rot = rot;
            }

            // rotation - more complicated because the display mode can be changed 
//.........这里部分代码省略.........
开发者ID:JSandusky,项目名称:open3mod,代码行数:101,代码来源:TrafoMatrixViewControl.cs


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