private void Awake() { CameraEvents.OnPostRenderEvent.AddListener(OnPostRender); for (int i = 0, c = Rotations.Count; i < c; ++i) { QuaternionObject element = Rotations[i]; element.Panel.SetSphereColor(element.color); } }
public void Update() { Quaternion result = Quaternion.identity; Vector3 eulerResult = Vector3.zero; for (int i = 0, c = Rotations.Count; i < c; ++i) { QuaternionObject element = Rotations[i]; UpdateElement(element); result *= element.Target.rotation; eulerResult += element.Target.eulerAngles; } Target.rotation = result; TargetEuler.eulerAngles = eulerResult; }
public void UpdateElement(QuaternionObject element) { Quaternion elementRotation; switch (element.Panel.GetMode()) { case RotationMode.Euler: if (element.Panel.GetInverse()) { elementRotation = Quaternion.Inverse(Quaternion.Euler(element.Panel.GetVector())); } else { elementRotation = Quaternion.Euler(element.Panel.GetVector()); } element.Target.rotation = elementRotation; break; case RotationMode.AngleAxis: if (element.Panel.GetInverse()) { elementRotation = Quaternion.Inverse(Quaternion.AngleAxis(element.Panel.GetFloat(), element.Panel.GetVector())); } else { elementRotation = Quaternion.AngleAxis(element.Panel.GetFloat(), element.Panel.GetVector()); } element.Target.rotation = elementRotation; break; case RotationMode.LookRotation: if (element.Panel.GetInverse()) { elementRotation = Quaternion.Inverse(Quaternion.LookRotation(element.Panel.GetVector())); } else { elementRotation = Quaternion.LookRotation(element.Panel.GetVector()); } element.Target.rotation = elementRotation; element.Panel.sphere.transform.position = element.Target.position + element.Panel.GetVector(); break; } }
public void OnPostRender() { CreateLineMaterial(); Quaternion result = Quaternion.identity; lineMaterial.SetPass(0); //Draw the Quaternion Result GL.PushMatrix(); GL.MultMatrix(Matrix4x4.TRS(Target.position, Quaternion.identity, Target.lossyScale)); GL.Begin(GL.TRIANGLE_STRIP); for (int i = 0, c = Rotations.Count; i < c; ++i) { QuaternionObject element = Rotations[i]; GL.Color(element.color); Quaternion beforeRotation = result; result *= element.Target.rotation; DrawInterpolatedQuaternion(beforeRotation, result); } GL.End(); GL.PopMatrix(); //Draw the Euler Result GL.PushMatrix(); GL.MultMatrix(Matrix4x4.TRS(TargetEuler.position, Quaternion.identity, Target.lossyScale)); GL.Begin(GL.TRIANGLE_STRIP); Vector3 eulerResult = Vector3.zero; for (int i = 0, c = Rotations.Count; i < c; ++i) { QuaternionObject element = Rotations[i]; GL.Color(element.color); Quaternion beforeRotation = Quaternion.Euler(eulerResult); eulerResult += element.Target.eulerAngles; DrawInterpolatedQuaternion(beforeRotation, Quaternion.Euler(eulerResult)); } GL.End(); GL.PopMatrix(); //Draw the component results for (int i = 0, c = Rotations.Count; i < c; ++i) { QuaternionObject element = Rotations[i]; GL.PushMatrix(); GL.MultMatrix(Matrix4x4.TRS(element.Target.position, Quaternion.identity, Target.lossyScale)); GL.Begin(GL.TRIANGLE_STRIP); GL.Color(element.color); Quaternion elementRotation; elementRotation = element.Target.rotation; DrawInterpolatedQuaternion(Quaternion.identity, elementRotation); GL.End(); GL.PopMatrix(); } }