···11+// Copyright 2020, Collabora, Ltd.
22+// SPDX-License-Identifier: BSL-1.0
33+/*!
44+ * @file
55+ * @brief Code to handle distortion parameters and fov.
66+ * @author Jakob Bornecrantz <jakob@collabora.com>
77+ * @ingroup aux_distortion
88+ */
99+1010+#pragma once
1111+1212+#include "xrt/xrt_defines.h"
1313+1414+1515+#ifdef __cplusplus
1616+extern "C" {
1717+#endif
1818+1919+2020+struct xrt_hmd_parts;
2121+2222+/*!
2323+ * @defgroup aux_distortion Distortion utilities.
2424+ * @ingroup aux_util
2525+ */
2626+2727+/*!
2828+ * These are the values that you need to supply to the distortion code to setup
2929+ * a @ref u_cardboard_distortion properly.
3030+ *
3131+ * @ingroup aux_distortion
3232+ */
3333+struct u_cardboard_distortion_arguments
3434+{
3535+ float distortion_k[5];
3636+3737+ struct
3838+ {
3939+ uint32_t w_pixels, h_pixels;
4040+ float w_meters, h_meters;
4141+ } screen;
4242+4343+ //! Distances between the lenses in meters.
4444+ float inter_lens_distance_meters;
4545+4646+ //! Where on the y axis the center of the lens is on the screen.
4747+ float lens_y_center_on_screen_meters;
4848+4949+ /*!
5050+ * The distance to the lens from the screen, used to calculate calculate
5151+ * tanangle of various distances on the screen.
5252+ */
5353+ float screen_to_lens_distance_meters;
5454+5555+ //! Fov values that the cardboard configuration has given us.
5656+ struct xrt_fov fov;
5757+};
5858+5959+/*!
6060+ * Values to create a distortion mesh from cardboard values.
6161+ *
6262+ * This matches the formula in the cardboard SDK, while the array is fixed size
6363+ * just setting the K value to zero will make it not have a effect.
6464+ *
6565+ * p' = p (1 + K0 r^2 + K1 r^4 + ... + Kn r^(2n))
6666+ *
6767+ * @ingroup aux_distortion
6868+ */
6969+struct u_cardboard_distortion_values
7070+{
7171+ //! Cardboard distortion k values.
7272+ float distortion_k[5];
7373+7474+ struct
7575+ {
7676+ //! Used to transform to and from tanangle space.
7777+ struct xrt_vec2 size;
7878+ //! Used to transform to and from tanangle space.
7979+ struct xrt_vec2 offset;
8080+ } screen, texture;
8181+};
8282+8383+/*!
8484+ * Both given and derived values needed for cardboard distortion.
8585+ *
8686+ * @ingroup aux_distortion
8787+ */
8888+struct u_cardboard_distortion
8989+{
9090+ //! Arguments this distortion was created from.
9191+ struct u_cardboard_distortion_arguments args;
9292+9393+ //! Distortion parameters, some derived from @ref args.
9494+ struct u_cardboard_distortion_values values[2];
9595+};
9696+9797+/*!
9898+ * Take cardboard arguments to turn them into a @ref u_cardboard_distortion and
9999+ * fill out a @ref xrt_hmd_parts struct.
100100+ *
101101+ * @ingroup aux_distortion
102102+ */
103103+void
104104+u_distortion_cardboard_calculate(
105105+ const struct u_cardboard_distortion_arguments *args,
106106+ struct xrt_hmd_parts *parts,
107107+ struct u_cardboard_distortion *out_dist);
108108+109109+110110+#ifdef __cplusplus
111111+}
112112+#endif