/// <summary> /// Initializes the quaternion so that it orients an object so it faces in te provided direction. /// </summary> /// <param name="forward">Direction to orient the object towards.</param> /// <param name="up">Axis that determines the upward direction of the object.</param> public void SetLookRotation(Vector3 forward, Vector3 up) { Vector3 forwardNrm = Vector3.Normalize(forward); Vector3 upNrm = Vector3.Normalize(up); if (MathEx.ApproxEquals(Vector3.Dot(forwardNrm, upNrm), 1.0f)) { SetLookRotation(forwardNrm); return; } Vector3 x = Vector3.Cross(forwardNrm, upNrm); Vector3 y = Vector3.Cross(x, forwardNrm); x.Normalize(); y.Normalize(); this = Quaternion.FromAxes(x, y, -forwardNrm); }