本文整理汇总了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;
}