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


C# Matrix4x4.ToMatrix方法代码示例

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


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

示例1: Evaluate


//.........这里部分代码省略.........
                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();
                bones[channel.Name].LocalTransform = mat.ToMatrix();
            }
            LastTime = time;
        }
开发者ID:amitprakash07,项目名称:dx11,代码行数:101,代码来源:AnimEvaluator.cs


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