Esempio n. 1
0
 public void SetPoseActive(AimPoser.Pose pose)
 {
     for (int i = 0; i < this.poses.Length; i++)
     {
         this.poses[i].SetAngleBuffer((this.poses[i] != pose) ? 0f : this.angleBuffer);
     }
 }
 private void Start()
 {
     AimPoser.Pose[] poses = this.aimPoser.poses;
     for (int i = 0; i < poses.Length; i++)
     {
         AimPoser.Pose pose = poses[i];
         base.GetComponent <Animation>()[pose.name].AddMixingTransform(this.recursiveMixingTransform, true);
     }
     this.aim.Disable();
     this.lookAt.Disable();
 }
        private void Pose()
        {
            Vector3 direction      = this.targetPosition - this.aim.solver.bones[0].transform.position;
            Vector3 localDirection = base.transform.InverseTransformDirection(direction);

            this.aimPose = this.aimPoser.GetPose(localDirection);
            if (this.aimPose != this.lastPose)
            {
                base.GetComponent <Animation>().CrossFade(this.aimPose.name);
                this.aimPoser.SetPoseActive(this.aimPose);
                this.lastPose = this.aimPose;
            }
        }
Esempio n. 4
0
        private void Pose()
        {
            // Get the aiming direction
            Vector3 direction = (targetPosition - aim.solver.bones[0].transform.position);
            // Getting the direction relative to the root transform
            Vector3 localDirection = transform.InverseTransformDirection(direction);

            // Get the Pose from AimPoser
            aimPose = aimPoser.GetPose(localDirection);

            // If the Pose has changed
            if (aimPose != lastPose)
            {
                // CrossFade to the new pose
                animation.CrossFade(aimPose.name);

                // Increase the angle buffer of the pose so we won't switch back too soon if the direction changes a bit
                aimPoser.SetPoseActive(aimPose);

                // Store the pose so we know if it changes
                lastPose = aimPose;
            }
        }
Esempio n. 5
0
        private static void DrawPose(AimPoser.Pose pose, Vector3 position, Quaternion rotation, Color color)
        {
            if (pose.pitch <= 0f || pose.yaw <= 0f)
            {
                return;
            }
            if (pose.direction == Vector3.zero)
            {
                return;
            }

            Handles.color = color;
            GUI.color     = color;

            Vector3 up = rotation * Vector3.up;
            Vector3 normalizedPoseDirection = pose.direction.normalized;
            Vector3 direction = rotation * normalizedPoseDirection;

            // Direction and label
            Handles.DrawLine(position, position + direction);
            Handles.ConeCap(0, position + direction, Quaternion.LookRotation(direction), 0.05f);
            Handles.Label(position + direction.normalized * 1.1f, pose.name);

            if (pose.yaw >= 180f && pose.pitch >= 180f)
            {
                Handles.color = Color.white;
                GUI.color     = Color.white;
                return;
            }

            Quaternion halfYaw = Quaternion.AngleAxis(pose.yaw, up);

            float   directionPitch = Vector3.Angle(up, direction);
            Vector3 crossRight     = halfYaw * Vector3.Cross(up, direction);
            Vector3 crossLeft      = Quaternion.Inverse(halfYaw) * Vector3.Cross(up, direction);

            bool isVertical = normalizedPoseDirection == Vector3.up || normalizedPoseDirection == Vector3.down;

            if (isVertical)
            {
                crossRight = halfYaw * Vector3.right;
                crossLeft  = Quaternion.Inverse(halfYaw) * Vector3.right;
            }

            float minPitch = Mathf.Clamp(directionPitch - pose.pitch, 0f, 180f);
            float maxPitch = Mathf.Clamp(directionPitch + pose.pitch, 0f, 180f);

            Quaternion upToCornerUpperRight = Quaternion.AngleAxis(minPitch, crossRight);
            Quaternion upToCornerLowerRight = Quaternion.AngleAxis(maxPitch, crossRight);
            Quaternion upToCornerUpperLeft  = Quaternion.AngleAxis(minPitch, crossLeft);
            Quaternion upToCornerLowerLeft  = Quaternion.AngleAxis(maxPitch, crossLeft);

            Vector3 toCornerUpperRight = upToCornerUpperRight * up;
            Vector3 toCornerLowerRight = upToCornerLowerRight * up;
            Vector3 toCornerUpperLeft  = upToCornerUpperLeft * up;
            Vector3 toCornerLowerLeft  = upToCornerLowerLeft * up;

            if (pose.yaw < 180f)
            {
                Handles.DrawLine(position, position + toCornerUpperRight);
                Handles.DrawLine(position, position + toCornerUpperLeft);

                Handles.DrawLine(position, position + toCornerLowerRight);
                Handles.DrawLine(position, position + toCornerLowerLeft);
            }

            Vector3 d = direction;

            if (isVertical)
            {
                d = Vector3.forward;
            }

            if (pose.pitch < 180f)
            {
                DrawPolyLineOnSphere(position, toCornerUpperLeft, toCornerUpperRight, d, Vector3.up, color);
                DrawPolyLineOnSphere(position, toCornerLowerLeft, toCornerLowerRight, d, Vector3.up, color);
            }

            if (pose.yaw < 180f)
            {
                DrawPolyLineOnSphere(position, toCornerUpperLeft, toCornerLowerLeft, Quaternion.Inverse(halfYaw) * d, crossLeft, color);
                DrawPolyLineOnSphere(position, toCornerUpperRight, toCornerLowerRight, halfYaw * d, crossRight, color);
            }

            Handles.color = Color.white;
            GUI.color     = Color.white;
        }