Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RotKeyFrame"/> struct.
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="offset">The offset.</param>
 public RotKeyFrame(byte[] data, int offset)
 {
     Frame      = BitConverter.ToInt32(data, offset);
     Quaternion = new TkQuaternion(
         BitConverter.ToSingle(data, offset + 4),
         BitConverter.ToSingle(data, offset + 8),
         BitConverter.ToSingle(data, offset + 12),
         BitConverter.ToSingle(data, offset + 16)
         );
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the rotation quaternion.
        /// </summary>
        /// <param name="animationFrame">The animation frame.</param>
        /// <returns>TkQuaternion.</returns>
        public TkQuaternion GetRotationQuaternion(int animationFrame)
        {
            if (_bufferedRot == null)
            {
                for (int i = 0; i < _rotFrames.Count - 1; i++)
                {
                    if (animationFrame >= _rotFrames[i].Frame && _rotFrames[i + 1].Frame < animationFrame)
                    {
                        continue;
                    }

                    if (_rotFrames[i].Frame == animationFrame)
                    {
                        _bufferedRot = _rotFrames[i].Quaternion;
                        return(_bufferedRot.Value);
                    }

                    if (_rotFrames[i + 1].Frame == animationFrame)
                    {
                        _bufferedRot = _rotFrames[i + 1].Quaternion;
                        return(_bufferedRot.Value);
                    }

                    int dist = _rotFrames[i + 1].Frame - _rotFrames[i].Frame;
                    animationFrame = animationFrame - _rotFrames[i].Frame;
                    float mult = (animationFrame / (float)dist);

                    var curFrame = _rotFrames[i];
                    var nexFrame = _rotFrames[i + 1];

                    _bufferedRot = TkQuaternion.Slerp(curFrame.Quaternion, nexFrame.Quaternion, mult);
                    return(_bufferedRot.Value);
                }

                if (animationFrame >= _rotFrames[_rotFrames.Count - 1].Frame)
                {
                    return(_rotFrames[_rotFrames.Count - 1].Quaternion);
                }

                return(_rotFrames[0].Quaternion);
            }

            return(_bufferedRot.Value);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RotKeyFrame"/> struct.
 /// </summary>
 /// <param name="reader">The reader.</param>
 public RotKeyFrame(IBinaryReader reader)
 {
     Frame      = reader.Int32();
     Quaternion = new TkQuaternion(reader.Float(), reader.Float(), reader.Float(), reader.Float());
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RotKeyFrame"/> struct.
 /// </summary>
 /// <param name="rkf">The RKF.</param>
 public RotKeyFrame(RotKeyFrame rkf)
 {
     Frame      = rkf.Frame;
     Quaternion = rkf.Quaternion;
 }