static void AngleAxisRaw(Vector3 origin, float angle, Vector3 axis, Quaternion startRotation, BaseVectorDirection builtinDirection, float halfAxisLenght, Vector3 direction, bool showVectorLabel = !default(bool)) { Color temp = Gizmos.color; direction.Normalize(); Gizmos.color = new Color32(162, 0, 255, 255); Gizmos.DrawRay(origin - axis.normalized * halfAxisLenght, axis.normalized * halfAxisLenght * 2); GizmosForVector.DrawVector(origin - axis.normalized * halfAxisLenght, axis.normalized, halfAxisLenght * 2, Gizmos.color); Quaternion endRotation = Quaternion.AngleAxis(angle, axis); endRotation = endRotation * startRotation; // Slerp (origin, startRotation, endRotation, builtinDirection, halfAxisLenght, direction, showVectorLabel); InterpolateQuaternions(Quaternion.Slerp, origin, startRotation, endRotation, builtinDirection, halfAxisLenght, direction, showVectorLabel); Quaternion middle = Quaternion.Slerp(startRotation, endRotation, 0.5f); // DrawQuaternion (origin, middle, Color.yellow, 6, direction);//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GizmosForVector.ShowLabel(origin + middle * direction * halfAxisLenght, //* startRotation // System.Math.Round (Quaternion.Angle (startRotation, endRotation), 0) + "\xB0", Color.magenta); // System.Math.Round ((startRotation * Quaternion.Inverse (endRotation)).SignedAngle ()) + "\xB0", Color.magenta); System.Math.Round((Quaternion.Inverse(endRotation) * startRotation).SignedAngle()) + "\xB0", Color.magenta); //System.Math.Round ((angle), 2) + "\xB0", Color.magenta); //first * Quaternion.Inverse (second) Gizmos.color = temp; }
public static void Angle(Vector3 origin, Quaternion startRotation, Quaternion endRotation, Vector3 customDirection, float lenght = lenght6, bool showVectorLabel = !default(bool)) { //Slerp (origin, startRotation, endRotation, customDirection, lenght, showVectorLabel); InterpolateQuaternions(Quaternion.Slerp, origin, startRotation, endRotation, customVectorDirection, lenght, customDirection, showVectorLabel); GizmosForVector.ShowLabel(origin, "angle: " + System.Math.Round(Quaternion.Angle(startRotation, endRotation), 0) + "\xB0", new Color32(127, 0, 255, 255)); }
public static void Angle(Vector3 origin, Quaternion startRotation, Quaternion endRotation, BaseVectorDirection builtinDirection = default(BaseVectorDirection), float lenght = lenght6, bool showVectorLabel = !default(bool)) { Vector3 direction = ColorsAndDirections.GetBaseDirection(builtinDirection); InterpolateQuaternions(Quaternion.Slerp, origin, startRotation, endRotation, builtinDirection, lenght, direction, showVectorLabel); GizmosForVector.ShowLabel(origin, "angle: " + System.Math.Round(Quaternion.Angle(startRotation, endRotation), 0) + "\xB0", new Color32(127, 0, 255, 255)); }
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 DrawCoordinateSystem(Vector3 origin, Quaternion rotationOfCoordinateSystem, float axisLenght = 3) { GizmosForVector.DrawVector(origin, rotationOfCoordinateSystem * Vector3.right, axisLenght, Color.red, "x", Vector3.zero, false); GizmosForVector.DrawVector(origin, rotationOfCoordinateSystem * Vector3.up, axisLenght, Color.green, "y", Vector3.zero, false); GizmosForVector.DrawVector(origin, rotationOfCoordinateSystem * Vector3.forward, axisLenght, Color.blue, "z", Vector3.zero, false); }
public static void Inverse(Vector3 origin, Quaternion rotation, float lenght = lenght6, bool showVectorLabel = !default(bool)) { Quaternion inverseRotation = Quaternion.Inverse(rotation); Slerp(origin, Quaternion.identity, rotation, (BaseVectorDirection)6, lenght, right, showVectorLabel, "", "rotation"); Slerp(origin, Quaternion.identity, inverseRotation, (BaseVectorDirection)7, lenght, right, showVectorLabel, "", "inverseRotation"); float angle; Vector3 axis; rotation.ToAngleAxis(out angle, out axis); Vector3 cross = Vector3.Cross(axis, right); GizmosForVector.DrawPlane(origin, cross, lenght); }
public static void LookAt(Transform origin, Vector3 worldPosition, Vector3 worldUp = default(Vector3), float lenght = 5) { if (!origin) { return; } worldUp = worldUp == default(Vector3) ? Vector3.up : worldUp; Vector3 originV = origin.position; Vector3 forwardDirection = worldPosition - originV; GizmosForQuaternion.LookRotation(originV, forwardDirection, worldUp, lenght); GizmosForVector.ShowVectorValue(worldPosition, "worldPosition", worldPosition, Color.red); Color temp = Gizmos.color; Gizmos.color = Color.red; Gizmos.DrawSphere(worldPosition, 0.2f); Gizmos.color = temp; }
public static void Dot(Vector3 origin, Quaternion a, Quaternion b, float lenght = 5, bool showVectorLabel = !default(bool)) { Slerp(origin, a, b, (BaseVectorDirection)5, lenght, right, showVectorLabel); GizmosForVector.ShowLabel(origin, "dotProduct: " + System.Math.Round(Quaternion.Dot(a, b), 4), new Color32(0, 199, 29, 255)); }