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


C# Matrix4x4.Transpose方法代码示例

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


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

示例1: Test_Transpose

        public void Test_Transpose()
        {
            var a = new Matrix4x4 (1, 2, 1, 1,
                                   2, 1, 2, 1,
                                   2, 2, 2, 2,
                                   1, 1, 2, 1);

            var b = new Matrix4x4 (1, 2, -1, 1,
                                   -1, 1, -1, 1,
                                   2, -1, 1, -1,
                                   1, 1, 2, 1);

            var aTra = new Matrix4x4 (1, 2, 2, 1,
                                      2, 1, 2, 1,
                                      1, 2, 2, 2,
                                      1, 1, 2, 1);
            var bTra = new Matrix4x4 (1, -1, 2, 1,
                                     2, 1, -1, 1,
                                     -1, -1, 1, 2,
                                     1, 1, -1, 1);

            Assert.AreEqual (aTra, a.Transpose ());
            Assert.AreEqual (bTra, b.Transpose ());
        }
开发者ID:weimingtom,项目名称:erica,代码行数:24,代码来源:TestMatrix4x4.cs

示例2: Adjoint

 //type-specific methods
 /// <summary>
 /// Calculates the adjoint matrix
 /// </summary>
 /// <returns>the adjoint matrix</returns>
 public Matrix4x4 Adjoint()
 {
     Matrix4x4 adj = new Matrix4x4();
     for (int r=0;r<4;r++)
     {
         for (int c = 0; c < 4; c++)
         {
             adj[r, c] = (float)Math.Pow(-1, (r + 1) + (c + 1)) * Minor(r + 1, c + 1);
         }
     }
     return adj.Transpose();
 }
开发者ID:revb39,项目名称:crmath,代码行数:17,代码来源:Matrix4x4.cs

示例3: RotateZ

 public static Transform RotateZ(float angle) {
     float sin_t = (float)Math.Sin(MathLab.Radians(angle));
     float cos_t = (float)Math.Cos(MathLab.Radians(angle));
     Matrix4x4 m = new Matrix4x4(cos_t, -sin_t, 0, 0,
                                 sin_t, cos_t, 0, 0,
                                 0, 0, 1, 0,
                                 0, 0, 0, 1);
     return new Transform(m, m.Transpose());
 }
开发者ID:HungryBear,项目名称:rayden,代码行数:9,代码来源:Transform.cs

示例4: Rotate

        public static Transform Rotate(float angle, Vector axis) {
            Vector a = axis.Normalize();
            float s = (float)Math.Sin(MathLab.Radians(angle));
            float c = (float)Math.Cos(MathLab.Radians(angle));
            float[,] m = new float[4, 4];

            m[0, 0] = a.x * a.x + (1f - a.x * a.x) * c;
            m[0, 1] = a.x * a.y * (1f - c) - a.z * s;
            m[0, 2] = a.x * a.z * (1f - c) + a.y * s;
            m[0, 3] = 0;

            m[1, 0] = a.x * a.y * (1f - c) + a.z * s;
            m[1, 1] = a.y * a.y + (1f - a.y * a.y) * c;
            m[1, 2] = a.y * a.z * (1f - c) - a.x * s;
            m[1, 3] = 0;

            m[2, 0] = a.x * a.z * (1f - c) - a.y * s;
            m[2, 1] = a.y * a.z * (1f - c) + a.x * s;
            m[2, 2] = a.z * a.z + (1f - a.z * a.z) * c;
            m[2, 3] = 0;

            m[3, 0] = 0;
            m[3, 1] = 0;
            m[3, 2] = 0;
            m[3, 3] = 1;

            Matrix4x4 o = new Matrix4x4(m);
            return new Transform(o, o.Transpose());
        }
开发者ID:HungryBear,项目名称:rayden,代码行数:29,代码来源:Transform.cs

示例5: RotateX

 public static Transform RotateX(float angle) {
     float sin_t = (float)Math.Sin(MathLab.Radians(angle));
     float cos_t = (float)Math.Cos(MathLab.Radians(angle));
     Matrix4x4 m = new Matrix4x4(1, 0, 0, 0,
                                 0, cos_t, -sin_t, 0,
                                 0, sin_t, cos_t, 0,
                                 0, 0, 0, 1);
     var mt = m.Transpose();
     return new Transform(ref m, ref mt);
 }
开发者ID:HungryBear,项目名称:rayden,代码行数:10,代码来源:Transform.cs

示例6: Evaluate


//.........这里部分代码省略.........
                cAnimationChannel channel = Channels[a];
                cBone bonenode;
                bool found = bones.TryGetValue(channel.Name, out bonenode);
                //std::map<std::string, cBone*>::iterator bonenode = bones.find(channel->Name);

                if(!found)
                {
                    Console.Write("Couldn't find bone");
                    continue;
                }
                // ******** Position *****
                Vector3D presentPosition = new Vector3D(0, 0, 0);
                if(channel.mPositionKeys.Count > 0){
                    // Look for present frame number. Search from last position if time is after the last time, else from beginning
                    // Should be much quicker than always looking from start for the average use case.
                    int frame = (time >= mLastTime) ? mLastPositions[a].Item1 : 0;
                    while( frame < channel.mPositionKeys.Count() - 1)
                    {
                        if(time < channel.mPositionKeys[frame+1].Time)
                        {
                            break;
                        }
                        frame++;
                    }
                    // interpolate between this frame's value and next frame's value
                    int nextFrame = (frame + 1) % channel.mPositionKeys.Count();

                    VectorKey key = channel.mPositionKeys[frame];
                    VectorKey nextKey = channel.mPositionKeys[nextFrame];
                    double diffTime = nextKey.Time - key.Time;
                    if( diffTime < 0.0)
                        diffTime += Duration;
                    if( diffTime > 0)
                    {
                        float factor = (float)((time - key.Time) / diffTime);
                        presentPosition = key.Value + (nextKey.Value - key.Value) * factor;
                    }
                    else
                    {
                        presentPosition = key.Value;
                    }
                    mLastPositions[a] = new Tuple<int,int,int>(frame, mLastPositions[a].Item2, mLastPositions[a].Item3);
                }
                // ******** Rotation *********
                Quaternion presentRotation = new Quaternion(1, 0, 0, 0);
                if(channel.mRotationKeys.Count() > 0)
                {
                    int frame = (time >= mLastTime) ? mLastPositions[a].Item2 : 0;
                    while( frame < channel.mRotationKeys.Count()  - 1)
                    {
                        if( time < channel.mRotationKeys[frame+1].Time)
                            break;
                        frame++;
                    }

                    // interpolate between this frame's value and next frame's value
                    int nextFrame = (frame + 1) % channel.mRotationKeys.Count();

                    QuaternionKey key = channel.mRotationKeys[frame];
                    QuaternionKey nextKey = channel.mRotationKeys[nextFrame];
                    double diffTime = nextKey.Time - key.Time;
                    if( diffTime < 0.0) diffTime += Duration;
                    if( diffTime > 0)
                    {
                        float factor = (float)((time - key.Time) / diffTime);
                        //this next line might be wrong (written awake for 20 hours), but I chanced it
                        presentRotation *= Quaternion.Slerp(key.Value, nextKey.Value, factor);
                    }
                    else presentRotation = key.Value;
                    mLastPositions[a] = new Tuple<int,int,int>(mLastPositions[a].Item1, frame, mLastPositions[a].Item3);
                }

                // ******** Scaling **********
                Vector3D presentScaling = new Vector3D(1, 1, 1);
                if(channel.mScalingKeys.Count() > 0)
                {
                    int frame = (time >= mLastTime) ? mLastPositions[a].Item3 : 0;
                    while( frame < channel.mScalingKeys.Count() - 1){
                        if( time < channel.mScalingKeys[frame+1].Time)
                            break;
                        frame++;
                    }
                    presentScaling = channel.mScalingKeys[frame].Value;
                    mLastPositions[a] = new Tuple<int,int,int>(mLastPositions[a].Item1, mLastPositions[a].Item2, frame);
                }

                Matrix4x4 mat = new Matrix4x4(presentRotation.GetMatrix());

                mat.A1 *= presentScaling.X; mat.B1 *= presentScaling.X; mat.C1 *= presentScaling.X;
                mat.A2 *= presentScaling.Y; mat.B2 *= presentScaling.Y; mat.C2 *= presentScaling.Y;
                mat.A3 *= presentScaling.Z; mat.B3 *= presentScaling.Z; mat.C3 *= presentScaling.Z;
                mat.A4 = presentPosition.X; mat.B4 = presentPosition.Y; mat.C4 = presentPosition.Z;
                mat.Transpose();

                //may need to write custom TransformMatrix function here
                bonenode.LocalTransform = mat;
                //TransformMatrix(bonenode->second->LocalTransform, mat);
            }
            mLastTime = time;
        }
开发者ID:EternalEnvy,项目名称:SmackBrosClient,代码行数:101,代码来源:AnimationLoader.cs

示例7: Evaluate

        public void Evaluate(float dt, Dictionary<string, Bone> bones) {
            dt *= TicksPerSecond;
            var time = 0.0f;
            if (Duration > 0.0f) {
                time = dt % Duration;
            }
            for (int i = 0; i < Channels.Count; i++) {
                var channel = Channels[i];
                if (!bones.ContainsKey(channel.Name)) {
                    Console.WriteLine("Did not find the bone node " + channel.Name);
                    continue;
                }
                // interpolate position keyframes
                var pPosition = new Vector3D();
                if (channel.PositionKeys.Count > 0) {
                    var frame = (time >= LastTime) ? LastPositions[i].Item1 : 0;
                    while (frame < channel.PositionKeys.Count - 1) {
                        if (time < channel.PositionKeys[frame + 1].Time) {
                            break;
                        }
                        frame++;
                    }
                    if (frame >= channel.PositionKeys.Count) {
                        frame = 0;
                    }

                    var nextFrame = (frame + 1) % channel.PositionKeys.Count;

                    var key = channel.PositionKeys[frame];
                    var nextKey = channel.PositionKeys[nextFrame];
                    var diffTime = nextKey.Time - key.Time;
                    if (diffTime < 0.0) {
                        diffTime += Duration;
                    }
                    if (diffTime > 0.0) {
                        var factor = (float)((time - key.Time) / diffTime);
                        pPosition = key.Value + (nextKey.Value - key.Value) * factor;
                    } else {
                        pPosition = key.Value;
                    }
                    LastPositions[i].Item1 = frame;

                }
                // interpolate rotation keyframes
                var pRot = new Assimp.Quaternion(1, 0, 0, 0);
                if (channel.RotationKeys.Count > 0) {
                    var frame = (time >= LastTime) ? LastPositions[i].Item2 : 0;
                    while (frame < channel.RotationKeys.Count - 1) {
                        if (time < channel.RotationKeys[frame + 1].Time) {
                            break;
                        }
                        frame++;
                    }
                    if (frame >= channel.RotationKeys.Count) {
                        frame = 0;
                    }
                    var nextFrame = (frame + 1) % channel.RotationKeys.Count;

                    var key = channel.RotationKeys[frame];
                    var nextKey = channel.RotationKeys[nextFrame];
                    key.Value.Normalize();
                    nextKey.Value.Normalize();
                    var diffTime = nextKey.Time - key.Time;
                    if (diffTime < 0.0) {
                        diffTime += Duration;
                    }
                    if (diffTime > 0) {
                        var factor = (float)((time - key.Time) / diffTime);
                        pRot = Assimp.Quaternion.Slerp(key.Value, nextKey.Value, factor);
                    } else {
                        pRot = key.Value;
                    }
                    LastPositions[i].Item1= frame;

                }
                // interpolate scale keyframes
                var pscale = new Vector3D(1);
                if (channel.ScalingKeys.Count > 0) {
                    var frame = (time >= LastTime) ? LastPositions[i].Item3 : 0;
                    while (frame < channel.ScalingKeys.Count - 1) {
                        if (time < channel.ScalingKeys[frame + 1].Time) {
                            break;
                        }
                        frame++;
                    }
                    if (frame >= channel.ScalingKeys.Count) {
                        frame = 0;
                    }
                    LastPositions[i].Item3 = frame;
                }

                // create the combined transformation matrix
                var mat = new Matrix4x4(pRot.GetMatrix());
                mat.A1 *= pscale.X; mat.B1 *= pscale.X; mat.C1 *= pscale.X;
                mat.A2 *= pscale.Y; mat.B2 *= pscale.Y; mat.C2 *= pscale.Y;
                mat.A3 *= pscale.Z; mat.B3 *= pscale.Z; mat.C3 *= pscale.Z;
                mat.A4 = pPosition.X; mat.B4 = pPosition.Y; mat.C4 = pPosition.Z;

                // transpose to get DirectX style matrix
                mat.Transpose();
//.........这里部分代码省略.........
开发者ID:amitprakash07,项目名称:dx11,代码行数:101,代码来源:AnimEvaluator.cs

示例8: exportBone

        static void exportBone(BinaryWriter dest, MeshNode target,  Assimp.Scene scene, int boneID)
        {
            Assimp.Node node = target.node;

            exportString(dest, node.Name);
            if (node.Parent!=null)
                exportString(dest, node.Parent.Name);
            else
                exportString(dest, "");

            Matrix4x4 mat = new Matrix4x4(node.Transform.A1, node.Transform.A2, node.Transform.A3, node.Transform.A4, node.Transform.B1, node.Transform.B2, node.Transform.B3, node.Transform.B4, node.Transform.C1, node.Transform.C2, node.Transform.C3, node.Transform.C4, node.Transform.D1, node.Transform.D2, node.Transform.D3, node.Transform.D4);
            mat.Transpose();

            exportMatrix(dest, mat);

            Bone bone = target.bone;
            if (bone != null)
            {
                mat = new Matrix4x4(bone.OffsetMatrix.A1, bone.OffsetMatrix.A2, bone.OffsetMatrix.A3, bone.OffsetMatrix.A4, bone.OffsetMatrix.B1, bone.OffsetMatrix.B2, bone.OffsetMatrix.B3, bone.OffsetMatrix.B4, bone.OffsetMatrix.C1, bone.OffsetMatrix.C2, bone.OffsetMatrix.C3, bone.OffsetMatrix.C4, bone.OffsetMatrix.D1, bone.OffsetMatrix.D2, bone.OffsetMatrix.D3, bone.OffsetMatrix.D4);
                mat.Transpose();
            }
            else
                mat = Matrix4x4.Identity;

            exportMatrix(dest, mat);
        }
开发者ID:Relfos,项目名称:assimp_terra_exporter,代码行数:26,代码来源:Program.cs

示例9: Matrix4x4TransposeTest

        public void Matrix4x4TransposeTest()
        {
            var a = new Matrix4x4(new float[] { 
                                            1.0f, 2.0f, 3.0f, 4.0f,
                                            5.0f, 6.0f, 7.0f, 8.0f,
                                            9.0f, 10.0f, 11.0f, 12.0f,
                                            13.0f, 14.0f, 15.0f, 16.0f});

            var expectedResult = new Matrix4x4(new float[] { 
                                            1.0f, 5.0f, 9.0f, 13.0f,
                                            2.0f, 6.0f, 10.0f, 14.0f,
                                            3.0f, 7.0f, 11.0f, 15.0f,
                                            4.0f, 8.0f, 12.0f, 16.0f});

            a.Transpose();

            Assert.Equal<Matrix4x4>(expectedResult, a);
        }
开发者ID:richardhallett,项目名称:nml,代码行数:18,代码来源:Matrix4x4Tests.cs


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