Exemplo n.º 1
0
        public void UpdateMatrix(uint time, int animation, out Matrix matrix,
                                 M2Animator animator, BillboardParameters billboard)
        {
            var boneMatrix = Matrix.Identity;

            if (IsBillboarded && billboard != null)
            {
                var billboardMatrix = Matrix.Identity;
                billboardMatrix.Row1 = new Vector4(billboard.Forward, 0);
                billboardMatrix.Row2 = new Vector4(billboard.Right, 0);
                billboardMatrix.Row3 = new Vector4(billboard.Up, 0);
                boneMatrix           = billboardMatrix * billboard.InverseRotation;
            }

            if (IsTransformed)
            {
                var position = mTranslation.GetValue(animation, time, animator.AnimationLength);
                var scaling  = mScaling.GetValue(animation, time, animator.AnimationLength);
                var rotation = mRotation.GetValue(animation, time, animator.AnimationLength);
                boneMatrix *= Matrix.RotationQuaternion(rotation) * Matrix.Scaling(scaling) * Matrix.Translation(position);
            }

            boneMatrix = mInvPivot * boneMatrix * mPivot;

            if (mBone.parentBone >= 0)
            {
                boneMatrix *= animator.GetBoneMatrix(time, mBone.parentBone, billboard);
            }

            matrix = boneMatrix;
        }
Exemplo n.º 2
0
        public void UpdateMatrix(uint time, int animation, out Matrix matrix, M2Animator animator)
        {
            var position = mTranslation.GetValue(animation, time, animator.AnimationLength);
            var scaling  = mScaling.GetValue(animation, time, animator.AnimationLength);
            var rotation = mRotation.GetValue(animation, time, animator.AnimationLength);

            var boneMatrix = Matrix.RotationQuaternion(rotation) *
                             Matrix.Scaling(scaling) * Matrix.Translation(position);

            var billboard = (Bone.flags & 0x08) != 0;

            if (billboard)
            {
                // Should really get this from somewhere else...
                var camera = WorldFrame.Instance.ActiveCamera;

                boneMatrix.M11 = camera.Forward.X;
                boneMatrix.M12 = camera.Forward.Y;
                boneMatrix.M13 = camera.Forward.Z;

                boneMatrix.M21 = camera.Right.X;
                boneMatrix.M22 = camera.Right.Y;
                boneMatrix.M23 = camera.Right.Z;

                boneMatrix.M31 = camera.Up.X;
                boneMatrix.M32 = camera.Up.Y;
                boneMatrix.M33 = camera.Up.Z;

                // TODO: Must not rotate this bone with the
                // instance matrix in case billboarding was applied
            }

            boneMatrix = mInvPivot * boneMatrix * mPivot;

            if (Bone.parentBone >= 0)
            {
                boneMatrix *= animator.GetBoneMatrix(time, Bone.parentBone);
            }

            matrix = boneMatrix;
        }