public void Bind(AnimatedModel m)
        {
            this.model           = m;
            this.sprintAnimation = m["Sprint"];
            this.runAnimation    = m["Run"];
            this.fallAnimation   = m["Fall"];

            m["Idle"].GetChannel(m.GetBoneIndex("ORG-spine")).Filter = delegate(Matrix spine)
            {
                float x;
                if (this.idleRotationBlend < 1.0f)
                {
                    x = (this.Rotation - this.idleRotation.ClosestAngle(this.Rotation)) * Math.Max(0.0f, 1.0f - this.idleRotationBlend);
                }
                else if (this.idling)
                {
                    x = this.Rotation - this.idleRotation.ClosestAngle(this.Rotation);
                }
                else
                {
                    x = 0.0f;
                }
                return(spine * Matrix.CreateRotationY(x));
            };

            m["Idle"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter = delegate(Matrix hips)
            {
                float x;
                if (this.idleRotationBlend < 1.0f)
                {
                    x = (this.idleRotation.ClosestAngle(this.Rotation) - this.Rotation) * Math.Max(0.0f, 1.0f - this.idleRotationBlend);
                }
                else if (this.idling)
                {
                    x = this.idleRotation.ClosestAngle(this.Rotation) - this.Rotation;
                }
                else
                {
                    x = 0.0f;
                }
                return(hips * Matrix.CreateRotationZ(x));
            };

            this.relativeHeadBone  = m.GetRelativeBoneTransform("ORG-head");
            m["Swim"].Speed        = 2.0f;
            m["SwimForward"].Speed = 2.0f;
            m["TurnLeft"].Speed    = 2.0f;
            m["TurnRight"].Speed   = 2.0f;

            m["WallRunStraight"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter = delegate(Matrix hips)
            {
                hips.Translation += new Vector3(0, 1, 0);
                return(hips);
            };
        }
Пример #2
0
 // Animated model
 public void Bind(AnimatedModel m)
 {
     this.model         = m;
     m["Land"].Strength = m["Land"].TargetStrength = 0.7f;
     this.landAnimation = m["LandHard"];
     this.landAnimation.GetChannel(m.GetBoneIndex("ORG-hips")).Filter = delegate(Matrix hips)
     {
         float t = (float)this.landAnimation.CurrentTime.TotalSeconds;
         hips.Translation += new Vector3(0, Math.Max(0.0f, 1.0f - (t > 0.75f ? t - 0.75f : 0)), 0);
         return(hips);
     };
     this.landAnimation.Speed = 1.5f;
 }
Пример #3
0
        public void Bind(AnimatedModel m)
        {
            Func <Matrix, Matrix> filter = delegate(Matrix mat)
            {
                mat.Translation = new Vector3(0.0f, 0.2f, 2.0f);
                return(mat);
            };

            m["Jump"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter         = filter;
            m["Jump02"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter       = filter;
            m["Jump03"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter       = filter;
            m["JumpLeft"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter     = filter;
            m["JumpRight"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter    = filter;
            m["JumpBackward"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter = filter;
            m["Fall"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter         = filter;
            this.model = m;
        }
Пример #4
0
        public void Bind(AnimatedModel m)
        {
            this.model           = m;
            this.sprintAnimation = m["Sprint"];
            this.runAnimation    = m["Run"];
            this.fallAnimation   = m["Fall"];

            m["Idle"].GetChannel(m.GetBoneIndex("ORG-spine")).Filter = delegate(Matrix spine)
            {
                float x;
                if (this.idleRotationBlend < 1.0f)
                {
                    x = (this.Rotation - this.idleRotation.ClosestAngle(this.Rotation)) * Math.Max(0.0f, 1.0f - this.idleRotationBlend);
                }
                else if (this.idling)
                {
                    x = this.Rotation - this.idleRotation.ClosestAngle(this.Rotation);
                }
                else
                {
                    x = 0.0f;
                }
                return(spine * Matrix.CreateRotationY(x));
            };

            int    headIndex    = m.GetBoneIndex("ORG-head");
            Matrix headBindPose = m.GetWorldBindTransform(headIndex) * Matrix.CreateTranslation(0, 0.1f, 0.25f);
            Func <SkinnedModel.Clip, Func <Matrix, Matrix> > cancelHeadBob = delegate(SkinnedModel.Clip clip)
            {
                int bone = headIndex;
                List <SkinnedModel.Channel> channels = new List <SkinnedModel.Channel>();
                channels.Add(new SkinnedModel.Channel {
                    BoneIndex = bone
                });
                while (true)
                {
                    int parent = m.SkeletonHierarchy[bone];
                    if (parent == -1)
                    {
                        break;
                    }
                    else
                    {
                        channels.Add(clip.GetChannel(parent) ?? new SkinnedModel.Channel {
                            BoneIndex = bone
                        });
                    }
                    bone = parent;
                }
                return(delegate(Matrix x)
                {
                    if (main.MinimizeCameraMovement)
                    {
                        Matrix world = Matrix.Identity;
                        for (int i = 0; i < channels.Count; i++)
                        {
                            SkinnedModel.Channel channel = channels[i];
                            if (channel.Count == 0)
                            {
                                world = world * m.BindPose[channel.BoneIndex];
                            }
                            else
                            {
                                world = world * channel.CurrentMatrix;
                            }
                        }
                        return headBindPose * Matrix.Invert(world);
                    }
                    else
                    {
                        return x;
                    }
                });
            };

            int cameraIndex = m.GetBoneIndex("Camera");
            Func <SkinnedModel.Clip, Func <Matrix, Matrix> > cancelRotation = delegate(SkinnedModel.Clip clip)
            {
                int bone = cameraIndex;
                List <SkinnedModel.Channel> channels = new List <SkinnedModel.Channel>();
                channels.Add(new SkinnedModel.Channel {
                    BoneIndex = bone
                });
                while (true)
                {
                    int parent = m.SkeletonHierarchy[bone];
                    if (parent == -1)
                    {
                        break;
                    }
                    else
                    {
                        channels.Add(clip.GetChannel(parent) ?? new SkinnedModel.Channel {
                            BoneIndex = bone
                        });
                    }
                    bone = parent;
                }
                return(delegate(Matrix x)
                {
                    if (
#if VR
                        this.main.VR ||
#endif
                        this.main.MinimizeCameraMovement)
                    {
                        Matrix world = Matrix.Identity;
                        for (int i = 0; i < channels.Count; i++)
                        {
                            SkinnedModel.Channel channel = channels[i];
                            if (channel.Count == 0)
                            {
                                world = world * m.BindPose[channel.BoneIndex];
                            }
                            else
                            {
                                world = world * channel.CurrentMatrix;
                            }
                        }
                        Matrix rot = Matrix.Invert(world) * Matrix.CreateRotationX((float)Math.PI * 0.5f);
                        rot.Translation = x.Translation;
                        return rot;
                    }
                    else
                    {
                        return x;
                    }
                });
            };

            m["Run"].GetChannel(headIndex).Filter             = cancelHeadBob(m["Run"]);
            m["RunLeft"].GetChannel(headIndex).Filter         = cancelHeadBob(m["RunLeft"]);
            m["RunRight"].GetChannel(headIndex).Filter        = cancelHeadBob(m["RunRight"]);
            m["RunLeftForward"].GetChannel(headIndex).Filter  = cancelHeadBob(m["RunLeftForward"]);
            m["RunRightForward"].GetChannel(headIndex).Filter = cancelHeadBob(m["RunRightForward"]);
            m["Sprint"].GetChannel(headIndex).Filter          = cancelHeadBob(m["Sprint"]);
            m["Slide"].GetChannel(cameraIndex).Filter         = cancelRotation(m["Slide"]);
            m["WallRunLeft"].GetChannel(cameraIndex).Filter   = cancelRotation(m["WallRunLeft"]);
            m["WallRunRight"].GetChannel(cameraIndex).Filter  = cancelRotation(m["WallRunRight"]);
            m["TopOut"].GetChannel(cameraIndex).Filter        = cancelRotation(m["TopOut"]);
            m["Land"].GetChannel(cameraIndex).Filter          = cancelRotation(m["Land"]);
            m["LandHard"].GetChannel(cameraIndex).Filter      = cancelRotation(m["LandHard"]);

            m["Idle"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter = delegate(Matrix hips)
            {
                float x;
                if (this.idleRotationBlend < 1.0f)
                {
                    x = (this.idleRotation.ClosestAngle(this.Rotation) - this.Rotation) * Math.Max(0.0f, 1.0f - this.idleRotationBlend);
                }
                else if (this.idling)
                {
                    x = this.idleRotation.ClosestAngle(this.Rotation) - this.Rotation;
                }
                else
                {
                    x = 0.0f;
                }
                return(hips * Matrix.CreateRotationZ(x));
            };

            this.relativeHeadBone  = m.GetRelativeBoneTransform("ORG-head");
            m["Swim"].Speed        = 2.0f;
            m["SwimForward"].Speed = 2.0f;
            m["TurnLeft"].Speed    = 2.0f;
            m["TurnRight"].Speed   = 2.0f;

            m["WallRunStraight"].GetChannel(m.GetBoneIndex("ORG-hips")).Filter = delegate(Matrix hips)
            {
                hips.Translation += new Vector3(0, 1, 0);
                return(hips);
            };
        }