Beispiel #1
0
        static void DrawRotateGizmo(Transform objectToRotate, Vector3 point, float angle, Vector3 axis, float halfAxisLenght, float offset, bool showPoints)
        {
            if (!objectToRotate)
            {
                return;
            }

            Vector3 binormal = Vector3.zero;
            Vector3 tangent  = Vector3.zero;

            Vector3.OrthoNormalize(ref axis, ref binormal, ref tangent);

            Vector3 directionFromPointToObject = point - objectToRotate.position;

            Vector3    distanceBetweenPointAndPivotBelongAxis = Vector3.Project(directionFromPointToObject, axis.normalized);
            Vector3    pivot         = point - distanceBetweenPointAndPivotBelongAxis;
            Quaternion pendicularQ0  = Quaternion.AngleAxis(0, -axis.normalized);
            Quaternion pendicularQ90 = Quaternion.AngleAxis(90, -axis.normalized);


            float             radius     = (objectToRotate.position - pivot).magnitude + offset;
            Vector3           dir        = axis.normalized;
            Color             startColor = ColorsAndDirections.GetColors((BaseVectorDirection)0) [0];
            Color             endColor   = ColorsAndDirections.GetColors((BaseVectorDirection)7) [1];
            int               iterations = 200;
            List <Quaternion> points     = new List <Quaternion> (iterations);
            List <Color>      colors     = new List <Color> (iterations);

            Vector3 direction = binormal;

            Gizmos.DrawRay(pivot - axis.normalized * halfAxisLenght * halfAxisLenght, axis.normalized * halfAxisLenght * halfAxisLenght * 2);

            for (int i = 0; i < iterations; i++)
            {
                float t = i * 4 / (float)iterations;
                points.Add(Quaternion.SlerpUnclamped(pendicularQ0, pendicularQ0 * pendicularQ90, t));
                colors.Add(Color.Lerp(startColor, endColor, t * 0.25f));
            }
            for (int i = 0; i < iterations - 1; i++)
            {
                if (i % 2 == 0)
                {
                    Gizmos.color = colors [i];
                    Gizmos.DrawLine(pivot + points [i] * direction * radius, pivot + points [i + 1] * direction * radius);
                }
            }
            if (showPoints)
            {
                GizmosForVector.ShowVectorValue(point, "point", point, Color.red);
                GizmosForVector.ShowVectorValue(pivot, "pivot", pivot, Color.green);
                Gizmos.color = Color.red;
                Gizmos.DrawSphere(point, 0.2f);
                Gizmos.color = Color.green;
                Gizmos.DrawSphere(pivot, 0.2f);
            }
        }
        public static void SlerpUnclampedRaw(Vector3 origin, Quaternion startRotation, Quaternion endRotation,
                                             float howFuther, BaseVectorDirection builtinDirection = default(BaseVectorDirection),
                                             float lenght = lenght6, Vector3 direction = default(Vector3), bool showVectorLabel = !default(bool))
        {
            float   angle;
            Vector3 axis;
//			Quaternion sub = startRotation.Substraction (endRotation);
            Quaternion sub = startRotation * Quaternion.Inverse(endRotation);

            sub.ToAngleAxis(out angle, out axis);

            float halfAxisLenght = lenght * 0.5f;

            Gizmos.DrawRay(origin - axis.normalized * halfAxisLenght, axis.normalized * halfAxisLenght * 2);
            //Vector3	direction = ColorsAndDirections.GetBaseDirection (builtinDirection);
            //	directionn = (directionn == Vector3.zero) ? Vector3.right : directionn.normalized;///w bok

            direction = (direction == Vector3.zero) ? Vector3.right : direction.normalized;
            Color startColor = ColorsAndDirections.GetColors(builtinDirection) [0];
            Color endColor   = ColorsAndDirections.GetColors(builtinDirection) [1];

            DrawQuaternion(origin, startRotation, startColor, lenght, direction, showVectorLabel, "start");
            DrawQuaternion(origin, endRotation, endColor, lenght, direction, showVectorLabel, "end");
            Color finishColor = (builtinDirection == customVectorDirection) ? (Color) new Color32(0, 174, 219, 255) : ColorsAndDirections.GetColors((BaseVectorDirection)7) [1];

            DrawQuaternion(origin, Quaternion.SlerpUnclamped(startRotation, endRotation, howFuther), finishColor, lenght, direction, showVectorLabel, "howFuther: " + howFuther + "\nfinal Position: ");

            Quaternion pendicularQ0  = Quaternion.AngleAxis(0, axis);
            Quaternion pendicularQ90 = Quaternion.AngleAxis(90, axis);

            pendicularQ0  *= startRotation;
            pendicularQ90 *= startRotation;
            int iterations           = 200;
            List <Quaternion> points = new List <Quaternion> (iterations);
            List <Color>      colors = new List <Color> (iterations);

            for (int i = 0; i < iterations; i++)
            {
                float t = i * 4 / (float)iterations;
                points.Add(Quaternion.SlerpUnclamped(pendicularQ0, pendicularQ90, t));
                colors.Add(Color.Lerp(startColor, endColor, t * 0.25f));
            }
            for (int i = 0; i < iterations - 1; i++)
            {
                if (i % 2 == 0)
                {
                    Gizmos.color = colors [i];
                    Gizmos.DrawLine(points [i] * direction * lenght + origin, points [i + 1] * direction * lenght + origin);
                }
            }
        }
        static void InterpolateQuaternions(System.Func <Quaternion, Quaternion, float, Quaternion> func, Vector3 origin, Quaternion startRotation, Quaternion endRotation,
                                           BaseVectorDirection builtinDirection = default(BaseVectorDirection),
                                           float lenght = lenght6, Vector3 direction = default(Vector3), bool showVectorLabel = default(bool), string name1 = "", string name2 = "")
        {
            Color temp       = Gizmos.color;
            int   iterations = 100;

            direction = (direction == Vector3.zero) ? Vector3.right : direction.normalized;
            Color startColor = ColorsAndDirections.GetColors(builtinDirection) [0];
            Color endColor   = ColorsAndDirections.GetColors(builtinDirection) [1];

            DrawQuaternion(origin, startRotation, startColor, lenght, direction, showVectorLabel, name1);
            DrawQuaternion(origin, endRotation, endColor, lenght, direction, showVectorLabel, name2);
            DrawDotsConnectingQuaternions(func, origin, startRotation, endRotation, lenght, direction, iterations, startColor, endColor);
            Gizmos.color = temp;
            ;
        }
        static void InterpolateQuaternionsForLerp(System.Func <Quaternion, Quaternion, float, Quaternion> func, Vector3 origin, Quaternion startRotation, Quaternion endRotation, float t,
                                                  BaseVectorDirection builtinDirection = default(BaseVectorDirection),
                                                  float lenght = lenght6, Vector3 direction = default(Vector3), bool showVectorLabel = default(bool), string name1 = "", string name2 = "")
        {
            Color temp       = Gizmos.color;
            int   iterations = 100;

            direction = (direction == Vector3.zero) ? Vector3.right : direction.normalized;
            Color      startColor     = ColorsAndDirections.GetColors(builtinDirection)[0];
            Color      endColor       = ColorsAndDirections.GetColors(builtinDirection)[1];
            Quaternion middleRotation = func(startRotation, endRotation, t);


            DrawQuaternion(origin, startRotation, startColor, lenght, direction, false, "a:");
            DrawQuaternion(origin, middleRotation, Color.magenta, lenght, direction, false, "Interpolated for t = " + System.Math.Round(t, 2) + " :");
            DrawQuaternion(origin, endRotation, endColor, lenght, direction, false, "b:");
            DrawDotsConnectingQuaternions(func, origin, startRotation, middleRotation, lenght, direction, iterations, Color.magenta, Color.magenta);
            DrawDotsConnectingQuaternions(func, origin, middleRotation, endRotation, lenght, direction, iterations, startColor, endColor);

            Gizmos.color = temp;
            ;
        }
Beispiel #5
0
        static void VisualizeRotateTowardsRaw(Vector3 origin, Vector3 current, Vector3 target,
                                              BaseVectorDirection builtinDirection = default(BaseVectorDirection), float lenght = 6,
                                              Vector3 direction = default(Vector3), bool showPlane = default(bool))
        {
            Color temp = Gizmos.color;

            direction = (direction == Vector3.zero) ? Vector3.right : direction.normalized;
            Color          startColor = ColorsAndDirections.GetColors((BaseVectorDirection)4) [0];
            Color          endColor   = ColorsAndDirections.GetColors((BaseVectorDirection)4) [1];
            int            iterations = 100;
            List <Vector3> points     = new List <Vector3> (iterations);
            List <Color>   colors     = new List <Color> (iterations);

            for (int i = 0; i < iterations; i++)
            {
                float t = i / (float)iterations;
                points.Add(Vector3.Slerp(current.normalized * lenght, target.normalized * lenght, t));
                colors.Add(Color.Lerp(startColor, endColor, t));
            }
            for (int i = 0; i < iterations - 1; i++)
            {
                if (i % 2 == 0)
                {
                    Gizmos.color = colors [i];
                    Gizmos.DrawLine(points [i] + origin, points [i + 1] + origin);
                }
            }
            if (showPlane)
            {
                Vector3 normal = Vector3.Cross(current, target);
                if (normal.magnitude > 0f)
                {
                    DrawPlane(origin, normal, lenght);
                }
            }

            DrawVector(origin, current, lenght, startColor);
            DrawVector(origin, target, lenght, endColor);
        }