Ejemplo n.º 1
0
        // This is fast animation blending, but it creates broken blended states. So correctness goees above performance I guess.

        /*{
         *  bool first = true;
         *
         *  for (int i = 0; i < curAnimCount; i++)
         *  {
         *      RunningAnimation anim = curAnims[i];
         *
         *      cheapMatrixLerp(anim, first);
         *      first = false;
         *  }
         * }*/


        /*protected void cheapMatrixLerp(RunningAnimation anim, bool first)
         * {
         *  try
         *  {
         *      AnimationFrame curFrame = anim.Animation.AllFrames[(int)anim.CurrentFrame % anim.Animation.AllFrames.Length];
         *      AnimationFrame nextFrame = anim.Animation.AllFrames[((int)anim.CurrentFrame + 1) % anim.Animation.AllFrames.Length];
         *
         *      float l = anim.CurrentFrame - (int)anim.CurrentFrame;
         *
         *      if (first)
         *      {
         *          for (int i = 0; i < TransformationMatrices.Length; i++)
         *          {
         *              TransformationMatrices[i] = curFrame.transformationMatrices[i] * (1 - l) + nextFrame.transformationMatrices[i] * (l);
         *          }
         *      }
         *      else
         *      {
         *          for (int i = 0; i < TransformationMatrices.Length; i++)
         *          {
         *              TransformationMatrices[i] += curFrame.transformationMatrices[i] * (1 - l) + nextFrame.transformationMatrices[i] * (l);
         *          }
         *      }
         *  } catch (Exception e)
         *  {
         *      string str = string.Format("Something crashed while trying to calculate an animation frame for {0}. AllFrames.Length={1}, currframee={2}, tf mats length={3}. Exception: {4}", entity?.Code, anim.Animation.AllFrames.Length,  anim.CurrentFrame, TransformationMatrices.Length, e);
         *      throw new Exception(str);
         *  }
         * }*/


        public AttachmentPointAndPose GetAttachmentPointPose(string code)
        {
            AttachmentPointAndPose apap = null;

            AttachmentPointByCode.TryGetValue(code, out apap);
            return(apap);
        }
Ejemplo n.º 2
0
        void updateLocalEyePosImmersiveFpMode()
        {
            AttachmentPointAndPose apap = AnimManager.Animator.GetAttachmentPointPose("Eyes");
            AttachmentPoint        ap   = apap.AttachPoint;

            float[] ModelMat    = Mat4f.Create();
            Matrixf tmpModelMat = new Matrixf();

            float bodyYaw   = BodyYaw;
            float rotX      = Properties.Client.Shape != null ? Properties.Client.Shape.rotateX : 0;
            float rotY      = Properties.Client.Shape != null ? Properties.Client.Shape.rotateY : 0;
            float rotZ      = Properties.Client.Shape != null ? Properties.Client.Shape.rotateZ : 0;
            float bodyPitch = WalkPitch;

            float lookOffset = (SidedPos.Pitch - GameMath.PI) / 9f;

            bool wasHoldPos = holdPosition;

            holdPosition = false;

            for (int i = 0; i < AnimManager.Animator.RunningAnimations.Length; i++)
            {
                RunningAnimation anim = AnimManager.Animator.RunningAnimations[i];
                if (anim.Running && anim.EasingFactor > anim.meta.HoldEyePosAfterEasein)
                {
                    if (!wasHoldPos)
                    {
                        prevAnimModelMatrix = (float[])apap.AnimModelMatrix.Clone();
                    }
                    holdPosition = true;
                    break;
                }
            }


            tmpModelMat
            .Set(ModelMat)
            .RotateX(SidedPos.Roll + rotX * GameMath.DEG2RAD)
            .RotateY(bodyYaw + (180 + rotY) * GameMath.DEG2RAD)
            .RotateZ(bodyPitch + rotZ * GameMath.DEG2RAD)
            .Mul(holdPosition ? prevAnimModelMatrix : apap.AnimModelMatrix)
            .Scale(Properties.Client.Size, Properties.Client.Size, Properties.Client.Size)
            .Translate(-0.5f, 0, -0.5f)
            .Translate(ap.PosX / 16f - lookOffset, ap.PosY / 16f - lookOffset / 1.3f, ap.PosZ / 16f)
            ;

            float[] pos = new float[4] {
                0, 0, 0, 1
            };
            float[] endVec = Mat4f.MulWithVec4(tmpModelMat.Values, pos);

            LocalEyePos.Set(endVec[0], endVec[1], endVec[2]);
        }