Example #1
0
        /// <summary>
        /// To update the position of the bones to the specified frame number
        /// </summary>
        /// <param name="frameNumber">The current frame number</param>
        public void ReviseBone(float frameNumber)
        {
            // 現在のフレームの前後のキーフレームを探す
            MMDFileParser.IFrameData pastFrame, futureFrame;
            this.frameManager.SearchKeyFrame(frameNumber, out pastFrame, out futureFrame);
            var pastBoneFrame   = (BoneFrameData)pastFrame;
            var futureBoneFrame = (BoneFrameData)futureFrame;

            // 現在のフレームの前後キーフレーム間での進行度を求めてペジェ関数で変換する
            float s = (futureBoneFrame.FrameNumber == pastBoneFrame.FrameNumber) ? 0 :
                      (float)(frameNumber - pastBoneFrame.FrameNumber) / (float)(futureBoneFrame.FrameNumber - pastBoneFrame.FrameNumber); // 進行度
            var ss = new float[4];

            for (int i = 0; i < ss.Length; ++i)
            {
                ss[i] = pastBoneFrame.Curves[i].Evaluate(s);
            }

            // ボーンを更新する
            this.bone.Translation = CGHelper.ComplementTranslate(pastBoneFrame, futureBoneFrame, new Vector3(ss[0], ss[1], ss[2]));
            this.bone.Rotation    = CGHelper.ComplementRotateQuaternion(pastBoneFrame, futureBoneFrame, ss[3]);
        }
        private void LeapFrame(CameraFrameData cf1, CameraFrameData cf2, CameraProvider cp, IProjectionMatrixProvider proj, float f)
        {
            float ProgX, ProgY, ProgZ, ProgR, ProgL, ProgP;;

            ProgX           = cf1.Curves[0].Evaluate(f);
            ProgY           = cf1.Curves[1].Evaluate(f);
            ProgZ           = cf1.Curves[2].Evaluate(f);
            ProgR           = cf1.Curves[3].Evaluate(f);
            ProgL           = cf1.Curves[4].Evaluate(f);
            ProgP           = cf1.Curves[5].Evaluate(f);
            cp.CameraLookAt = CGHelper.ComplementTranslate(cf1, cf2,
                                                           new Vector3(ProgX, ProgY, ProgZ));
            Quaternion rotation = CGHelper.ComplementRotateQuaternion(cf1, cf2,
                                                                      ProgR);
            float   length          = CGHelper.Lerp(cf1.Distance, cf2.Distance, ProgL);
            float   angle           = CGHelper.Lerp(cf1.ViewAngle, cf2.ViewAngle, ProgP);
            Vector3 Position2target = Vector3.TransformCoordinate(new Vector3(0, 0, 1),
                                                                  Matrix.RotationQuaternion(rotation));
            Vector3 TargetPosition = cp.CameraLookAt + length * Position2target;

            cp.CameraPosition = TargetPosition;
            proj.Fovy         = CGHelper.ToRadians(angle);
        }